Merge pull request #1469 from bclozel
* pr/1497: Polish "Remove deprecated HttpComponents5Connection usage" Remove deprecated HttpComponents5Connection usage Closes gh-1469
This commit is contained in:
@@ -31,6 +31,7 @@ import org.apache.hc.core5.http.ClassicHttpResponse;
|
||||
import org.apache.hc.core5.http.ContentType;
|
||||
import org.apache.hc.core5.http.HttpEntity;
|
||||
import org.apache.hc.core5.http.HttpHeaders;
|
||||
import org.apache.hc.core5.http.HttpHost;
|
||||
import org.apache.hc.core5.http.HttpResponse;
|
||||
import org.apache.hc.core5.http.NameValuePair;
|
||||
import org.apache.hc.core5.http.io.entity.ByteArrayEntity;
|
||||
@@ -43,19 +44,23 @@ import org.springframework.ws.transport.WebServiceConnection;
|
||||
|
||||
/**
|
||||
* Implementation of {@link WebServiceConnection} that is based on Apache HttpClient 5.
|
||||
* Exposes a {@link HttpPost} and {@link HttpResponse}.
|
||||
* Exposes the {@linkplain #getHttpHost() HTTP host}, {@linkplain #getHttpPost() HTTP
|
||||
* port}, and {@linkplain #getHttpResponse() HTTP response}.
|
||||
*
|
||||
* @author Alan Stewart
|
||||
* @author Barry Pitman
|
||||
* @author Arjen Poutsma
|
||||
* @author Greg Turnquist
|
||||
* @author Lars Uffmann
|
||||
* @author Brian Clozel
|
||||
* @since 4.0.5
|
||||
*/
|
||||
public class HttpComponents5Connection extends AbstractHttpSenderConnection {
|
||||
|
||||
private final HttpClient httpClient;
|
||||
|
||||
private final HttpHost httpHost;
|
||||
|
||||
private final HttpPost httpPost;
|
||||
|
||||
private final HttpContext httpContext;
|
||||
@@ -64,16 +69,23 @@ public class HttpComponents5Connection extends AbstractHttpSenderConnection {
|
||||
|
||||
private ByteArrayOutputStream requestBuffer;
|
||||
|
||||
protected HttpComponents5Connection(HttpClient httpClient, HttpPost httpPost, HttpContext httpContext) {
|
||||
protected HttpComponents5Connection(HttpClient httpClient, HttpHost httpHost, HttpPost httpPost,
|
||||
HttpContext httpContext) {
|
||||
|
||||
Assert.notNull(httpClient, "httpClient must not be null");
|
||||
Assert.notNull(httpHost, "httpHost must not be null");
|
||||
Assert.notNull(httpPost, "httpPost must not be null");
|
||||
|
||||
this.httpClient = httpClient;
|
||||
this.httpHost = httpHost;
|
||||
this.httpPost = httpPost;
|
||||
this.httpContext = httpContext;
|
||||
}
|
||||
|
||||
public HttpHost getHttpHost() {
|
||||
return this.httpHost;
|
||||
}
|
||||
|
||||
public HttpPost getHttpPost() {
|
||||
return this.httpPost;
|
||||
}
|
||||
@@ -84,12 +96,11 @@ public class HttpComponents5Connection extends AbstractHttpSenderConnection {
|
||||
|
||||
@Override
|
||||
public void onClose() throws IOException {
|
||||
|
||||
if (this.httpResponse instanceof ClassicHttpResponse response) {
|
||||
|
||||
if (response.getEntity() != null) {
|
||||
EntityUtils.consume(response.getEntity());
|
||||
}
|
||||
response.close();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -121,20 +132,11 @@ public class HttpComponents5Connection extends AbstractHttpSenderConnection {
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("deprecation")
|
||||
protected void onSendAfterWrite(WebServiceMessage message) throws IOException {
|
||||
|
||||
String contentType = this.httpPost.getFirstHeader(HttpHeaders.CONTENT_TYPE).getValue();
|
||||
this.httpPost.setEntity(new ByteArrayEntity(this.requestBuffer.toByteArray(), ContentType.parse(contentType)));
|
||||
|
||||
this.requestBuffer = null;
|
||||
|
||||
if (this.httpContext != null) {
|
||||
this.httpResponse = this.httpClient.execute(this.httpPost, this.httpContext);
|
||||
}
|
||||
else {
|
||||
this.httpResponse = this.httpClient.execute(this.httpPost);
|
||||
}
|
||||
this.httpResponse = this.httpClient.executeOpen(this.httpHost, this.httpPost, this.httpContext);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -31,6 +31,7 @@ import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager;
|
||||
import org.apache.hc.core5.http.EntityDetails;
|
||||
import org.apache.hc.core5.http.HttpException;
|
||||
import org.apache.hc.core5.http.HttpHeaders;
|
||||
import org.apache.hc.core5.http.HttpHost;
|
||||
import org.apache.hc.core5.http.HttpRequest;
|
||||
import org.apache.hc.core5.http.HttpRequestInterceptor;
|
||||
import org.apache.hc.core5.http.protocol.HttpContext;
|
||||
@@ -198,9 +199,10 @@ public class HttpComponents5MessageSender extends AbstractHttpWebServiceMessageS
|
||||
HttpTransportConstants.CONTENT_ENCODING_GZIP);
|
||||
}
|
||||
|
||||
HttpHost httpHost = HttpHost.create(uri);
|
||||
HttpContext httpContext = createContext(uri);
|
||||
|
||||
return new HttpComponents5Connection(getHttpClient(), httpPost, httpContext);
|
||||
return new HttpComponents5Connection(getHttpClient(), httpHost, httpPost, httpContext);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user