3131import org .apache .hc .core5 .http .ContentType ;
3232import org .apache .hc .core5 .http .HttpEntity ;
3333import org .apache .hc .core5 .http .HttpHeaders ;
34+ import org .apache .hc .core5 .http .HttpHost ;
3435import org .apache .hc .core5 .http .HttpResponse ;
3536import org .apache .hc .core5 .http .NameValuePair ;
3637import org .apache .hc .core5 .http .io .entity .ByteArrayEntity ;
@@ -56,6 +57,8 @@ public class HttpComponents5Connection extends AbstractHttpSenderConnection {
5657
5758 private final HttpClient httpClient ;
5859
60+ private final HttpHost httpHost ;
61+
5962 private final HttpPost httpPost ;
6063
6164 private final HttpContext httpContext ;
@@ -64,16 +67,23 @@ public class HttpComponents5Connection extends AbstractHttpSenderConnection {
6467
6568 private ByteArrayOutputStream requestBuffer ;
6669
67- protected HttpComponents5Connection (HttpClient httpClient , HttpPost httpPost , HttpContext httpContext ) {
70+ protected HttpComponents5Connection (HttpClient httpClient , HttpHost httpHost , HttpPost httpPost ,
71+ HttpContext httpContext ) {
6872
6973 Assert .notNull (httpClient , "httpClient must not be null" );
74+ Assert .notNull (httpHost , "httpHost must not be null" );
7075 Assert .notNull (httpPost , "httpPost must not be null" );
7176
7277 this .httpClient = httpClient ;
78+ this .httpHost = httpHost ;
7379 this .httpPost = httpPost ;
7480 this .httpContext = httpContext ;
7581 }
7682
83+ public HttpHost getHttpHost () {
84+ return this .httpHost ;
85+ }
86+
7787 public HttpPost getHttpPost () {
7888 return this .httpPost ;
7989 }
@@ -84,12 +94,11 @@ public HttpResponse getHttpResponse() {
8494
8595 @ Override
8696 public void onClose () throws IOException {
87-
8897 if (this .httpResponse instanceof ClassicHttpResponse response ) {
89-
9098 if (response .getEntity () != null ) {
9199 EntityUtils .consume (response .getEntity ());
92100 }
101+ response .close ();
93102 }
94103 }
95104
@@ -121,20 +130,11 @@ protected OutputStream getRequestOutputStream() throws IOException {
121130 }
122131
123132 @ Override
124- @ SuppressWarnings ("deprecation" )
125133 protected void onSendAfterWrite (WebServiceMessage message ) throws IOException {
126-
127134 String contentType = this .httpPost .getFirstHeader (HttpHeaders .CONTENT_TYPE ).getValue ();
128135 this .httpPost .setEntity (new ByteArrayEntity (this .requestBuffer .toByteArray (), ContentType .parse (contentType )));
129-
130136 this .requestBuffer = null ;
131-
132- if (this .httpContext != null ) {
133- this .httpResponse = this .httpClient .execute (this .httpPost , this .httpContext );
134- }
135- else {
136- this .httpResponse = this .httpClient .execute (this .httpPost );
137- }
137+ this .httpResponse = this .httpClient .executeOpen (this .httpHost , this .httpPost , this .httpContext );
138138 }
139139
140140 /*
0 commit comments