Reputation: 540
I found that HttpComponentsMessageSender default constructor in spring-ws-core 3.4.0.RELEASE, which depends on httpclient 4.5.6, is instantiating a DefaultHttpClient() which is deprecated. However, when i tried to set a custom Httpclient with:
HttpComponentsMessageSender httpComponentsMessageSender = new HttpComponentsMessageSender(HttpClientBuilder.create().build());
httpComponentsMessageSender.setReadTimeout(1000l);
i got:
Caused by: java.lang.UnsupportedOperationException: null
at org.apache.http.impl.client.InternalHttpClient.getParams(InternalHttpClient.java:211) ~[httpclient-4.5.6.jar:4.5.6]
at org.springframework.ws.transport.http.HttpComponentsMessageSender.setReadTimeout(HttpComponentsMessageSender.java:149) ~[spring-ws-core-3.0.4.RELEASE.jar:na]
Is that correct that spring uses a deprecated class by default? How should i set my custom HttpClient instance? it seems that if i set my own HttpClient i cannot configure it through HttpCompoemntsMessageSender.
thanks,
Upvotes: 3
Views: 1620
Reputation: 66
Not sure if you was able to resolve this but here is the solution to the following issue:
Caused by: java.lang.UnsupportedOperationException: null
at org.apache.http.impl.client.InternalHttpClient.getParams(InternalHttpClient.java:211) ~[httpclient-4.5.6.jar:4.5.6]
at org.springframework.ws.transport.http.HttpComponentsMessageSender.setReadTimeout(HttpComponentsMessageSender.java:149) ~[spring-ws-core-3.0.4.RELEASE.jar:na]
Note the HttpComponentsMessageSender.setReadTimeout() configures the underlying HttpClient's readTimeout by configuring the HttpClient Params.
As you provided above you can use the HttpClientBuilder to do this:
HttpComponentsMessageSender httpComponentsMessageSender = new HttpComponentsMessageSender(HttpClientBuilder.create().build());
The solution is to set the "DefaultRequestConfig" on the HttpClientBuilder
HttpClientBuilder.create()
.setDefaultRequestConfig(requestConfig)
.build();
As shown below you can set these configuration options at the HttpClient Level by defining a RequestConfig. Here is an example below:
RequestConfig requestConfig = RequestConfig.custom()
.setConnectionRequestTimeout(60 * 1000)
.setConnectTimeout(60 * 1000)
.setSocketTimeout(60 * 1000)
.build();
Hope this helps.
Upvotes: 5