Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance
Java decentralizedintranet-searchintranet-search-enginep2pp2p-networkprivacyprivacy-protectionsearch-enginesearchenginewebweb-search-enginewebsearchwebseearch-engine
*) Some minor bugfixes - httpc: wrong error-message on 404 - httpc: error message was accidentally shown when object was released from pool
(no author)4a76ccc6d6a5
diff --git a/source/de/anomic/htmlFilter/htmlFilterOutputStream.java b/source/de/anomic/htmlFilter/htmlFilterOutputStream.javaindex 14c236efc..e3d69a5b3 100644--- a/source/de/anomic/htmlFilter/htmlFilterOutputStream.java+++ b/source/de/anomic/htmlFilter/htmlFilterOutputStream.java@@ -322,7 +322,7 @@ public final class htmlFilterOutputStream extends OutputStream {} else if (inScript) {buffer.append(b);int bufferLength = buffer.length();- if ((b == rb) && (buffer.length() > 14) &&+ if ((b == rb) && (bufferLength > 14) &&(buffer.byteAt(bufferLength - 8) == (byte) '/') &&(buffer.byteAt(bufferLength - 7) == (byte) 's') &&(buffer.byteAt(bufferLength - 6) == (byte) 'c') &&diff --git a/source/de/anomic/http/httpc.java b/source/de/anomic/http/httpc.javaindex 570b4487f..3fa30d1b7 100644--- a/source/de/anomic/http/httpc.java+++ b/source/de/anomic/http/httpc.java@@ -105,6 +105,7 @@ public final class httpc {}private static final httpcPool theHttpcPool;+ boolean removedFromPool = false;static {// implementation of session thread poolGenericObjectPool.Config config = new GenericObjectPool.Config();@@ -129,17 +130,18 @@ public final class httpc {public static httpc getInstance(String server, int port, int timeout, boolean ssl,String remoteProxyHost, int remoteProxyPort) throws IOException {+ httpc newHttpc;try {// fetching a new httpc from the object pool- httpc newHttpc = (httpc) httpc.theHttpcPool.borrowObject();-- // initialize it- newHttpc.init(server,port,timeout,ssl,remoteProxyHost, remoteProxyPort);- return newHttpc;+ newHttpc = (httpc) httpc.theHttpcPool.borrowObject();} catch (Exception e) {throw new IOException("Unable to initialize a new httpc. " + e.getMessage());- }+ }++ // initialize it+ newHttpc.init(server,port,timeout,ssl,remoteProxyHost, remoteProxyPort);+ return newHttpc;}public static httpc getInstance(String server, int port, int timeout, boolean ssl) throws IOException {@@ -167,7 +169,7 @@ public final class httpc {}protected void finalize() throws Throwable {- System.err.println("Httpc object was not returned to object pool.");+ if (!this.removedFromPool) System.err.println("Httpc object was not returned to object pool.");this.reset();httpc.theHttpcPool.invalidateObject(this);}@@ -240,7 +242,7 @@ public final class httpc {// http clientvoid init(String server, int port, int timeout, boolean ssl,- String remoteProxyHost, int remoteProxyPort) throws IOException {+ String remoteProxyHost, int remoteProxyPort) throws IOException {this.init(remoteProxyHost, remoteProxyPort, timeout, ssl);this.remoteProxyUse = true;this.savedRemoteHost = server + ((port == 80) ? "" : (":" + port));@@ -417,7 +419,7 @@ public final class httpc {public byte[] writeContent(OutputStream procOS) throws IOException {serverByteBuffer sbb = new serverByteBuffer();- writeContentX(procOS, sbb);+ writeContentX(procOS, sbb, httpc.this.clientInput);return sbb.getBytes();}@@ -426,14 +428,14 @@ public final class httpc {// a file or both.FileOutputStream bufferOS = null;if (file != null) bufferOS = new FileOutputStream(file);- writeContentX(procOS, bufferOS);+ writeContentX(procOS, bufferOS, httpc.this.clientInput);if (bufferOS != null) {bufferOS.close();if (file.length() == 0) file.delete();}}- public void writeContentX(OutputStream procOS, OutputStream bufferOS) throws IOException {+ public void writeContentX(OutputStream procOS, OutputStream bufferOS, InputStream clientInput) throws IOException {// we write length bytes, but if length == -1 (or < 0) then we// write until the input stream closes// procOS == null -> no write to procOS@@ -442,7 +444,7 @@ public final class httpc {// and change the Content-Encoding and Content-Length attributes in the headerbyte[] buffer = new byte[2048];int l;- long len = 0;+ long len = 0;// find out lengthlong length = responseHeader.contentLength();@@ -473,7 +475,7 @@ public final class httpc {}baos.flush();// now uncompress- InputStream dis = (InputStream) new GZIPInputStream(new ByteArrayInputStream(baos.toByteArray()));+ InputStream dis = new GZIPInputStream(new ByteArrayInputStream(baos.toByteArray()));try {while ((l = dis.read(buffer)) > 0) {if (procOS != null) procOS.write(buffer, 0, l);@@ -489,18 +491,18 @@ public final class httpc {}baos.close(); baos = null;} else {- // no content-length was given, thus we read until the connection closes- InputStream dis = (gzip) ? (InputStream) new GZIPInputStream(clientInput) : (InputStream) clientInput;- try {- while ((l = dis.read(buffer, 0, buffer.length)) >= 0) {- if (procOS != null) procOS.write(buffer, 0, l);- if (bufferOS != null) bufferOS.write(buffer, 0, l);- }- } catch (java.net.SocketException e) {- // this is not an error: it's ok, we waited for that- } catch (java.net.SocketTimeoutException e) {+ // no content-length was given, thus we read until the connection closes+ InputStream dis = (gzip) ? (InputStream) new GZIPInputStream(clientInput) : (InputStream) clientInput;+ try {+ while ((l = dis.read(buffer, 0, buffer.length)) >= 0) {+ if (procOS != null) procOS.write(buffer, 0, l);+ if (bufferOS != null) bufferOS.write(buffer, 0, l);+ }+ } catch (java.net.SocketException e) {+ // this is not an error: it's ok, we waited for that+ } catch (java.net.SocketTimeoutException e) {// the same here; should be ok.- }+ }}// close the streams@@ -1180,6 +1182,7 @@ final class httpcFactory implements org.apache.commons.pool.PoolableObjectFactorpublic void destroyObject(Object obj) {if (obj instanceof httpc) {httpc theHttpc = (httpc) obj;+ theHttpc.removedFromPool = true;}}diff --git a/source/de/anomic/http/httpdProxyHandler.java b/source/de/anomic/http/httpdProxyHandler.javaindex 4611a1647..9c992d994 100644--- a/source/de/anomic/http/httpdProxyHandler.java+++ b/source/de/anomic/http/httpdProxyHandler.java@@ -394,7 +394,7 @@ public final class httpdProxyHandler extends httpdAbstractHandler implements htt// maybe the content length is missingif (!(cachedResponseHeader.containsKey("CONTENT-LENGTH")))- cachedResponseHeader.put("CONTENT-LENGTH", (String) ("" + cacheFile.length()));+ cachedResponseHeader.put("CONTENT-LENGTH", Long.toString(cacheFile.length()));// check if we can send a 304 instead the complete contentif (requestHeader.containsKey("IF-MODIFIED-SINCE")) {