Package com.helger.httpclient
Class HttpClientManager
java.lang.Object
com.helger.httpclient.HttpClientManager
- All Implemented Interfaces:
AutoCloseable
A small wrapper around
CloseableHttpClient.- Author:
- Philip Helger
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected final voidvoidclose()static HttpClientManagercreate(HttpClientSettings aHttpClientSettings) <T> Texecute(org.apache.hc.client5.http.classic.methods.HttpUriRequest aRequest, org.apache.hc.core5.http.io.HttpClientResponseHandler<? extends T> aResponseHandler) Execute the provided request without any special context.<T> Texecute(org.apache.hc.core5.http.ClassicHttpRequest aRequest, org.apache.hc.core5.http.protocol.HttpContext aHttpContext, org.apache.hc.core5.http.io.HttpClientResponseHandler<? extends T> aResponseHandler) Execute the provided request with an optional special context.final booleanisClosed()
-
Constructor Details
-
HttpClientManager
public HttpClientManager() -
HttpClientManager
-
-
Method Details
-
close
public void close()- Specified by:
closein interfaceAutoCloseable
-
isClosed
public final boolean isClosed()- Returns:
trueif this manager is already closed, and no further requests can be executed,falseif this manager is not yet closed.- Since:
- 8.8.2
-
checkIfClosed
protected final void checkIfClosed() -
execute
@Nullable public <T> T execute(@Nonnull org.apache.hc.client5.http.classic.methods.HttpUriRequest aRequest, @Nonnull org.apache.hc.core5.http.io.HttpClientResponseHandler<? extends T> aResponseHandler) throws IOException Execute the provided request without any special context. The response handler is invoked as a callback. This method automatically cleans up all used resources and as such is preferred over the execute methods returning the CloseableHttpResponse.- Type Parameters:
T- return type- Parameters:
aRequest- The request to be executed. May not benull.aResponseHandler- The response handler to be executed. May not benull.- Returns:
- The evaluated response of the response handler. May be
null. - Throws:
IOException- In case of errorIllegalStateException- If this manager was already closed!
-
execute
@Nullable public <T> T execute(@Nonnull org.apache.hc.core5.http.ClassicHttpRequest aRequest, @Nullable org.apache.hc.core5.http.protocol.HttpContext aHttpContext, @Nonnull org.apache.hc.core5.http.io.HttpClientResponseHandler<? extends T> aResponseHandler) throws IOException Execute the provided request with an optional special context. The response handler is invoked as a callback. This method automatically cleans up all used resources and as such is preferred over the execute methods returning the CloseableHttpResponse.- Type Parameters:
T- return type- Parameters:
aRequest- The request to be executed. May not benull.aHttpContext- The optional context to be used. May benulltoaResponseHandler- The response handler to be executed. May not benull.- Returns:
- The evaluated response of the response handler. May be
null. - Throws:
IOException- In case of errorIllegalStateException- If this manager was already closed!
-
create
-