*) Some minor bugfixes

- httpc: wrong error-message on 404
- httpc: error message was accidentally shown when object 
  was released from pool


git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@31 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
(no author) 20 years ago
parent 1fec00bc24
commit 4a76ccc6d6

@ -322,7 +322,7 @@ public final class htmlFilterOutputStream extends OutputStream {
} else if (inScript) { } else if (inScript) {
buffer.append(b); buffer.append(b);
int bufferLength = buffer.length(); int bufferLength = buffer.length();
if ((b == rb) && (buffer.length() > 14) && if ((b == rb) && (bufferLength > 14) &&
(buffer.byteAt(bufferLength - 8) == (byte) '/') && (buffer.byteAt(bufferLength - 8) == (byte) '/') &&
(buffer.byteAt(bufferLength - 7) == (byte) 's') && (buffer.byteAt(bufferLength - 7) == (byte) 's') &&
(buffer.byteAt(bufferLength - 6) == (byte) 'c') && (buffer.byteAt(bufferLength - 6) == (byte) 'c') &&

@ -105,6 +105,7 @@ public final class httpc {
} }
private static final httpcPool theHttpcPool; private static final httpcPool theHttpcPool;
boolean removedFromPool = false;
static { static {
// implementation of session thread pool // implementation of session thread pool
GenericObjectPool.Config config = new GenericObjectPool.Config(); GenericObjectPool.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, public static httpc getInstance(String server, int port, int timeout, boolean ssl,
String remoteProxyHost, int remoteProxyPort) throws IOException { String remoteProxyHost, int remoteProxyPort) throws IOException {
httpc newHttpc;
try { try {
// fetching a new httpc from the object pool // fetching a new httpc from the object pool
httpc newHttpc = (httpc) httpc.theHttpcPool.borrowObject(); newHttpc = (httpc) httpc.theHttpcPool.borrowObject();
// initialize it
newHttpc.init(server,port,timeout,ssl,remoteProxyHost, remoteProxyPort);
return newHttpc;
} catch (Exception e) { } catch (Exception e) {
throw new IOException("Unable to initialize a new httpc. " + e.getMessage()); 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 { 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 { 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(); this.reset();
httpc.theHttpcPool.invalidateObject(this); httpc.theHttpcPool.invalidateObject(this);
} }
@ -417,7 +419,7 @@ public final class httpc {
public byte[] writeContent(OutputStream procOS) throws IOException { public byte[] writeContent(OutputStream procOS) throws IOException {
serverByteBuffer sbb = new serverByteBuffer(); serverByteBuffer sbb = new serverByteBuffer();
writeContentX(procOS, sbb); writeContentX(procOS, sbb, httpc.this.clientInput);
return sbb.getBytes(); return sbb.getBytes();
} }
@ -426,14 +428,14 @@ public final class httpc {
// a file or both. // a file or both.
FileOutputStream bufferOS = null; FileOutputStream bufferOS = null;
if (file != null) bufferOS = new FileOutputStream(file); if (file != null) bufferOS = new FileOutputStream(file);
writeContentX(procOS, bufferOS); writeContentX(procOS, bufferOS, httpc.this.clientInput);
if (bufferOS != null) { if (bufferOS != null) {
bufferOS.close(); bufferOS.close();
if (file.length() == 0) file.delete(); 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 // we write length bytes, but if length == -1 (or < 0) then we
// write until the input stream closes // write until the input stream closes
// procOS == null -> no write to procOS // procOS == null -> no write to procOS
@ -473,7 +475,7 @@ public final class httpc {
} }
baos.flush(); baos.flush();
// now uncompress // now uncompress
InputStream dis = (InputStream) new GZIPInputStream(new ByteArrayInputStream(baos.toByteArray())); InputStream dis = new GZIPInputStream(new ByteArrayInputStream(baos.toByteArray()));
try { try {
while ((l = dis.read(buffer)) > 0) { while ((l = dis.read(buffer)) > 0) {
if (procOS != null) procOS.write(buffer, 0, l); if (procOS != null) procOS.write(buffer, 0, l);
@ -1180,6 +1182,7 @@ final class httpcFactory implements org.apache.commons.pool.PoolableObjectFactor
public void destroyObject(Object obj) { public void destroyObject(Object obj) {
if (obj instanceof httpc) { if (obj instanceof httpc) {
httpc theHttpc = (httpc) obj; httpc theHttpc = (httpc) obj;
theHttpc.removedFromPool = true;
} }
} }

@ -394,7 +394,7 @@ public final class httpdProxyHandler extends httpdAbstractHandler implements htt
// maybe the content length is missing // maybe the content length is missing
if (!(cachedResponseHeader.containsKey("CONTENT-LENGTH"))) if (!(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 content // check if we can send a 304 instead the complete content
if (requestHeader.containsKey("IF-MODIFIED-SINCE")) { if (requestHeader.containsKey("IF-MODIFIED-SINCE")) {

Loading…
Cancel
Save