Skip to content

Remove deprecated HttpComponents5Connection usage #1497

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
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;
Expand All @@ -56,6 +57,8 @@ public class HttpComponents5Connection extends AbstractHttpSenderConnection {

private final HttpClient httpClient;

private final HttpHost httpHost;

private final HttpPost httpPost;

private final HttpContext httpContext;
Expand All @@ -64,16 +67,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;
}
Expand All @@ -84,12 +94,11 @@ public HttpResponse getHttpResponse() {

@Override
public void onClose() throws IOException {

if (this.httpResponse instanceof ClassicHttpResponse response) {

if (response.getEntity() != null) {
EntityUtils.consume(response.getEntity());
}
response.close();
}
}

Expand Down Expand Up @@ -121,20 +130,11 @@ protected OutputStream getRequestOutputStream() throws IOException {
}

@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);
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
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;
Expand Down Expand Up @@ -198,9 +199,10 @@ public WebServiceConnection createConnection(URI uri) throws IOException {
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);
}

/**
Expand Down