just cosmetics - keeping my baby clean :-)

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@7656 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
sixcooler 14 years ago
parent e402622584
commit 8d63f3b70f

@ -150,17 +150,17 @@ public class HTTPClient {
* HTTP connection settings * HTTP connection settings
*/ */
// timeout in milliseconds until a connection is established in milliseconds // timeout in milliseconds until a connection is established in milliseconds
HttpConnectionParams.setConnectionTimeout(httpParams, 9500); HttpConnectionParams.setConnectionTimeout(httpParams, 6000);
// SO_LINGER affects the socket close operation in seconds // SO_LINGER affects the socket close operation in seconds
// HttpConnectionParams.setLinger(httpParams, 6); // HttpConnectionParams.setLinger(httpParams, 6);
// HttpConnectionParams.setSocketBufferSize(httpParams, 8192); // HttpConnectionParams.setSocketBufferSize(httpParams, 8192);
// SO_TIMEOUT: maximum period inactivity between two consecutive data packets in milliseconds // SO_TIMEOUT: maximum period inactivity between two consecutive data packets in milliseconds
HttpConnectionParams.setSoTimeout(httpParams, 9900); HttpConnectionParams.setSoTimeout(httpParams, 1000);
// getting an I/O error when executing a request over a connection that has been closed at the server side // getting an I/O error when executing a request over a connection that has been closed at the server side
HttpConnectionParams.setStaleCheckingEnabled(httpParams, true); HttpConnectionParams.setStaleCheckingEnabled(httpParams, true);
// conserve bandwidth by minimizing the number of segments that are sent // conserve bandwidth by minimizing the number of segments that are sent
HttpConnectionParams.setTcpNoDelay(httpParams, false); HttpConnectionParams.setTcpNoDelay(httpParams, false);
// TODO: testing reuse of socket - there will be HttpConnectionParams.setSoReuseaddr(HttpParams params, boolean reuseaddr) in core-4.1 // Defines whether the socket can be bound even though a previous connection is still in a timeout state.
HttpConnectionParams.setSoReuseaddr(httpParams, true); HttpConnectionParams.setSoReuseaddr(httpParams, true);
httpClient = new DefaultHttpClient(clientConnectionManager, httpParams); httpClient = new DefaultHttpClient(clientConnectionManager, httpParams);
@ -195,6 +195,16 @@ public class HTTPClient {
} }
/**
* this method sets a host on which more than the default of 2 router per host are allowed
*
* @param the host to be raised in 'route per host'
*/
public static void setMaxRouteHost(final String host) {
HttpHost mHost = new HttpHost(host);
((ThreadSafeClientConnManager) httpClient.getConnectionManager()).setMaxForRoute(new HttpRoute(mHost), 50);
}
/** /**
* This method sets the Header used for the request * This method sets the Header used for the request
* *
@ -337,7 +347,7 @@ public class HTTPClient {
} }
/** /**
* This method POSTs a page from the server. * send data to the server named by uri
* *
* @param uri the url to post * @param uri the url to post
* @param parts to post * @param parts to post
@ -346,13 +356,27 @@ public class HTTPClient {
*/ */
public byte[] POSTbytes(final String uri, final Map<String, ContentBody> parts, final boolean usegzip) throws IOException { public byte[] POSTbytes(final String uri, final Map<String, ContentBody> parts, final boolean usegzip) throws IOException {
final MultiProtocolURI url = new MultiProtocolURI(uri); final MultiProtocolURI url = new MultiProtocolURI(uri);
return POSTbytes(url, url.getHost(), parts, usegzip);
}
/**
* send data to the server named by vhost
*
* @param url address of the server
* @param vhost name of the server at address which should respond
* @param post data to send (name-value-pairs)
* @param usegzip if the body should be gzipped
* @return response body
* @throws IOException
*/
public byte[] POSTbytes(final MultiProtocolURI url, final String vhost, final Map<String, ContentBody> post, final boolean usegzip) throws IOException {
final HttpPost httpPost = new HttpPost(url.toNormalform(true, false, true, false)); final HttpPost httpPost = new HttpPost(url.toNormalform(true, false, true, false));
String host = url.getHost();
if (host == null) host = "127.0.0.1"; setHost(vhost); // overwrite resolved IP, needed for shared web hosting DO NOT REMOVE, see http://en.wikipedia.org/wiki/Shared_web_hosting_service
setHost(host); // overwrite resolved IP, needed for shared web hosting DO NOT REMOVE, see http://en.wikipedia.org/wiki/Shared_web_hosting_service if (vhost == null) setHost("127.0.0.1");
final MultipartEntity multipartEntity = new MultipartEntity(); final MultipartEntity multipartEntity = new MultipartEntity();
for (final Entry<String,ContentBody> part : parts.entrySet()) for (final Entry<String,ContentBody> part : post.entrySet())
multipartEntity.addPart(part.getKey(), part.getValue()); multipartEntity.addPart(part.getKey(), part.getValue());
// statistics // statistics
upbytes = multipartEntity.getContentLength(); upbytes = multipartEntity.getContentLength();
@ -366,6 +390,15 @@ public class HTTPClient {
return getContentBytes(httpPost, Long.MAX_VALUE); return getContentBytes(httpPost, Long.MAX_VALUE);
} }
/**
* send stream-data to the server named by uri
*
* @param uri the url to post
* @param instream the stream to send
* @param length the length of the stream
* @return content bytes
* @throws IOException
*/
public byte[] POSTbytes(final String uri, final InputStream instream, long length) throws IOException { public byte[] POSTbytes(final String uri, final InputStream instream, long length) throws IOException {
final MultiProtocolURI url = new MultiProtocolURI(uri); final MultiProtocolURI url = new MultiProtocolURI(uri);
final HttpPost httpPost = new HttpPost(url.toNormalform(true, false, true, false)); final HttpPost httpPost = new HttpPost(url.toNormalform(true, false, true, false));
@ -381,27 +414,6 @@ public class HTTPClient {
return getContentBytes(httpPost, Long.MAX_VALUE); return getContentBytes(httpPost, Long.MAX_VALUE);
} }
/**
* send data to the server named by vhost
*
* @param url address of the server
* @param vhost name of the server at address which should respond
* @param post data to send (name-value-pairs)
* @param usegzip if the body should be gzipped
* @return response body
* @throws IOException
*/
public byte[] POSTbytes(final MultiProtocolURI url, final String vhost, final Map<String, ContentBody> post, final boolean usegzip) throws IOException {
this.setHost(vhost);
byte[] b;
try {
b = this.POSTbytes(url.toNormalform(true, false, true, false), post, usegzip);
} finally {
this.finish();
}
return b;
}
/** /**
* *
* @return HttpResponse from call * @return HttpResponse from call

Loading…
Cancel
Save