@@ -64,16 +64,15 @@ public class HttpComponents5MessageSender extends AbstractHttpWebServiceMessageS
6464
6565	private  static  final  String  HTTP_CLIENT_ALREADY_SET  = "httpClient already set" ;
6666
67- 	private  HttpClient   httpClient ;
67+ 	private  final   HttpComponents5ClientFactory   clientFactory ;
6868
69- 	private  HttpComponents5ClientFactory   clientFactory ;
69+ 	private  HttpClient   httpClient ;
7070
7171	/** 
7272	 * Create a new instance of the {@code HttpClientMessageSender} with a default 
7373	 * {@link HttpClient} that uses a default {@link PoolingHttpClientConnectionManager}. 
7474	 */ 
7575	public  HttpComponents5MessageSender () {
76- 
7776		this .clientFactory  = new  HttpComponents5ClientFactory ();
7877		this .clientFactory .setClientBuilderCustomizer (
7978				httpClientBuilder  -> httpClientBuilder .addRequestInterceptorFirst (new  RemoveSoapHeadersInterceptor ()));
@@ -90,7 +89,7 @@ public HttpComponents5MessageSender() {
9089	 * @param httpClient the HttpClient instance to use for this sender 
9190	 */ 
9291	public  HttpComponents5MessageSender (HttpClient  httpClient ) {
93- 
92+ 		 this (); 
9493		Assert .notNull (httpClient , "httpClient must not be null" );
9594		this .httpClient  = httpClient ;
9695	}
@@ -99,23 +98,19 @@ public HttpComponents5MessageSender(HttpClient httpClient) {
9998	 * * @see HttpComponents5ClientFactory#setAuthScope(AuthScope) 
10099	 */ 
101100	public  void  setAuthScope (AuthScope  authScope ) {
102- 
103101		if  (getHttpClient () != null ) {
104102			throw  new  IllegalStateException (HTTP_CLIENT_ALREADY_SET );
105103		}
106- 
107104		this .clientFactory .setAuthScope (authScope );
108105	}
109106
110107	/* 
111108	 * * @see HttpComponents5ClientFactory#setCredentials(Credentials) 
112109	 */ 
113110	public  void  setCredentials (Credentials  credentials ) {
114- 
115111		if  (getHttpClient () != null ) {
116112			throw  new  IllegalStateException (HTTP_CLIENT_ALREADY_SET );
117113		}
118- 
119114		this .clientFactory .setCredentials (credentials );
120115	}
121116
@@ -128,63 +123,64 @@ public HttpClient getHttpClient() {
128123
129124	/** 
130125	 * Set the {@code HttpClient} used by this message sender. 
126+ 	 * <p> 
127+ 	 * This effectively disable any customization and does not change the given 
128+ 	 * {@code HttpClient} in any way. As such, it does not set timeouts, nor does it 
129+ 	 * {@linkplain HttpClientBuilder#addRequestInterceptorFirst(HttpRequestInterceptor) 
130+ 	 * add} the {@link RemoveSoapHeadersInterceptor}. 
131+ 	 * @param httpClient the HttpClient to use 
131132	 */ 
132133	public  void  setHttpClient (HttpClient  httpClient ) {
133134		this .httpClient  = httpClient ;
134135	}
135136
136- 	/* 
137- 	 * * @see HttpComponents5ClientFactory#setConnectionTimeout(Duration) 
137+ 	/** 
138+ 	 * Set the timeout until a connection is established. 
139+ 	 * @see HttpComponents5ClientFactory#setConnectionTimeout(Duration) 
138140	 */ 
139141	public  void  setConnectionTimeout (Duration  timeout ) {
140- 
141142		if  (getHttpClient () != null ) {
142143			throw  new  IllegalStateException (HTTP_CLIENT_ALREADY_SET );
143144		}
144- 
145145		this .clientFactory .setConnectionTimeout (timeout );
146146	}
147147
148- 	/* 
149- 	 * * @see HttpComponents5ClientFactory#setReadTimeout(Duration) 
148+ 	/** 
149+ 	 * Set the socket read timeout for the underlying HttpClient. 
150+ 	 * @see HttpComponents5ClientFactory#setReadTimeout(Duration) 
150151	 */ 
151152	public  void  setReadTimeout (Duration  timeout ) {
152- 
153153		if  (getHttpClient () != null ) {
154154			throw  new  IllegalStateException (HTTP_CLIENT_ALREADY_SET );
155155		}
156- 
157156		this .clientFactory .setReadTimeout (timeout );
158157	}
159158
160- 	/* 
161- 	 * * @see HttpComponents5ClientFactory#setMaxTotalConnections(int) 
159+ 	/** 
160+ 	 * Sets the maximum number of connections allowed for the underlying HttpClient. 
161+ 	 * @see HttpComponents5ClientFactory#setMaxTotalConnections(int) 
162162	 */ 
163163	public  void  setMaxTotalConnections (int  maxTotalConnections ) {
164- 
165164		if  (getHttpClient () != null ) {
166165			throw  new  IllegalStateException (HTTP_CLIENT_ALREADY_SET );
167166		}
168- 
169167		this .clientFactory .setMaxTotalConnections (maxTotalConnections );
170168	}
171169
172- 	/* 
173- 	 * * @see HttpComponents5ClientFactory#setMaxConnectionsPerHost(Map) 
170+ 	/** 
171+ 	 * Sets the maximum number of connections per host for the underlying HttpClient. 
172+ 	 * @see HttpComponents5ClientFactory#setMaxConnectionsPerHost(Map) 
174173	 */ 
175174	public  void  setMaxConnectionsPerHost (Map <String , String > maxConnectionsPerHost ) {
176- 
177175		if  (getHttpClient () != null ) {
178176			throw  new  IllegalStateException (HTTP_CLIENT_ALREADY_SET );
179177		}
180- 
181178		this .clientFactory .setMaxConnectionsPerHost (maxConnectionsPerHost );
182179	}
183180
184181	@ Override 
185182	public  void  afterPropertiesSet () throws  Exception  {
186- 
187- 		if  (this .clientFactory  != null ) {
183+ 		if  (getHttpClient () == null ) {
188184			this .httpClient  = this .clientFactory .getObject ();
189185		}
190186	}
0 commit comments