Skip to content

Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance

Added an build-target to the ant-configuration to create the yacy-javadoc-documentation in doc/api. Just do ant create-doc and point your favourite browser to doc/api/index.html. As most of the classes are not documented right now this just gives a great overview of all classes. Hopefully this helps stimulating the creation of javadoc-insource-documentation.

jerri7792e5ae9bda
diff --git a/build.xml b/build.xml
index b5d9dda5c..d09da6530 100644
--- a/build.xml
+++ b/build.xml
@@ -467,5 +467,14 @@
<arg line=""/>
</java>
</target>
-
+
+<!-- create the html-documentation from javadoc -->
+<target name="create-doc" description="Create the javadoc-HTML-Pages">
+ <javadoc destdir="doc/api" version="no" use="yes" encoding="iso-8859-1" windowtitle="YaCy API Documentation">
+ <fileset dir="source" defaultexcludes="yes">
+ <include name="**/*.java" />
+ </fileset>
+ </javadoc>
+</target>
+
</project>
diff --git a/source/de/anomic/http/httpc.java b/source/de/anomic/http/httpc.java
index e5bda7c14..7ac28170d 100644
--- a/source/de/anomic/http/httpc.java
+++ b/source/de/anomic/http/httpc.java
@@ -38,15 +38,6 @@
// the intact and unchanged copyright notice.
// Contributions and changes to the program code must be marked as such.
-/*
- Class documentation:
- this class forms an http client
- while http access is built-in in java libraries, it is still
- necessary to implement the network interface since otherwise
- there is no access to the HTTP/1.0 / HTTP/1.1 header information
- that comes along each connection.
- */
-
package de.anomic.http;
import java.io.ByteArrayOutputStream;
@@ -86,93 +77,99 @@ import de.anomic.server.serverCore.Session;
import org.apache.commons.pool.impl.GenericObjectPool;
+/**
+* This class implements an http client. While http access is built-in in java
+* libraries, it is still necessary to implement the network interface since
+* otherwise there is no access to the HTTP/1.0 / HTTP/1.1 header information
+* that comes along each connection.
+*/
public final class httpc {
-
+
// statics
private static final String vDATE = "20040602";
private static String userAgent;
public static String systemOST;
private static final int terminalMaxLength = 30000;
private static final TimeZone GMTTimeZone = TimeZone.getTimeZone("PST");
-
+
// --- The GMT standard date format used in the HTTP protocol
private static final SimpleDateFormat HTTPGMTFormatter = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss 'GMT'", Locale.US);
private static final SimpleDateFormat EMLFormatter = new SimpleDateFormat("dd MMM yyyy HH:mm:ss", Locale.US);
private static final SimpleDateFormat ShortFormatter = new SimpleDateFormat("yyyyMMddHHmmss");
//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 Thread socketOwner = null;
private String host = null;
private long timeout;
private long handle;
-
+
// output and input streams for client control connection
PushbackInputStream clientInput = null;
private OutputStream clientOutput = null;
-
+
private boolean remoteProxyUse = false;
private String savedRemoteHost = null;
private String requestPath = null;
private boolean allowContentEncoding = true;
-
+
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");
}
-
+
/**
* Indicates if the current object was removed from pool because the maximum limit
* was exceeded.
*/
boolean removedFromPool = false;
-
+
// Configuring the httpc object pool
static {
// implementation of session thread pool
GenericObjectPool.Config config = new GenericObjectPool.Config();
-
+
// The maximum number of active connections that can be allocated from pool at the same time,
// 0 for no limit
config.maxActive = 150;
-
+
// The maximum number of idle connections connections in the pool
// 0 = no limit.
config.maxIdle = 75;
config.minIdle = 10;
-
+
config.whenExhaustedAction = GenericObjectPool.WHEN_EXHAUSTED_BLOCK;
config.minEvictableIdleTimeMillis = 30000;
-
+
theHttpcPool = new httpcPool(new httpcFactory(),config);
}
-
+
/**
* A reusable readline buffer
* @see serverByteBuffer
*/
final serverByteBuffer readLineBuffer = new serverByteBuffer(100);
-
+
private static final Hashtable openSocketLookupTable = new Hashtable();
-
+
public String toString() {
return (this.savedRemoteHost == null) ? "Disconnected" : "Connected to " + this.savedRemoteHost +
((this.remoteProxyUse) ? " via " + this.host : "");
}
-
+
public static httpc getInstance(
String server,
int port,
@@ -181,7 +178,7 @@ public final class httpc {
String remoteProxyHost,
int remoteProxyPort
) throws IOException {
-
+
httpc newHttpc;
try {
// fetching a new httpc from the object pool
@@ -189,23 +186,23 @@ public final class httpc {
} 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 {
-
+
httpc newHttpc = null;
// fetching a new httpc from the object pool
try {
newHttpc = (httpc) httpc.theHttpcPool.borrowObject();
-
+
} catch (Exception e) {
throw new IOException("Unable to fetch a new httpc from pool. " + e.getMessage());
}
-
+
// initialize it
try {
newHttpc.init(server,port,timeout,ssl);
@@ -214,10 +211,10 @@ public final class httpc {
throw e;
}
return newHttpc;
-
-
+
+
}
-
+
public static void returnInstance(httpc theHttpc) {
try {
theHttpc.reset();
@@ -226,16 +223,16 @@ public final class httpc {
// we could ignore this error
}
}
-
+
public void setAllowContentEncoding(boolean status) {
this.allowContentEncoding = status;
}
-
+
public boolean isClosed() {
if (this.socket == null) return true;
else return (!this.socket.isConnected()) || (this.socket.isClosed());
}
-
+
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);
@@ -254,7 +251,7 @@ public final class httpc {
}
return null;
}
-
+
public static boolean dnsFetch(String host) {
// looks for the ip of host <host> and returns false if the host was in the cache
// if it is not in the cache the ip is fetched and this resturns true
@@ -277,11 +274,11 @@ public final class httpc {
public static String dateString(Date date) {
if (date == null) return ""; else return HTTPGMTFormatter.format(date);
}
-
+
public static Date nowDate() {
return new GregorianCalendar(GMTTimeZone).getTime();
}
-
+
static {
// provide system information for client identification
String loc = System.getProperty("user.timezone", "nowhere");
@@ -296,21 +293,21 @@ public final class httpc {
}
// http client
-
+
void init(String server, int port, int timeout, boolean ssl,
String remoteProxyHost, int remoteProxyPort) throws IOException {
this.init(remoteProxyHost, remoteProxyPort, timeout, ssl);
this.remoteProxyUse = true;
this.savedRemoteHost = server + ((port == 80) ? "" : (":" + port));
}
-
+
void init(String server, int port, int timeout, boolean ssl) throws IOException {
handle = System.currentTimeMillis();
//serverLog.logDebug("HTTPC", handle + " initialized");
this.remoteProxyUse = false;
this.timeout = timeout;
this.savedRemoteHost = server;
-
+
try {
this.host = server + ((port == 80) ? "" : (":" + port));
String hostip;
@@ -320,19 +317,19 @@ public final class httpc {
hostip = dnsResolve(server);
if (hostip == null) throw new UnknownHostException(server);
}
-
+
// opening the socket
socket = (ssl) ? SSLSocketFactory.getDefault().createSocket(hostip, port)
: new Socket(hostip, port);
-
+
// registering the socket
this.socketOwner = this.registerOpenSocket(socket);
-
+
// setting socket timeout and keep alive behaviour
socket.setSoTimeout(timeout); // waiting time for write
//socket.setSoLinger(true, timeout); // waiting time for read
socket.setKeepAlive(true); //
-
+
// getting input and output streams
clientInput = new PushbackInputStream(socket.getInputStream());
clientOutput = socket.getOutputStream();
@@ -346,7 +343,7 @@ public final class httpc {
throw new IOException("unknown host: " + server);
}
}
-
+
void reset() {
if (this.clientInput != null) {
try {this.clientInput.close();} catch (Exception e) {}
@@ -362,17 +359,17 @@ public final class httpc {
this.socket = null;
this.socketOwner = null;
}
-
+
this.host = null;
this.timeout = 0;
this.handle = 0;
-
+
this.remoteProxyUse = false;
this.savedRemoteHost = null;
this.requestPath = null;
-
+
this.allowContentEncoding = true;
-
+
// shrink readlinebuffer if it is to large
this.readLineBuffer.reset(80);
}
@@ -400,28 +397,28 @@ public final class httpc {
4xx: Client Error - The request contains bad syntax or cannot be fulfilled
5xx: Server Error - The server failed to fulfill an apparently valid request
*/
-
+
// header information
public httpHeader responseHeader = null;
public String httpVer = "HTTP/0.9";
public String status; // the success/failure response string starting with status-code
private boolean gzip; // for gunzipping on-the-fly
private String encoding;
-
+
public response(boolean zipped) throws IOException {
-
+
// lets start with worst-case attributes as set-up
responseHeader = new httpHeader(reverseMappingCache);
status = "503 internal error";
gzip = false;
-
+
// check connection status
if (clientInput == null) {
// the server has meanwhile disconnected
status = "503 lost connection to server";
return; // in bad mood
}
-
+
// reads in the http header, right now, right here
byte[] b = serverCore.receive(clientInput, readLineBuffer, terminalMaxLength, false);
if (b == null) {
@@ -440,10 +437,10 @@ public final class httpc {
}
// the http version reported by the server
this.httpVer = buffer.substring(0,p);
-
+
// we have a status
status = buffer.substring(p + 1).trim(); // the status code plus reason-phrase
-
+
// check validity
if (status.startsWith("400")) {
// bad request
@@ -451,7 +448,7 @@ public final class httpc {
while ((b = serverCore.receive(clientInput, readLineBuffer, terminalMaxLength, false)).length != 0) {}
return; // in bad mood
}
-
+
// at this point we should have a valid response. read in the header properties
String key = "";
while ((b = serverCore.receive(clientInput, readLineBuffer, terminalMaxLength, false)) != null) {
@@ -476,17 +473,17 @@ public final class httpc {
}
}
// finished with reading header
-
+
// we will now manipulate the header if the content is gzip encoded, because
// reading the content with "writeContent" will gunzip on-the-fly
gzip = ((zipped) && (responseHeader.gzip()));
-
+
if (gzip) {
responseHeader.remove("CONTENT-ENCODING"); // we fake that we don't have encoding, since what comes out does not have gzip and we also don't know what was encoded
responseHeader.remove("CONTENT-LENGTH"); // we cannot use the length during gunzippig yet; still we can hope that it works
}
}
-
+
public String toString() {
StringBuffer toStringBuffer = new StringBuffer();
toStringBuffer.append((this.status == null) ? "Status: Unknown" : "Status: " + this.status)
@@ -494,25 +491,25 @@ public final class httpc {
.append((this.responseHeader == null) ? "none" : this.responseHeader.toString());
return toStringBuffer.toString();
}
-
+
public boolean success() {
return ((status.charAt(0) == '2') || (status.charAt(0) == '3'));
}
-
+
public byte[] writeContent() throws IOException {
int contentLength = (int) this.responseHeader.contentLength();
serverByteBuffer sbb = new serverByteBuffer((contentLength==-1)?8192:contentLength);
writeContentX(null, sbb, httpc.this.clientInput);
return sbb.getBytes();
}
-
+
public byte[] writeContent(OutputStream procOS) throws IOException {
int contentLength = (int) this.responseHeader.contentLength();
serverByteBuffer sbb = new serverByteBuffer((contentLength==-1)?8192:contentLength);
writeContentX(procOS, sbb, httpc.this.clientInput);
return sbb.getBytes();
}
-
+
public void writeContent(OutputStream procOS, File file) throws IOException {
// this writes the input stream to either another output stream or
// a file or both.
@@ -527,7 +524,7 @@ public final class httpc {
}
}
}
-
+
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
@@ -538,13 +535,13 @@ public final class httpc {
byte[] buffer = new byte[2048];
int l;
long len = 0;
-
+
// find out length
long length = this.responseHeader.contentLength();
-
+
// using the proper intput stream
InputStream dis = (this.gzip) ? (InputStream) new GZIPInputStream(clientInput) : (InputStream) clientInput;
-
+
// we have three methods of reading: length-based, length-based gzip and connection-close-based
try {
if (length > 0) {
@@ -576,26 +573,26 @@ public final class httpc {
buffer = null;
}
}
-
+
public void print() {
serverLog.logInfo("HTTPC", "RESPONSE: status=" + status + ", header=" + responseHeader.toString());
}
-
+
}
-
+
// 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
-
+
// check and correct path
if ((path == null) || (path.length() == 0)) path = "/";
-
+
// for debuggug:
requestPath = path;
-
+
// prepare header
if (header == null) header = new httpHeader();
-
+
// set some standard values
if (!(header.containsKey(httpHeader.ACCEPT)))
header.put(httpHeader.ACCEPT, "text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5");
@@ -605,12 +602,12 @@ public final class httpc {
header.put(httpHeader.ACCEPT_LANGUAGE, "en-us,en;q=0.5");
if (!(header.containsKey(httpHeader.KEEP_ALIVE)))
header.put(httpHeader.KEEP_ALIVE, "300");
-
+
// set user agent. The user agent is only set if the value does not yet exists.
// this gives callers the opportunity, to change the user agent themselves, and
// it will not be changed.
if (!(header.containsKey(httpHeader.USER_AGENT))) header.put(httpHeader.USER_AGENT, userAgent);
-
+
// set the host attribute. This is in particular necessary, if we contact another proxy
// the host is mandatory, if we use HTTP/1.1
if (!(header.containsKey(httpHeader.HOST))) {
@@ -619,11 +616,11 @@ public final class httpc {
else
header.put(httpHeader.HOST, this.host);
}
-
+
if (!(header.containsKey(httpHeader.CONNECTION))) {
header.put(httpHeader.CONNECTION, "close");
}
-
+
// advertise a little bit...
if ((!(header.containsKey(httpHeader.REFERER))) || (((String) header.get(httpHeader.REFERER)).trim().length() == 0)) {
header.put(httpHeader.REFERER,
@@ -631,7 +628,7 @@ public final class httpc {
"http://www.anomic.de" :
"http://www.yacy.net/yacy");
}
-
+
// stimulate zipping or not
// we can unzip, and we will return it always as unzipped, unless not wanted
if (header.containsKey(httpHeader.ACCEPT_ENCODING)) {
@@ -653,14 +650,14 @@ public final class httpc {
} else {
if (zipped) header.put(httpHeader.ACCEPT_ENCODING, "gzip,deflate");
}
-
+
//header = new httpHeader(); header.put("Host", this.host); // debug
-
+
// send request
if ((this.remoteProxyUse) && (!(method.equals(httpHeader.METHOD_CONNECT))))
path = "http://" + this.savedRemoteHost + path;
serverCore.send(clientOutput, method + " " + path + " HTTP/1.0"); // if set to HTTP/1.1, servers give time-outs?
-
+
// send header
//System.out.println("***HEADER for path " + path + ": PROXY TO SERVER = " + header.toString()); // DEBUG
Iterator i = header.keySet().iterator();
@@ -678,14 +675,14 @@ public final class httpc {
//System.out.println("#" + key + ": " + value);
}
}
-
+
// send terminating line
serverCore.send(this.clientOutput, "");
this.clientOutput.flush();
-
+
// this is the place where www.stern.de refuses to answer ..???
}
-
+
public response GET(String path, httpHeader requestHeader) throws IOException {
//serverLog.logDebug("HTTPC", handle + " requested GET '" + path + "', time = " + (System.currentTimeMillis() - handle));
try {
@@ -698,7 +695,7 @@ public final class httpc {
throw new IOException(e.getMessage());
}
}
-
+
public response HEAD(String path, httpHeader requestHeader) throws IOException {
try {
send(httpHeader.METHOD_HEAD, path, requestHeader, false);
@@ -709,7 +706,7 @@ public final class httpc {
throw new IOException(e.getMessage());
}
}
-
+
public response POST(String path, httpHeader requestHeader, InputStream ins) throws IOException {
try {
send(httpHeader.METHOD_POST, path, requestHeader, false);
@@ -738,7 +735,7 @@ public final class httpc {
throw new IOException(e.getMessage());
}
}
-
+
public response CONNECT(String host, int port, httpHeader requestHeader) throws IOException {
try {
send(httpHeader.METHOD_CONNECT, host + ":" + port, requestHeader, false);
@@ -747,8 +744,8 @@ public final class httpc {
throw new IOException(e.getMessage());
}
}
-
-
+
+
public response POST(String path, httpHeader requestHeader, serverObjects args, Hashtable files) throws IOException {
// make shure, the header has a boundary information like
// CONTENT-TYPE=multipart/form-data; boundary=----------0xKhTmLbOuNdArY
@@ -768,7 +765,7 @@ public final class httpc {
pos = boundary.indexOf("boundary=");
}
boundary = "--" + boundary.substring(pos + "boundary=".length());
-
+
ByteArrayOutputStream buf = new ByteArrayOutputStream();
// in contrast to GET and HEAD, this method also transports a message body
// the body consists of repeated boundaries and values in between
@@ -816,47 +813,47 @@ public final class httpc {
// send the body
//System.out.println("body=" + buf.toString());
serverCore.send(clientOutput, body);
-
+
return new response(false);
}
-
+
/*
DEBUG: PUT BODY=------------1090358578442
Content-Disposition: form-data; name="youare"
-
+
Ty2F86ekSWM5
------------1090358578442
Content-Disposition: form-data; name="key"
-
+
6EkPPOl7
------------1090358578442
Content-Disposition: form-data; name="iam"
-
+
HnTvzwV7SCJR
------------1090358578442
Content-Disposition: form-data; name="process"
-
+
permission
------------1090358578442
-
+
*/
-
+
/*
------------0xKhTmLbOuNdArY
Content-Disposition: form-data; name="file1"; filename="dir.gif"
Content-Type: image/gif
-
+
GIF89
------------0xKhTmLbOuNdArY
Content-Disposition: form-data; name="file2"; filename=""
-
-
+
+
------------0xKhTmLbOuNdArY
Content-Disposition: form-data; name="upload"
-
+
do upload
------------0xKhTmLbOuNdArY--
-
+
###### Listing Properties ######
# METHOD=POST
### Header Values:
@@ -873,7 +870,7 @@ do upload
### Call Properties:
###### End OfList ######
*/
-
+
public static byte[] singleGET(String host, int port, String path, int timeout,
String user, String password, boolean ssl,
String proxyHost, int proxyPort,
@@ -882,16 +879,16 @@ do upload
if ((user != null) && (password != null) && (user.length() != 0)) {
requestHeader.put(httpHeader.AUTHORIZATION, serverCodings.standardCoder.encodeBase64String(user + ":" + password));
}
-
+
httpc con = null;
try {
-
+
if ((proxyHost == null) || (proxyPort == 0)) {
con = httpc.getInstance(host, port, timeout, ssl);
} else {
con = httpc.getInstance(host, port, timeout, ssl, proxyHost, proxyPort);
}
-
+
httpc.response res = con.GET(path, null);
if (res.status.startsWith("2")) {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
@@ -906,9 +903,9 @@ do upload
} finally {
if (con != null) httpc.returnInstance(con);
}
-
+
}
-
+
public static byte[] singleGET(URL u, int timeout,
String user, String password,
String proxyHost, int proxyPort) throws IOException {
@@ -920,7 +917,7 @@ do upload
if ((query != null) && (query.length() > 0)) path = path + "?" + query;
return singleGET(u.getHost(), port, path, timeout, user, password, ssl, proxyHost, proxyPort, null);
}
-
+
/*
public static byte[] singleGET(String url, int timeout) throws IOException {
try {
@@ -930,17 +927,17 @@ do upload
}
}
*/
-
+
public static byte[] singlePOST(String host, int port, String path, int timeout,
String user, String password, boolean ssl,
String proxyHost, int proxyPort,
httpHeader requestHeader, serverObjects props) throws IOException {
-
+
if (requestHeader == null) requestHeader = new httpHeader();
if ((user != null) && (password != null) && (user.length() != 0)) {
requestHeader.put(httpHeader.AUTHORIZATION, serverCodings.standardCoder.encodeBase64String(user + ":" + password));
}
-
+
httpc con = null;
try {
if ((proxyHost == null) || (proxyPort == 0))
@@ -948,7 +945,7 @@ do upload
else
con = httpc.getInstance(host, port, timeout, ssl, proxyHost, proxyPort);
httpc.response res = con.POST(path, null, props, null);
-
+
//System.out.println("response=" + res.toString());
if (res.status.startsWith("2")) {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
@@ -963,9 +960,9 @@ do upload
} finally {
if (con != null) httpc.returnInstance(con);
}
-
+
}
-
+
public static byte[] singlePOST(URL u, int timeout,
String user, String password,
String proxyHost, int proxyPort,
@@ -978,7 +975,7 @@ do upload
if ((query != null) && (query.length() > 0)) path = path + "?" + query;
return singlePOST(u.getHost(), port, path, timeout, user, password, ssl, proxyHost, proxyPort, null, props);
}
-
+
public static byte[] singlePOST(String url, int timeout, serverObjects props) throws IOException {
try {
return singlePOST(new URL(url), timeout, null, null, null, 0, props);
@@ -986,7 +983,7 @@ do upload
throw new IOException("Malformed URL: " + e.getMessage());
}
}
-
+
public static Vector wget(URL url, int timeout, String user, String password, String proxyHost, int proxyPort) throws IOException {
// splitting of the byte array into lines
byte[] a = singleGET(url, timeout, user, password, proxyHost, proxyPort);
@@ -1001,7 +998,7 @@ do upload
}
return v;
}
-
+
public static httpHeader whead(URL url, int timeout, String user, String password, String proxyHost, int proxyPort) throws IOException {
// generate request header
httpHeader requestHeader = new httpHeader();
@@ -1009,7 +1006,7 @@ do upload
requestHeader.put(httpHeader.AUTHORIZATION, serverCodings.standardCoder.encodeBase64String(user + ":" + password));
}
// parse query
-
+
int port = url.getPort();
boolean ssl = url.getProtocol().equals("https");
if (port < 0) port = (ssl) ? 443 : 80;
@@ -1017,14 +1014,14 @@ do upload
String query = url.getQuery();
if ((query != null) && (query.length() > 0)) path = path + "?" + query;
String host = url.getHost();
-
+
// start connection
httpc con = null;
try {
if ((proxyHost == null) || (proxyPort == 0))
con = httpc.getInstance(host, port, timeout, ssl);
else con = httpc.getInstance(host, port, timeout, ssl, proxyHost, proxyPort);
-
+
httpc.response res = con.HEAD(path, requestHeader);
if (res.status.startsWith("2")) {
// success
@@ -1039,7 +1036,7 @@ do upload
if (con != null) httpc.returnInstance(con);
}
}
-
+
/*
public static Vector wget(String url) {
try {
@@ -1051,7 +1048,7 @@ do upload
}
}
*/
-
+
public static Vector wput(URL url, int timeout, String user, String password, String proxyHost, int proxyPort, serverObjects props) throws IOException {
// splitting of the byte array into lines
byte[] a = singlePOST(url, timeout, user, password, proxyHost, proxyPort, props);
@@ -1066,7 +1063,7 @@ do upload
}
return v;
}
-
+
/*
public static Vector wput(String url, serverObjects props) {
try {
@@ -1080,7 +1077,7 @@ do upload
}
}
*/
-
+
public static void main(String[] args) {
System.out.println("ANOMIC.DE HTTP CLIENT v" + vDATE);
String url = args[0];
@@ -1109,13 +1106,13 @@ do upload
Enumeration i = text.elements();
while (i.hasMoreElements()) System.out.println((String) i.nextElement());
}
-
+
/**
* To register an open socket.
- * This adds the socket to the list of open sockets where the current thread
- * is is the owner.
+ * This adds the socket to the list of open sockets where the current thread
+ * is is the owner.
* @param openedSocket the socket that should be registered
- * @return the id of the current thread
+ * @return the id of the current thread
*/
private Thread registerOpenSocket(Socket openedSocket) {
Thread currentThread = Thread.currentThread();
@@ -1131,20 +1128,20 @@ do upload
openSockets.add(openedSocket);
}
return currentThread;
- }
+ }
}
-
+
/**
* Closing all sockets that were opened in the context of the thread
- * with the given thread id
+ * with the given thread id
* @param threadId
*/
public static int closeOpenSockets(Thread thread) {
-
- // getting all still opened sockets
+
+ // getting all still opened sockets
ArrayList openSockets = (ArrayList) httpc.getRegisteredOpenSockets(thread).clone();
int closedSocketCount = 0;
-
+
// looping through the list of sockets and close each one
for (int socketCount = 0; socketCount < openSockets.size(); socketCount++) {
Socket openSocket = (Socket) openSockets.get(0);
@@ -1158,12 +1155,12 @@ do upload
httpc.unregisterOpenSocket(openSocket,thread);
} catch (Exception ex) {}
}
-
+
return closedSocketCount;
}
-
+
/**
- * Unregistering the socket.
+ * Unregistering the socket.
* The socket will be removed from the list of sockets where the thread with the
* given thread id is the owner.
* @param closedSocket the socket that should be unregistered
@@ -1181,19 +1178,19 @@ do upload
}
}
}
- }
+ }
}
-
+
/**
* Getting a list of open sockets where the current thread is
- * the owner
+ * the owner
* @return the list of open sockets
*/
public static ArrayList getRegisteredOpenSockets() {
Thread currentThread = Thread.currentThread();
- return getRegisteredOpenSockets(currentThread);
+ return getRegisteredOpenSockets(currentThread);
}
-
+
/**
* Getting a list of open sockets where the thread with the given
* thread id is the owner
@@ -1209,9 +1206,9 @@ do upload
openSockets = new ArrayList(0);
}
return openSockets;
- }
- }
-
+ }
+ }
+
}
/*
@@ -1220,27 +1217,27 @@ import java.io.*;
import javax.net.ssl.*;
import javax.security.cert.X509Certificate;
import java.security.KeyStore;
-
-
+
+
//The application can be modified to connect to a server outside
//the firewall by following SSLSocketClientWithTunneling.java.
-
+
public class SSLSocketClientWithClientAuth {
-
+
public static void main(String[] args) throws Exception {
String host = null;
int port = -1;
String path = null;
for (int i = 0; i < args.length; i++)
System.out.println(args[i]);
-
+
if (args.length < 3) {
System.out.println(
"USAGE: java SSLSocketClientWithClientAuth " +
"host port requestedfilepath");
System.exit(-1);
}
-
+
try {
host = args[0];
port = Integer.parseInt(args[1]);
@@ -1250,34 +1247,34 @@ public class SSLSocketClientWithClientAuth {
"host port requestedfilepath");
System.exit(-1);
}
-
+
try {
-
+
SSLSocketFactory factory = null;
try {
SSLContext ctx;
KeyManagerFactory kmf;
KeyStore ks;
char[] passphrase = "passphrase".toCharArray();
-
+
ctx = SSLContext.getInstance("TLS");
kmf = KeyManagerFactory.getInstance("SunX509");
ks = KeyStore.getInstance("JKS");
-
+
ks.load(new FileInputStream("testkeys"), passphrase);
-
+
kmf.init(ks, passphrase);
ctx.init(kmf.getKeyManagers(), null, null);
-
+
factory = ctx.getSocketFactory();
} catch (Exception e) {
throw new IOException(e.getMessage());
}
-
+
SSLSocket socket = (SSLSocket)factory.createSocket(host, port);
-
+
socket.startHandshake();
-
+
PrintWriter out = new PrintWriter(
new BufferedWriter(
new OutputStreamWriter(
@@ -1285,24 +1282,24 @@ public class SSLSocketClientWithClientAuth {
out.println("GET " + path + " HTTP/1.1");
out.println();
out.flush();
-
+
if (out.checkError())
System.out.println(
"SSLSocketClient: java.io.PrintWriter error");
-
+
BufferedReader in = new BufferedReader(
new InputStreamReader(
socket.getInputStream()));
-
+
String inputLine;
-
+
while ((inputLine = in.readLine()) != null)
System.out.println(inputLine);
-
+
in.close();
out.close();
socket.close();
-
+
} catch (Exception e) {
e.printStackTrace();
}
@@ -1311,29 +1308,29 @@ public class SSLSocketClientWithClientAuth {
*/
final class httpcFactory implements org.apache.commons.pool.PoolableObjectFactory {
-
+
public httpcFactory() {
super();
}
-
+
/**
* @see org.apache.commons.pool.PoolableObjectFactory#makeObject()
*/
public Object makeObject() throws Exception {
return new httpc();
}
-
+
/**
* @see org.apache.commons.pool.PoolableObjectFactory#destroyObject(java.lang.Object)
*/
public void destroyObject(Object obj) {
if (obj instanceof httpc) {
httpc theHttpc = (httpc) obj;
-
+
theHttpc.removedFromPool = true;
}
}
-
+
/**
* @see org.apache.commons.pool.PoolableObjectFactory#validateObject(java.lang.Object)
*/
@@ -1344,7 +1341,7 @@ final class httpcFactory implements org.apache.commons.pool.PoolableObjectFactor
}
return true;
}
-
+
/**
* @param obj
*
@@ -1352,7 +1349,7 @@ final class httpcFactory implements org.apache.commons.pool.PoolableObjectFactor
public void activateObject(Object obj) {
//log.debug(" activateObject...");
}
-
+
/**
* @param obj
*
@@ -1377,19 +1374,19 @@ final class httpcPool extends GenericObjectPool {
this.setMinEvictableIdleTimeMillis(30000); //Evictor runs every 30 secs.
//this.setMaxWait(1000); // Wait 1 second till a thread is available
}
-
+
public httpcPool(httpcFactory objFactory,
GenericObjectPool.Config config) {
super(objFactory, config);
}
-
+
/**
* @see org.apache.commons.pool.impl.GenericObjectPool#borrowObject()
*/
public Object borrowObject() throws Exception {
return super.borrowObject();
}
-
+
/**
* @see org.apache.commons.pool.impl.GenericObjectPool#returnObject(java.lang.Object)
*/