|
19 | 19 | import java.io.IOException;
|
20 | 20 | import java.net.URI;
|
21 | 21 |
|
| 22 | +import org.springframework.beans.factory.DisposableBean; |
| 23 | +import org.springframework.http.HttpMethod; |
| 24 | +import org.springframework.util.Assert; |
| 25 | + |
22 | 26 | import org.apache.http.client.HttpClient;
|
23 | 27 | import org.apache.http.client.methods.HttpDelete;
|
24 | 28 | import org.apache.http.client.methods.HttpGet;
|
|
35 | 39 | import org.apache.http.impl.client.DefaultHttpClient;
|
36 | 40 | import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
|
37 | 41 | import org.apache.http.params.CoreConnectionPNames;
|
38 |
| - |
39 |
| -import org.springframework.beans.factory.DisposableBean; |
40 |
| -import org.springframework.http.HttpMethod; |
41 |
| -import org.springframework.util.Assert; |
| 42 | +import org.apache.http.protocol.HttpContext; |
42 | 43 |
|
43 | 44 | /**
|
44 | 45 | * {@link org.springframework.http.client.ClientHttpRequestFactory} implementation that uses
|
@@ -126,11 +127,10 @@ public void setReadTimeout(int timeout) {
|
126 | 127 | getHttpClient().getParams().setIntParameter(CoreConnectionPNames.SO_TIMEOUT, timeout);
|
127 | 128 | }
|
128 | 129 |
|
129 |
| - |
130 |
| - public ClientHttpRequest createRequest(URI uri, HttpMethod httpMethod) throws IOException { |
| 130 | + public ClientHttpRequest createRequest(URI uri, HttpMethod httpMethod) throws IOException { |
131 | 131 | HttpUriRequest httpRequest = createHttpUriRequest(httpMethod, uri);
|
132 | 132 | postProcessHttpRequest(httpRequest);
|
133 |
| - return new HttpComponentsClientHttpRequest(getHttpClient(), httpRequest); |
| 133 | + return new HttpComponentsClientHttpRequest(getHttpClient(), httpRequest, createHttpContext(httpMethod, uri)); |
134 | 134 | }
|
135 | 135 |
|
136 | 136 | /**
|
@@ -169,6 +169,17 @@ protected HttpUriRequest createHttpUriRequest(HttpMethod httpMethod, URI uri) {
|
169 | 169 | protected void postProcessHttpRequest(HttpUriRequest request) {
|
170 | 170 | }
|
171 | 171 |
|
| 172 | + /** |
| 173 | + * Template methods that creates a {@link HttpContext} for the given HTTP method and URI. |
| 174 | + * <p>The default implementation returns {@code null}. |
| 175 | + * @param httpMethod the HTTP method |
| 176 | + * @param uri the URI |
| 177 | + * @return the http context |
| 178 | + */ |
| 179 | + protected HttpContext createHttpContext(HttpMethod httpMethod, URI uri) { |
| 180 | + return null; |
| 181 | + } |
| 182 | + |
172 | 183 | /**
|
173 | 184 | * Shutdown hook that closes the underlying
|
174 | 185 | * {@link org.apache.http.conn.ClientConnectionManager ClientConnectionManager}'s
|
|
0 commit comments