1.通过MessageSender客户化http连接参数
AbstractHttpWebServiceMessageSender有若干实现子类:
- CommonsHttpMessageSender(deprecated)
- HttpComponentsMessageSender
- HttpUrlConnectionMessageSender
2.CommonsHttpMessageSender
2.1 CommonsHttpMessageSender 需要依赖于Apache httpclient包
<dependency>
<groupId>commons-httpclient</groupId>
<artifactId>commons-httpclient</artifactId>
<version>{version}</version>
</dependency>
2.2 示例源于spring integration sample master
<chain input-channel="fahrenheitChannel" output-channel="celsiusChannel">
<ws:header-enricher>
<ws:soap-action value="http://www.w3schools.com/webservices/CelsiusToFahrenheit" />
</ws:header-enricher>
<ws:outbound-gateway uri="http://www.w3schools.com/webservices/tempconvert.asmx" message-sender="httpSender"/>
</chain>
<beans:bean id="httpSender" class="org.springframework.ws.transport.http.CommonsHttpMessageSender">
<beans:constructor-arg name="httpClient">
<beans:bean class="org.apache.commons.httpclient.HttpClient">
<beans:property name="httpConnectionManager" ref="httpConnectionManager" />
</beans:bean>
</beans:constructor-arg>
</beans:bean>
<beans:bean id="httpConnectionManager" class="org.apache.commons.httpclient.MultiThreadedHttpConnectionManager">
<beans:property name="params">
<beans:bean class="org.apache.commons.httpclient.params.HttpConnectionManagerParams">
<beans:property name="soTimeout" value="5000" />
<!-- <beans:property name="maxTotalConnections" value="100" />
<beans:property name="defaultMaxConnectionsPerHost" value="100" /> -->
</beans:bean>
</beans:property>
</beans:bean>
3. HttpComponentsMessageSender
3.1 HttpComponentsMessageSender 需要依赖于Apache http components包
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.3.3</version>
</dependency>
3.2 配置相对容易
<ws:outbound-gateway uri="http://www.w3schools.com/webservices/tempconvert.asmx" message-sender="httpComponentsSender" />
<beans:bean id="httpComponentsSender" class="org.springframework.ws.transport.http.HttpComponentsMessageSender">
<beans:property name="connectionTimeout" value="12" />
<beans:property name="readTimeout" value="12" />
</beans:bean>
That's it!