diff --git a/org.springframework.web/src/main/java/org/springframework/http/client/HttpComponentsClientHttpRequest.java b/org.springframework.web/src/main/java/org/springframework/http/client/HttpComponentsClientHttpRequest.java index db9493c063..16a5908e45 100644 --- a/org.springframework.web/src/main/java/org/springframework/http/client/HttpComponentsClientHttpRequest.java +++ b/org.springframework.web/src/main/java/org/springframework/http/client/HttpComponentsClientHttpRequest.java @@ -21,6 +21,9 @@ import java.net.URI; import java.util.List; import java.util.Map; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; + import org.apache.http.HttpEntity; import org.apache.http.HttpEntityEnclosingRequest; import org.apache.http.HttpResponse; @@ -28,9 +31,7 @@ import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpUriRequest; import org.apache.http.entity.ByteArrayEntity; import org.apache.http.protocol.HTTP; - -import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpMethod; +import org.apache.http.protocol.HttpContext; /** * {@link org.springframework.http.client.ClientHttpRequest} implementation that uses @@ -49,10 +50,13 @@ final class HttpComponentsClientHttpRequest extends AbstractBufferingClientHttpR private final HttpUriRequest httpRequest; + private final HttpContext httpContext; + - public HttpComponentsClientHttpRequest(HttpClient httpClient, HttpUriRequest httpRequest) { + public HttpComponentsClientHttpRequest(HttpClient httpClient, HttpUriRequest httpRequest, HttpContext httpContext) { this.httpClient = httpClient; this.httpRequest = httpRequest; + this.httpContext = httpContext; } @@ -81,7 +85,7 @@ final class HttpComponentsClientHttpRequest extends AbstractBufferingClientHttpR HttpEntity requestEntity = new ByteArrayEntity(bufferedOutput); entityEnclosingRequest.setEntity(requestEntity); } - HttpResponse httpResponse = this.httpClient.execute(this.httpRequest); + HttpResponse httpResponse = this.httpClient.execute(this.httpRequest, this.httpContext); return new HttpComponentsClientHttpResponse(httpResponse); } diff --git a/org.springframework.web/src/main/java/org/springframework/http/client/HttpComponentsClientHttpRequestFactory.java b/org.springframework.web/src/main/java/org/springframework/http/client/HttpComponentsClientHttpRequestFactory.java index f2a576c236..f5dee91ec9 100644 --- a/org.springframework.web/src/main/java/org/springframework/http/client/HttpComponentsClientHttpRequestFactory.java +++ b/org.springframework.web/src/main/java/org/springframework/http/client/HttpComponentsClientHttpRequestFactory.java @@ -19,6 +19,10 @@ package org.springframework.http.client; import java.io.IOException; import java.net.URI; +import org.springframework.beans.factory.DisposableBean; +import org.springframework.http.HttpMethod; +import org.springframework.util.Assert; + import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpDelete; import org.apache.http.client.methods.HttpGet; @@ -35,10 +39,7 @@ import org.apache.http.conn.ssl.SSLSocketFactory; import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager; import org.apache.http.params.CoreConnectionPNames; - -import org.springframework.beans.factory.DisposableBean; -import org.springframework.http.HttpMethod; -import org.springframework.util.Assert; +import org.apache.http.protocol.HttpContext; /** * {@link org.springframework.http.client.ClientHttpRequestFactory} implementation that uses @@ -126,11 +127,10 @@ public class HttpComponentsClientHttpRequestFactory implements ClientHttpRequest getHttpClient().getParams().setIntParameter(CoreConnectionPNames.SO_TIMEOUT, timeout); } - - public ClientHttpRequest createRequest(URI uri, HttpMethod httpMethod) throws IOException { + public ClientHttpRequest createRequest(URI uri, HttpMethod httpMethod) throws IOException { HttpUriRequest httpRequest = createHttpUriRequest(httpMethod, uri); postProcessHttpRequest(httpRequest); - return new HttpComponentsClientHttpRequest(getHttpClient(), httpRequest); + return new HttpComponentsClientHttpRequest(getHttpClient(), httpRequest, createHttpContext(httpMethod, uri)); } /** @@ -169,6 +169,17 @@ public class HttpComponentsClientHttpRequestFactory implements ClientHttpRequest protected void postProcessHttpRequest(HttpUriRequest request) { } + /** + * Template methods that creates a {@link HttpContext} for the given HTTP method and URI. + *
The default implementation returns {@code null}. + * @param httpMethod the HTTP method + * @param uri the URI + * @return the http context + */ + protected HttpContext createHttpContext(HttpMethod httpMethod, URI uri) { + return null; + } + /** * Shutdown hook that closes the underlying * {@link org.apache.http.conn.ClientConnectionManager ClientConnectionManager}'s