Browse Source

SPR-8367 - 3.1.0.M2 update of the RestTemplate for Apache HTTP Components will default to sending 2 requests on authentication and doesn't support HttpContext parameters without significant extention/rewrite

pull/7/head
Arjen Poutsma 13 years ago
parent
commit
f9144ea1ea
  1. 14
      org.springframework.web/src/main/java/org/springframework/http/client/HttpComponentsClientHttpRequest.java
  2. 25
      org.springframework.web/src/main/java/org/springframework/http/client/HttpComponentsClientHttpRequestFactory.java

14
org.springframework.web/src/main/java/org/springframework/http/client/HttpComponentsClientHttpRequest.java

@ -21,6 +21,9 @@ import java.net.URI; @@ -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; @@ -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 @@ -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 @@ -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);
}

25
org.springframework.web/src/main/java/org/springframework/http/client/HttpComponentsClientHttpRequestFactory.java

@ -19,6 +19,10 @@ package org.springframework.http.client; @@ -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; @@ -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 @@ -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 @@ -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.
* <p>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

Loading…
Cancel
Save