Upgraded to Apache HttpComponents HttpClient 4.3.1 and HttpAsyncClient 4.0 GA, as well as Jackson 2.2.2
This commit is contained in:
@@ -28,8 +28,8 @@ import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.impl.nio.client.CloseableHttpAsyncClient;
|
||||
import org.apache.http.impl.nio.client.HttpAsyncClients;
|
||||
import org.apache.http.nio.client.HttpAsyncClient;
|
||||
import org.apache.http.nio.reactor.IOReactorStatus;
|
||||
import org.apache.http.protocol.HttpContext;
|
||||
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.util.Assert;
|
||||
@@ -37,7 +37,7 @@ import org.springframework.util.Assert;
|
||||
/**
|
||||
* Asynchronous extension of the {@link HttpComponentsClientHttpRequestFactory}. Uses
|
||||
* <a href="http://hc.apache.org/httpcomponents-asyncclient-dev/">Apache HttpComponents
|
||||
* HttpAsyncClient</a> to create requests.
|
||||
* HttpAsyncClient 4.0</a> to create requests.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @since 4.0
|
||||
@@ -75,13 +75,15 @@ public class HttpComponentsAsyncClientHttpRequestFactory
|
||||
* @param httpClient the HttpClient instance to use for this request factory
|
||||
* @param httpAsyncClient the HttpAsyncClient instance to use for this request factory
|
||||
*/
|
||||
public HttpComponentsAsyncClientHttpRequestFactory(CloseableHttpClient httpClient,
|
||||
CloseableHttpAsyncClient httpAsyncClient) {
|
||||
public HttpComponentsAsyncClientHttpRequestFactory(
|
||||
CloseableHttpClient httpClient, CloseableHttpAsyncClient httpAsyncClient) {
|
||||
|
||||
super(httpClient);
|
||||
Assert.notNull(httpAsyncClient, "'httpAsyncClient' must not be null");
|
||||
this.httpAsyncClient = httpAsyncClient;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the {@code HttpClient} used for
|
||||
* {@linkplain #createAsyncRequest(java.net.URI, org.springframework.http.HttpMethod) asynchronous execution}.
|
||||
@@ -105,7 +107,7 @@ public class HttpComponentsAsyncClientHttpRequestFactory
|
||||
|
||||
private void startAsyncClient() {
|
||||
CloseableHttpAsyncClient asyncClient = getHttpAsyncClient();
|
||||
if (asyncClient.getStatus() != IOReactorStatus.ACTIVE) {
|
||||
if (!asyncClient.isRunning()) {
|
||||
asyncClient.start();
|
||||
}
|
||||
}
|
||||
@@ -145,4 +147,5 @@ public class HttpComponentsAsyncClientHttpRequestFactory
|
||||
getHttpAsyncClient().close();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -52,12 +52,13 @@ import org.springframework.util.Assert;
|
||||
* @author Arjen Poutsma
|
||||
* @since 3.1
|
||||
*/
|
||||
public class HttpComponentsClientHttpRequestFactory
|
||||
implements ClientHttpRequestFactory, DisposableBean {
|
||||
public class HttpComponentsClientHttpRequestFactory implements ClientHttpRequestFactory, DisposableBean {
|
||||
|
||||
private CloseableHttpClient httpClient;
|
||||
|
||||
private int connectTimeout;
|
||||
|
||||
private int socketTimeout;
|
||||
private CloseableHttpClient httpClient;
|
||||
|
||||
private boolean bufferRequestBody = true;
|
||||
|
||||
@@ -80,6 +81,7 @@ public class HttpComponentsClientHttpRequestFactory
|
||||
this.httpClient = httpClient;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the {@code HttpClient} used for
|
||||
* {@linkplain #createRequest(URI, HttpMethod) synchronous execution}.
|
||||
@@ -118,7 +120,6 @@ public class HttpComponentsClientHttpRequestFactory
|
||||
|
||||
/**
|
||||
* Indicates whether this request factory should buffer the request body internally.
|
||||
*
|
||||
* <p>Default is {@code true}. When sending large amounts of data via POST or PUT, it is
|
||||
* recommended to change this property to {@code false}, so as not to run out of memory.
|
||||
*/
|
||||
@@ -126,20 +127,11 @@ public class HttpComponentsClientHttpRequestFactory
|
||||
this.bufferRequestBody = bufferRequestBody;
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates whether this request factory should buffer the request body internally.
|
||||
*/
|
||||
public boolean isBufferRequestBody() {
|
||||
return bufferRequestBody;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public ClientHttpRequest createRequest(URI uri, HttpMethod httpMethod) throws IOException {
|
||||
CloseableHttpClient client = getHttpClient();
|
||||
Assert.state(client != null,
|
||||
"Synchronous execution requires an HttpClient to be set");
|
||||
Assert.state(client != null, "Synchronous execution requires an HttpClient to be set");
|
||||
HttpUriRequest httpRequest = createHttpUriRequest(httpMethod, uri);
|
||||
postProcessHttpRequest(httpRequest);
|
||||
HttpContext context = createHttpContext(httpMethod, uri);
|
||||
@@ -159,13 +151,14 @@ public class HttpComponentsClientHttpRequestFactory
|
||||
.setConnectTimeout(this.connectTimeout)
|
||||
.setSocketTimeout(this.socketTimeout)
|
||||
.build();
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
config = RequestConfig.DEFAULT;
|
||||
}
|
||||
}
|
||||
context.setAttribute(HttpClientContext.REQUEST_CONFIG, config);
|
||||
}
|
||||
if (bufferRequestBody) {
|
||||
if (this.bufferRequestBody) {
|
||||
return new HttpComponentsClientHttpRequest(client, httpRequest, context);
|
||||
}
|
||||
else {
|
||||
@@ -229,7 +222,7 @@ public class HttpComponentsClientHttpRequestFactory
|
||||
*/
|
||||
@Override
|
||||
public void destroy() throws Exception {
|
||||
httpClient.close();
|
||||
this.httpClient.close();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user