@@ -63,16 +63,15 @@ public class HttpComponents5MessageSender extends AbstractHttpWebServiceMessageS
6363
6464 private static final String HTTP_CLIENT_ALREADY_SET = "httpClient already set" ;
6565
66- private HttpClient httpClient ;
66+ private final HttpComponents5ClientFactory clientFactory ;
6767
68- private HttpComponents5ClientFactory clientFactory ;
68+ private HttpClient httpClient ;
6969
7070 /**
7171 * Create a new instance of the {@code HttpClientMessageSender} with a default
7272 * {@link HttpClient} that uses a default {@link PoolingHttpClientConnectionManager}.
7373 */
7474 public HttpComponents5MessageSender () {
75-
7675 this .clientFactory = new HttpComponents5ClientFactory ();
7776 this .clientFactory .setClientBuilderCustomizer (
7877 httpClientBuilder -> httpClientBuilder .addRequestInterceptorFirst (new RemoveSoapHeadersInterceptor ()));
@@ -89,7 +88,7 @@ public HttpComponents5MessageSender() {
8988 * @param httpClient the HttpClient instance to use for this sender
9089 */
9190 public HttpComponents5MessageSender (HttpClient httpClient ) {
92-
91+ this ();
9392 Assert .notNull (httpClient , "httpClient must not be null" );
9493 this .httpClient = httpClient ;
9594 }
@@ -98,23 +97,19 @@ public HttpComponents5MessageSender(HttpClient httpClient) {
9897 * * @see HttpComponents5ClientFactory#setAuthScope(AuthScope)
9998 */
10099 public void setAuthScope (AuthScope authScope ) {
101-
102100 if (getHttpClient () != null ) {
103101 throw new IllegalStateException (HTTP_CLIENT_ALREADY_SET );
104102 }
105-
106103 this .clientFactory .setAuthScope (authScope );
107104 }
108105
109106 /*
110107 * * @see HttpComponents5ClientFactory#setCredentials(Credentials)
111108 */
112109 public void setCredentials (Credentials credentials ) {
113-
114110 if (getHttpClient () != null ) {
115111 throw new IllegalStateException (HTTP_CLIENT_ALREADY_SET );
116112 }
117-
118113 this .clientFactory .setCredentials (credentials );
119114 }
120115
@@ -127,63 +122,64 @@ public HttpClient getHttpClient() {
127122
128123 /**
129124 * Set the {@code HttpClient} used by this message sender.
125+ * <p>
126+ * This effectively disable any customization and does not change the given
127+ * {@code HttpClient} in any way. As such, it does not set timeouts, nor does it
128+ * {@linkplain HttpClientBuilder#addRequestInterceptorFirst(HttpRequestInterceptor)
129+ * add} the {@link RemoveSoapHeadersInterceptor}.
130+ * @param httpClient the HttpClient to use
130131 */
131132 public void setHttpClient (HttpClient httpClient ) {
132133 this .httpClient = httpClient ;
133134 }
134135
135- /*
136- * * @see HttpComponents5ClientFactory#setConnectionTimeout(Duration)
136+ /**
137+ * Set the timeout until a connection is established.
138+ * @see HttpComponents5ClientFactory#setConnectionTimeout(Duration)
137139 */
138140 public void setConnectionTimeout (Duration timeout ) {
139-
140141 if (getHttpClient () != null ) {
141142 throw new IllegalStateException (HTTP_CLIENT_ALREADY_SET );
142143 }
143-
144144 this .clientFactory .setConnectionTimeout (timeout );
145145 }
146146
147- /*
148- * * @see HttpComponents5ClientFactory#setReadTimeout(Duration)
147+ /**
148+ * Set the socket read timeout for the underlying HttpClient.
149+ * @see HttpComponents5ClientFactory#setReadTimeout(Duration)
149150 */
150151 public void setReadTimeout (Duration timeout ) {
151-
152152 if (getHttpClient () != null ) {
153153 throw new IllegalStateException (HTTP_CLIENT_ALREADY_SET );
154154 }
155-
156155 this .clientFactory .setReadTimeout (timeout );
157156 }
158157
159- /*
160- * * @see HttpComponents5ClientFactory#setMaxTotalConnections(int)
158+ /**
159+ * Sets the maximum number of connections allowed for the underlying HttpClient.
160+ * @see HttpComponents5ClientFactory#setMaxTotalConnections(int)
161161 */
162162 public void setMaxTotalConnections (int maxTotalConnections ) {
163-
164163 if (getHttpClient () != null ) {
165164 throw new IllegalStateException (HTTP_CLIENT_ALREADY_SET );
166165 }
167-
168166 this .clientFactory .setMaxTotalConnections (maxTotalConnections );
169167 }
170168
171- /*
172- * * @see HttpComponents5ClientFactory#setMaxConnectionsPerHost(Map)
169+ /**
170+ * Sets the maximum number of connections per host for the underlying HttpClient.
171+ * @see HttpComponents5ClientFactory#setMaxConnectionsPerHost(Map)
173172 */
174173 public void setMaxConnectionsPerHost (Map <String , String > maxConnectionsPerHost ) {
175-
176174 if (getHttpClient () != null ) {
177175 throw new IllegalStateException (HTTP_CLIENT_ALREADY_SET );
178176 }
179-
180177 this .clientFactory .setMaxConnectionsPerHost (maxConnectionsPerHost );
181178 }
182179
183180 @ Override
184181 public void afterPropertiesSet () throws Exception {
185-
186- if (this .clientFactory != null ) {
182+ if (getHttpClient () == null ) {
187183 this .httpClient = this .clientFactory .getObject ();
188184 }
189185 }
0 commit comments