diff --git a/htroot/Connections_p.html b/htroot/Connections_p.html index 47e3abd93..7565e85df 100644 --- a/htroot/Connections_p.html +++ b/htroot/Connections_p.html @@ -36,7 +36,7 @@

Outgoing Connections

-

Currently not available!

+

Details currently not available!

Showing #[clientActive]# active outgoing connections:

diff --git a/htroot/Connections_p.java b/htroot/Connections_p.java index 4357114e0..879425bf4 100644 --- a/htroot/Connections_p.java +++ b/htroot/Connections_p.java @@ -51,6 +51,8 @@ import java.net.InetAddress; import java.net.URLEncoder; import java.util.Properties; +import de.anomic.http.HttpConnectionInfo; +import de.anomic.http.JakartaCommonsHttpClient; import de.anomic.http.httpHeader; import de.anomic.http.httpd; import de.anomic.plasma.plasmaSwitchboard; @@ -227,24 +229,21 @@ public final class Connections_p { prop.putNum("numActivePending", numActivePending); // client sessions - // FIXME track connections of JakartaCommons Connection Manager -// httpc[] a = httpc.allConnections(); + HttpConnectionInfo[] a = JakartaCommonsHttpClient.allConnections(); + // TODO sorting // Arrays.sort(a, httpc.connectionTimeComparatorInstance); int c = 0; -// for (int i = 0; i < a.length; i++) { -// httpc clientConnection = a[i]; -// if (clientConnection != null) { -// prop.put("clientList_" + c + "_clientProtocol", (clientConnection.ssl) ? "HTTPS" : "HTTP"); -// prop.putNum("clientList_" + c + "_clientLifetime", System.currentTimeMillis() - clientConnection.initTime); -// prop.putNum("clientList_" + c + "_clientIdletime", System.currentTimeMillis() - clientConnection.lastIO); -// prop.put("clientList_" + c + "_clientTargetHost", clientConnection.adressed_host + ":" + clientConnection.adressed_port); -// prop.putHTML("clientList_" + c + "_clientCommand", (clientConnection.command == null) ? "-" : clientConnection.command); -// prop.put("clientList_" + c + "_clientID", clientConnection.hashCode()); -// c++; -// } -// } + for (HttpConnectionInfo conInfo: a) { + prop.put("clientList_" + c + "_clientProtocol", conInfo.getProtocol()); + prop.putNum("clientList_" + c + "_clientLifetime", conInfo.getLifetime()); + prop.putNum("clientList_" + c + "_clientIdletime", conInfo.getIdletime()); + prop.put("clientList_" + c + "_clientTargetHost", conInfo.getTargetHost()); + prop.putHTML("clientList_" + c + "_clientCommand", conInfo.getCommand()); + prop.put("clientList_" + c + "_clientID", conInfo.getID()); + c++; + } prop.put("clientList", c); - prop.put("clientActive", c); + prop.put("clientActive", JakartaCommonsHttpClient.connectionCount()); // return rewrite values for templates return prop; diff --git a/source/de/anomic/htmlFilter/htmlFilterWriter.java b/source/de/anomic/htmlFilter/htmlFilterWriter.java index 967998b69..e0e43cbf5 100644 --- a/source/de/anomic/htmlFilter/htmlFilterWriter.java +++ b/source/de/anomic/htmlFilter/htmlFilterWriter.java @@ -314,7 +314,7 @@ public final class htmlFilterWriter extends Writer { } public void write(int c) throws IOException { -// System.out.println((char) b); +// System.out.println((char) c); if ((binaryUnsuspect) && (binaryHint((char)c))) { binaryUnsuspect = false; if (passbyIfBinarySuspect) finalize(); @@ -489,10 +489,10 @@ public final class htmlFilterWriter extends Writer { // if (transformer != null) {transformer.close(); transformer = null;} } - private static boolean binaryHint(char c) { + private static boolean binaryHint(final char c) { // space, punctiation and symbols, letters and digits (ASCII/latin) //if (c >= 31 && c < 128) return false; - if(c >= 31) return false; + if(c > 31) return false; // 8 = backspace // 9 = horizontal tab // 10 = new line (line feed) diff --git a/source/de/anomic/http/HttpConnectionInfo.java b/source/de/anomic/http/HttpConnectionInfo.java new file mode 100644 index 000000000..5f5459655 --- /dev/null +++ b/source/de/anomic/http/HttpConnectionInfo.java @@ -0,0 +1,114 @@ +// HttpConnectionInfo.java +// (C) 2008 by Daniel Raap; danielr@users.berlios.de +// first published 07.04.2008 on http://yacy.net +// +// This is a part of YaCy, a peer-to-peer based web search engine +// +// $LastChangedDate: 2008-03-14 01:16:04 +0100 (Fr, 14 Mrz 2008) $ +// $LastChangedRevision: 4558 $ +// $LastChangedBy: orbiter $ +// +// LICENSE +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +package de.anomic.http; + +import org.apache.commons.httpclient.HttpConnection; + +/** + * Information about a connection + * + * @author daniel + * @since 07.04.2008 + */ +public class HttpConnectionInfo { + private final String protocol; + private final String targetHost; + private final String command; + private final int id; + private final long initTime; + + /** + * constructor using org.apache.commons.httpclient.HttpConnection + * + * @param connection + */ + public HttpConnectionInfo(final HttpConnection connection) { + this(connection.getProtocol().toString(), ((connection.getPort() == 80) ? connection.getHost() + : connection.getHost() + ":" + connection.getPort()), "unknown command", connection.hashCode(), + System.currentTimeMillis()); + } + + /** + * constructor setting all data + * + * @param protocol + * @param targetHost + * @param command + * @param id + * @param initTime + */ + public HttpConnectionInfo(final String protocol, final String targetHost, final String command, final int id, + final long initTime) { + this.protocol = protocol; + this.targetHost = targetHost; + this.command = command; + this.id = id; + this.initTime = initTime; + } + + /** + * @return + */ + public String getProtocol() { + return protocol; + } + + /** + * @return + */ + public long getLifetime() { + return System.currentTimeMillis() - initTime; + } + + /** + * @return + */ + public int getIdletime() { + return 0; + } + + /** + * @return + */ + public String getCommand() { + return command; + } + + /** + * @return + */ + public String getTargetHost() { + return targetHost; + } + + /** + * @return + */ + public int getID() { + return id; + } +} diff --git a/source/de/anomic/http/HttpResponse.java b/source/de/anomic/http/HttpResponse.java index a1d2cbd6a..dbb3e5d94 100644 --- a/source/de/anomic/http/HttpResponse.java +++ b/source/de/anomic/http/HttpResponse.java @@ -32,7 +32,7 @@ import java.io.OutputStreamWriter; import java.io.UnsupportedEncodingException; import java.io.Writer; -import de.anomic.tools.StreamTools; +import de.anomic.server.serverFileUtils; /** * @author daniel @@ -108,12 +108,12 @@ public interface HttpResponse { if (hfos instanceof OutputStream) { OutputStream[] streams = (byteStream == null ? new OutputStream[] { (OutputStream) hfos } : new OutputStream[] { (OutputStream) hfos, byteStream }); - StreamTools.copyToStreams(data, streams); + serverFileUtils.copyToStreams(data, streams); } else if (hfos instanceof Saver) { String charSet = httpHeader.getCharSet(res.getResponseHeader()); Writer[] writers = (byteStream == null ? new Writer[] { (Writer) hfos } : new Writer[] { (Writer) hfos, new OutputStreamWriter(byteStream, charSet) }); - StreamTools.copyToWriters(data, writers, charSet); + serverFileUtils.copyToWriters(data, writers, charSet); } else { throw new IOException("cannot save data: hfos-type ("+ hfos.getClass().toString() +") not supported!"); } diff --git a/source/de/anomic/http/JakartaCommonsHttpClient.java b/source/de/anomic/http/JakartaCommonsHttpClient.java index 70d093905..d8ae9ae8a 100644 --- a/source/de/anomic/http/JakartaCommonsHttpClient.java +++ b/source/de/anomic/http/JakartaCommonsHttpClient.java @@ -54,11 +54,12 @@ import org.apache.commons.httpclient.methods.multipart.StringPart; import org.apache.commons.httpclient.params.HttpClientParams; import org.apache.commons.httpclient.params.HttpMethodParams; import org.apache.commons.httpclient.protocol.Protocol; +import org.apache.commons.httpclient.protocol.ProtocolSocketFactory; import org.apache.commons.httpclient.util.DateUtil; import de.anomic.kelondro.kelondroBase64Order; +import de.anomic.server.serverFileUtils; import de.anomic.server.logging.serverLog; -import de.anomic.tools.StreamTools; import de.anomic.yacy.yacyVersion; /** @@ -90,7 +91,7 @@ public class JakartaCommonsHttpClient extends de.anomic.http.HttpClient { // TODO should this be configurable? // accept self-signed or untrusted certificates - Protocol.registerProtocol("https", new Protocol("https", new EasySSLProtocolSocketFactory(), 443)); + Protocol.registerProtocol("https", new Protocol("https", (ProtocolSocketFactory)new EasySSLProtocolSocketFactory(), 443)); } private final Map openStreams = new HashMap(); @@ -227,7 +228,7 @@ public class JakartaCommonsHttpClient extends de.anomic.http.HttpClient { if (file.isFile() && file.canRead()) { // read file final ByteArrayOutputStream fileData = new ByteArrayOutputStream(); - StreamTools.copyToStreams(new FileInputStream(file), new OutputStream[] { fileData }); + serverFileUtils.copyToStreams(new FileInputStream(file), new OutputStream[] { fileData }); value = fileData.toByteArray(); } } @@ -506,4 +507,22 @@ public class JakartaCommonsHttpClient extends de.anomic.http.HttpClient { public static String getCurrentUserAgent() { return (String) apacheHttpClient.getParams().getParameter(HttpClientParams.USER_AGENT); } + + /** + * a list of all connections (not yet implemented) + * + * @return + */ + public static HttpConnectionInfo[] allConnections() { + return new HttpConnectionInfo[0]; + } + + /** + * number of active connections + * + * @return + */ + public static int connectionCount() { + return conManager.getConnectionsInPool(); + } } \ No newline at end of file diff --git a/source/de/anomic/http/httpHeader.java b/source/de/anomic/http/httpHeader.java index fe7662273..47f058c28 100644 --- a/source/de/anomic/http/httpHeader.java +++ b/source/de/anomic/http/httpHeader.java @@ -952,7 +952,7 @@ public final class httpHeader extends TreeMap implements Map -1) { + ByteArrayOutputStream buffer = new ByteArrayOutputStream(); + serverFileUtils.copy(body, buffer, requestLength); + body = new ByteArrayInputStream(buffer.toByteArray()); + } HttpResponse res = null; try { // sending the request - // TODO is the input stream required and valid HTTP-data? res = client.POST(getUrl, body); // determine if it's an internal error of the httpc @@ -1133,7 +1156,7 @@ public final class httpdProxyHandler { private static void addXForwardedForHeader(Properties conProp, httpHeader requestHeader) { // setting the X-Forwarded-For Header if (switchboard.getConfigBool("proxy.sendXForwardedForHeader", true)) { - requestHeader.put(httpHeader.X_FORWARDED_FOR,conProp.getProperty(httpHeader.CONNECTION_PROP_CLIENTIP)); + requestHeader.put(httpHeader.X_FORWARDED_FOR, conProp.getProperty(httpHeader.CONNECTION_PROP_CLIENTIP)); } } diff --git a/source/de/anomic/server/serverFileUtils.java b/source/de/anomic/server/serverFileUtils.java index 7ee498bfa..75be2a2b2 100644 --- a/source/de/anomic/server/serverFileUtils.java +++ b/source/de/anomic/server/serverFileUtils.java @@ -40,8 +40,10 @@ package de.anomic.server; +import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.BufferedReader; +import java.io.BufferedWriter; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.File; @@ -79,17 +81,19 @@ public final class serverFileUtils { } /** - * Copies an InputStream to an OutputStream. - * @param source InputStream - * @param dest OutputStream - * @param count the total amount of bytes to copy - * @return Total number of bytes copied. - * - * @see #copy(InputStream source, File dest) - * @see #copyRange(File source, OutputStream dest, int start) - * @see #copy(File source, OutputStream dest) - * @see #copy(File source, File dest) - */ + * Copies an InputStream to an OutputStream. + * + * @param source InputStream + * @param dest OutputStream + * @param count the total amount of bytes to copy + * @return Total number of bytes copied. + * @throws IOException + * + * @see #copy(InputStream source, File dest) + * @see #copyRange(File source, OutputStream dest, int start) + * @see #copy(File source, OutputStream dest) + * @see #copy(File source, File dest) + */ public static long copy(InputStream source, OutputStream dest, long count) throws IOException { byte[] buffer = new byte[DEFAULT_BUFFER_SIZE]; int chunkSize = (int) ((count > 0) ? Math.min(count, DEFAULT_BUFFER_SIZE) : DEFAULT_BUFFER_SIZE); @@ -153,15 +157,17 @@ public final class serverFileUtils { } /** - * Copies an InputStream to a File. - * @param source InputStream - * @param dest File - * @param the amount of bytes to copy - * @see #copy(InputStream source, OutputStream dest) - * @see #copyRange(File source, OutputStream dest, int start) - * @see #copy(File source, OutputStream dest) - * @see #copy(File source, File dest) - */ + * Copies an InputStream to a File. + * + * @param source InputStream + * @param dest File + * @param count the amount of bytes to copy + * @throws IOException + * @see #copy(InputStream source, OutputStream dest) + * @see #copyRange(File source, OutputStream dest, int start) + * @see #copy(File source, OutputStream dest) + * @see #copy(File source, File dest) + */ public static void copy(InputStream source, File dest, long count) throws IOException { FileOutputStream fos = null; try { @@ -173,15 +179,16 @@ public final class serverFileUtils { } /** - * Copies a part of a File to an OutputStream. - * @param source File - * @param dest OutputStream - * @param start Number of bytes to skip from the beginning of the File - * @see #copy(InputStream source, OutputStream dest) - * @see #copy(InputStream source, File dest) - * @see #copy(File source, OutputStream dest) - * @see #copy(File source, File dest) - */ + * Copies a part of a File to an OutputStream. + * @param source File + * @param dest OutputStream + * @param start Number of bytes to skip from the beginning of the File + * @throws IOException + * @see #copy(InputStream source, OutputStream dest) + * @see #copy(InputStream source, File dest) + * @see #copy(File source, OutputStream dest) + * @see #copy(File source, File dest) + */ public static void copyRange(File source, OutputStream dest, int start) throws IOException { InputStream fis = null; try { @@ -195,14 +202,15 @@ public final class serverFileUtils { } /** - * Copies a File to an OutputStream. - * @param source File - * @param dest OutputStream - * @see #copy(InputStream source, OutputStream dest) - * @see #copy(InputStream source, File dest) - * @see #copyRange(File source, OutputStream dest, int start) - * @see #copy(File source, File dest) - */ + * Copies a File to an OutputStream. + * @param source File + * @param dest OutputStream + * @throws IOException + * @see #copy(InputStream source, OutputStream dest) + * @see #copy(InputStream source, File dest) + * @see #copyRange(File source, OutputStream dest, int start) + * @see #copy(File source, File dest) + */ public static void copy(File source, OutputStream dest) throws IOException { InputStream fis = null; try { @@ -214,15 +222,16 @@ public final class serverFileUtils { } /** - * Copies a File to a File. - * @param source File - * @param dest File - * @param count the amount of bytes to copy - * @see #copy(InputStream source, OutputStream dest) - * @see #copy(InputStream source, File dest) - * @see #copyRange(File source, OutputStream dest, int start) - * @see #copy(File source, OutputStream dest) - */ + * Copies a File to a File. + * @param source File + * @param dest File + * @param count the amount of bytes to copy + * @throws IOException + * @see #copy(InputStream source, OutputStream dest) + * @see #copy(InputStream source, File dest) + * @see #copyRange(File source, OutputStream dest, int start) + * @see #copy(File source, OutputStream dest) + */ public static void copy(File source, File dest) throws IOException { FileInputStream fis = null; FileOutputStream fos = null; @@ -500,4 +509,75 @@ public final class serverFileUtils { e.printStackTrace(); } } + + /** + * copies the input stream to all output streams (byte per byte) + * @param in + * @param outs + * @return + * @throws IOException + */ + public static int copyToStreams(InputStream in, final OutputStream[] outs) throws IOException { + if(!(in instanceof BufferedInputStream)) { + // add buffer + in = new BufferedInputStream(in); + } + + // check if buffer is used + int i = 0; + for(final OutputStream output: outs) { + if (!(output instanceof BufferedOutputStream)) { + // add buffer + outs[i] = new BufferedOutputStream(output); + } + i++; + } + + int count = 0; + // copy bytes + int b; + while((b = in.read()) != -1) { + count++; + for(final OutputStream out: outs) { + out.write(b); + } + } + return count; + } + + /** + * copies the input stream to all writers (byte per byte) + * @param data + * @param writers + * @param charSet + * @return + * @throws IOException + */ + public static int copyToWriters(final InputStream data, final Writer[] writers, final String charSet) throws IOException { + // the docs say: "For top efficiency, consider wrapping an InputStreamReader within a BufferedReader." + final BufferedReader sourceReader = new BufferedReader(new InputStreamReader(data, charSet)); + + // check if buffer is used. From the documentation: + // "For top efficiency, consider wrapping an OutputStreamWriter within a BufferedWriter so as to avoid frequent + // converter invocations" + int i = 0; + for(final Writer writer: writers) { + if (!(writer instanceof BufferedWriter)) { + // add buffer + writers[i] = new BufferedWriter(writer); + } + i++; + } + + int count = 0; + // copy bytes + int b; + while((b = sourceReader.read()) != -1) { + count++; + for(final Writer writer: writers) { + writer.write(b); + } + } + return count; + } } diff --git a/source/de/anomic/tools/StreamTools.java b/source/de/anomic/tools/StreamTools.java deleted file mode 100644 index e86970b09..000000000 --- a/source/de/anomic/tools/StreamTools.java +++ /dev/null @@ -1,114 +0,0 @@ -// LowLevelTools.java -// (C) 2008 by Daniel Raap; danielr@users.berlios.de -// first published 2.4.2008 on http://yacy.net -// -// This is a part of YaCy, a peer-to-peer based web search engine -// -// $LastChangedDate: 2008-03-14 01:16:04 +0100 (Fr, 14 Mrz 2008) $ -// $LastChangedRevision: 4558 $ -// $LastChangedBy: orbiter $ -// -// LICENSE -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 2 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -package de.anomic.tools; - -import java.io.BufferedInputStream; -import java.io.BufferedOutputStream; -import java.io.BufferedReader; -import java.io.BufferedWriter; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.OutputStream; -import java.io.Writer; - -/** - * @author danielr - * - */ -public class StreamTools { - /** - * copies the input stream to all output streams (byte per byte) - * @param in - * @param outs - * @return - * @throws IOException - */ - public static int copyToStreams(InputStream in, final OutputStream[] outs) throws IOException { - if(!(in instanceof BufferedInputStream)) { - // add buffer - in = new BufferedInputStream(in); - } - - // check if buffer is used - int i = 0; - for(final OutputStream output: outs) { - if (!(output instanceof BufferedOutputStream)) { - // add buffer - outs[i] = new BufferedOutputStream(output); - } - i++; - } - - int count = 0; - // copy bytes - int b; - while((b = in.read()) != -1) { - count++; - for(final OutputStream out: outs) { - out.write(b); - } - } - return count; - } - - /** - * copies the input stream to all writers (byte per byte) - * @param data - * @param writers - * @param charSet - * @return - * @throws IOException - */ - public static int copyToWriters(final InputStream data, final Writer[] writers, final String charSet) throws IOException { - // the docs say: "For top efficiency, consider wrapping an InputStreamReader within a BufferedReader." - final BufferedReader sourceReader = new BufferedReader(new InputStreamReader(data, charSet)); - - // check if buffer is used. From the documentation: - // "For top efficiency, consider wrapping an OutputStreamWriter within a BufferedWriter so as to avoid frequent - // converter invocations" - int i = 0; - for(final Writer writer: writers) { - if (!(writer instanceof BufferedWriter)) { - // add buffer - writers[i] = new BufferedWriter(writer); - } - i++; - } - - int count = 0; - // copy bytes - int b; - while((b = sourceReader.read()) != -1) { - count++; - for(final Writer writer: writers) { - writer.write(b); - } - } - return count; - } - -} diff --git a/source/de/anomic/yacy/yacyClient.java b/source/de/anomic/yacy/yacyClient.java index 92087b757..d0b9d21e5 100644 --- a/source/de/anomic/yacy/yacyClient.java +++ b/source/de/anomic/yacy/yacyClient.java @@ -83,11 +83,6 @@ import de.anomic.xml.rssReader; public final class yacyClient { - /** - * - */ - private static final String GZIP_POST_BODY = "GZIP_POST_BODY"; - public static int publishMySeed(String address, String otherHash) { // this is called to enrich the seed information by // - own address (if peer is behind a nat/router) @@ -911,7 +906,7 @@ public final class yacyClient { // enabling gzip compression for post request body if ((gzipBody) && (targetSeed.getVersion() >= yacyVersion.YACY_SUPPORTS_GZIP_POST_REQUESTS)) { - post.put(GZIP_POST_BODY,"true"); + // TODO generate gzip-Header (and stream?) } post.put("wordc", Integer.toString(indexes.length)); @@ -968,7 +963,7 @@ public final class yacyClient { // enabling gzip compression for post request body if ((gzipBody) && (targetSeed.getVersion() >= yacyVersion.YACY_SUPPORTS_GZIP_POST_REQUESTS)) { - post.put(GZIP_POST_BODY,"true"); + // TODO generate gzip-Header (and stream?) } String resource = "";