|
|
|
@ -102,6 +102,16 @@ public final class httpc {
|
|
|
|
|
//Mo 06 Sep 2004 23:32
|
|
|
|
|
private static final HashMap reverseMappingCache = new HashMap();
|
|
|
|
|
|
|
|
|
|
// the dns cache
|
|
|
|
|
private static final HashMap nameCacheHit = new HashMap();
|
|
|
|
|
//private static HashSet nameCacheMiss = new HashSet();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* A Object Pool containing all pooled httpc-objects.
|
|
|
|
|
* @see httpcPool
|
|
|
|
|
*/
|
|
|
|
|
private static final httpcPool theHttpcPool;
|
|
|
|
|
|
|
|
|
|
// class variables
|
|
|
|
|
private Socket socket = null; // client socket for commands
|
|
|
|
|
private String host = null;
|
|
|
|
@ -109,31 +119,19 @@ public final class httpc {
|
|
|
|
|
private long handle;
|
|
|
|
|
|
|
|
|
|
// output and input streams for client control connection
|
|
|
|
|
PushbackInputStream clientInput = null;
|
|
|
|
|
OutputStream clientOutput = null;
|
|
|
|
|
private PushbackInputStream clientInput = null;
|
|
|
|
|
private OutputStream clientOutput = null;
|
|
|
|
|
|
|
|
|
|
private boolean remoteProxyUse = false;
|
|
|
|
|
private String savedRemoteHost = null;
|
|
|
|
|
private String requestPath = null;
|
|
|
|
|
|
|
|
|
|
// the dns cache
|
|
|
|
|
private static final HashMap nameCacheHit = new HashMap();
|
|
|
|
|
//private static HashSet nameCacheMiss = new HashSet();
|
|
|
|
|
|
|
|
|
|
static {
|
|
|
|
|
// set time-out of InetAddress.getByName cache ttl
|
|
|
|
|
java.security.Security.setProperty("networkaddress.cache.ttl" , "60");
|
|
|
|
|
java.security.Security.setProperty("networkaddress.cache.negative.ttl" , "0");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* A Object Pool containing all pooled httpc-objects.
|
|
|
|
|
* @see httpcPool
|
|
|
|
|
*/
|
|
|
|
|
private static final httpcPool theHttpcPool;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Indicates if the current object was removed from pool because the maximum limit
|
|
|
|
|
* was exceeded.
|
|
|
|
@ -225,14 +223,6 @@ public final class httpc {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected void finalize() throws Throwable {
|
|
|
|
|
if (!this.removedFromPool) {
|
|
|
|
|
System.err.println("Httpc object was not returned to object pool.");
|
|
|
|
|
httpc.theHttpcPool.invalidateObject(this);
|
|
|
|
|
}
|
|
|
|
|
this.reset();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static String dnsResolve(String host) {
|
|
|
|
|
// looks for the ip of host <host> and returns ip number as string
|
|
|
|
|
String ip = (String) nameCacheHit.get(host);
|
|
|
|
@ -270,37 +260,27 @@ public final class httpc {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void reset() {
|
|
|
|
|
try {
|
|
|
|
|
if (this.clientInput != null) {
|
|
|
|
|
this.clientInput.close();
|
|
|
|
|
this.clientInput = null;
|
|
|
|
|
}
|
|
|
|
|
if (this.clientOutput != null) {
|
|
|
|
|
this.clientOutput.close();
|
|
|
|
|
this.clientOutput = null;
|
|
|
|
|
}
|
|
|
|
|
if (this.socket != null) {
|
|
|
|
|
this.socket.close();
|
|
|
|
|
this.socket = null;
|
|
|
|
|
// provide HTTP date handling static methods
|
|
|
|
|
public static String dateString(Date date) {
|
|
|
|
|
if (date == null) return ""; else return HTTPGMTFormatter.format(date);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.host = null;
|
|
|
|
|
this.timeout = 0;
|
|
|
|
|
this.handle = 0;
|
|
|
|
|
|
|
|
|
|
this.remoteProxyUse = false;
|
|
|
|
|
this.savedRemoteHost = null;
|
|
|
|
|
this.requestPath = null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// shrink readlinebuffer if it is to large
|
|
|
|
|
this.readLineBuffer.reset(80);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
// we could ignore this ...
|
|
|
|
|
}
|
|
|
|
|
public static Date nowDate() {
|
|
|
|
|
return new GregorianCalendar(GMTTimeZone).getTime();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static {
|
|
|
|
|
// provide system information for client identification
|
|
|
|
|
String loc = System.getProperty("user.timezone", "nowhere");
|
|
|
|
|
int p = loc.indexOf("/");
|
|
|
|
|
if (p > 0) loc = loc.substring(0,p);
|
|
|
|
|
loc = loc + "/" + System.getProperty("user.language", "dumb");
|
|
|
|
|
systemOST =
|
|
|
|
|
System.getProperty("os.arch", "no-os-arch") + " " + System.getProperty("os.name", "no-os-arch") + " " +
|
|
|
|
|
System.getProperty("os.version", "no-os-version") + "; " +
|
|
|
|
|
"java " + System.getProperty("java.version", "no-java-version") + "; " + loc;
|
|
|
|
|
userAgent = "yacy (www.yacy.net; v" + vDATE + "; " + systemOST + ")";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// http client
|
|
|
|
|
|
|
|
|
@ -342,26 +322,43 @@ public final class httpc {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// provide HTTP date handling static methods
|
|
|
|
|
public static String dateString(Date date) {
|
|
|
|
|
if (date == null) return ""; else return HTTPGMTFormatter.format(date);
|
|
|
|
|
void reset() {
|
|
|
|
|
if (this.clientInput != null) {
|
|
|
|
|
try {this.clientInput.close();} catch (Exception e) {}
|
|
|
|
|
this.clientInput = null;
|
|
|
|
|
}
|
|
|
|
|
if (this.clientOutput != null) {
|
|
|
|
|
try {this.clientOutput.close();} catch (Exception e) {}
|
|
|
|
|
this.clientOutput = null;
|
|
|
|
|
}
|
|
|
|
|
if (this.socket != null) {
|
|
|
|
|
try {this.socket.close();} catch (Exception e) {}
|
|
|
|
|
this.socket = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static Date nowDate() {
|
|
|
|
|
return new GregorianCalendar(GMTTimeZone).getTime();
|
|
|
|
|
this.host = null;
|
|
|
|
|
this.timeout = 0;
|
|
|
|
|
this.handle = 0;
|
|
|
|
|
|
|
|
|
|
this.remoteProxyUse = false;
|
|
|
|
|
this.savedRemoteHost = null;
|
|
|
|
|
this.requestPath = null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// shrink readlinebuffer if it is to large
|
|
|
|
|
this.readLineBuffer.reset(80);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static {
|
|
|
|
|
// provide system information for client identification
|
|
|
|
|
String loc = System.getProperty("user.timezone", "nowhere");
|
|
|
|
|
int p = loc.indexOf("/");
|
|
|
|
|
if (p > 0) loc = loc.substring(0,p);
|
|
|
|
|
loc = loc + "/" + System.getProperty("user.language", "dumb");
|
|
|
|
|
systemOST =
|
|
|
|
|
System.getProperty("os.arch", "no-os-arch") + " " + System.getProperty("os.name", "no-os-arch") + " " +
|
|
|
|
|
System.getProperty("os.version", "no-os-version") + "; " +
|
|
|
|
|
"java " + System.getProperty("java.version", "no-java-version") + "; " + loc;
|
|
|
|
|
userAgent = "yacy (www.yacy.net; v" + vDATE + "; " + systemOST + ")";
|
|
|
|
|
public void close() {
|
|
|
|
|
reset();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected void finalize() throws Throwable {
|
|
|
|
|
if (!(this.removedFromPool)) {
|
|
|
|
|
System.err.println("Httpc object was not returned to object pool.");
|
|
|
|
|
httpc.theHttpcPool.invalidateObject(this);
|
|
|
|
|
}
|
|
|
|
|
this.reset();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public final class response {
|
|
|
|
@ -551,15 +548,6 @@ public final class httpc {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void close() {
|
|
|
|
|
// closes the connection
|
|
|
|
|
try {
|
|
|
|
|
this.clientInput.close();
|
|
|
|
|
this.clientOutput.close();
|
|
|
|
|
this.socket.close();
|
|
|
|
|
} catch (IOException e) {}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// method is either GET, HEAD or POST
|
|
|
|
|
private void send(String method, String path, httpHeader header, boolean zipped) throws IOException {
|
|
|
|
|
// scheduled request through request-response objects/threads
|
|
|
|
@ -1207,6 +1195,7 @@ final class httpcFactory implements org.apache.commons.pool.PoolableObjectFactor
|
|
|
|
|
public void destroyObject(Object obj) {
|
|
|
|
|
if (obj instanceof httpc) {
|
|
|
|
|
httpc theHttpc = (httpc) obj;
|
|
|
|
|
|
|
|
|
|
theHttpc.removedFromPool = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -1215,8 +1204,7 @@ final class httpcFactory implements org.apache.commons.pool.PoolableObjectFactor
|
|
|
|
|
* @see org.apache.commons.pool.PoolableObjectFactory#validateObject(java.lang.Object)
|
|
|
|
|
*/
|
|
|
|
|
public boolean validateObject(Object obj) {
|
|
|
|
|
if (obj instanceof httpc)
|
|
|
|
|
{
|
|
|
|
|
if (obj instanceof httpc) {
|
|
|
|
|
httpc theHttpc = (httpc) obj;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|