HTTPCLIENT-1235: Add javadoc to Executor to explain that response must be handled to avoid connection leakage
Contributed by Alf Høgemark <alf at i100.no> git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1390314 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
7985a45e97
commit
57c323a09d
|
@ -58,6 +58,12 @@ import org.apache.http.impl.client.HttpClientBuilder;
|
||||||
import org.apache.http.impl.conn.PoolingClientConnectionManager;
|
import org.apache.http.impl.conn.PoolingClientConnectionManager;
|
||||||
import org.apache.http.protocol.BasicHttpContext;
|
import org.apache.http.protocol.BasicHttpContext;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An Executor for fluent requests
|
||||||
|
* <p/>
|
||||||
|
* A {@link PoolingClientConnectionManager} with maximum 100 connections per route and
|
||||||
|
* a total maximum of 200 connections is used internally.
|
||||||
|
*/
|
||||||
public class Executor {
|
public class Executor {
|
||||||
|
|
||||||
final static PoolingClientConnectionManager CONNMGR;
|
final static PoolingClientConnectionManager CONNMGR;
|
||||||
|
@ -178,6 +184,14 @@ public class Executor {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Executes the request. Please Note that response content must be processed
|
||||||
|
* or discarded using {@link Response#discardContent()}, otherwise the
|
||||||
|
* connection used for the request might not be released to the pool.
|
||||||
|
*
|
||||||
|
* @see Response#handleResponse(org.apache.http.client.ResponseHandler)
|
||||||
|
* @see Response#discardContent()
|
||||||
|
*/
|
||||||
public Response execute(
|
public Response execute(
|
||||||
final Request request) throws ClientProtocolException, IOException {
|
final Request request) throws ClientProtocolException, IOException {
|
||||||
this.localContext.setAttribute(ClientContext.CREDS_PROVIDER, this.credentialsProvider);
|
this.localContext.setAttribute(ClientContext.CREDS_PROVIDER, this.credentialsProvider);
|
||||||
|
|
|
@ -68,10 +68,16 @@ public class Response {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Discards response content and deallocates all resources associated with it.
|
||||||
|
*/
|
||||||
public void discardContent() {
|
public void discardContent() {
|
||||||
dispose();
|
dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles the response using the specified {@link ResponseHandler}
|
||||||
|
*/
|
||||||
public <T> T handleResponse(
|
public <T> T handleResponse(
|
||||||
final ResponseHandler<T> handler) throws ClientProtocolException, IOException {
|
final ResponseHandler<T> handler) throws ClientProtocolException, IOException {
|
||||||
assertNotConsumed();
|
assertNotConsumed();
|
||||||
|
|
Loading…
Reference in New Issue