Https 使用SpringWS客户端建立持久连接
我正在使用SpringWS客户端以双向ssl模式调用web服务。我需要确保我不会每次都创建一个新的连接,而是重复使用连接。 我做了一些重新搜索,发现默认情况下HTTP1.1总是进行持久HTTP连接。这是真的吗 我的客户端是否需要任何代码来确保连接的持久性?如何在每次发送新请求时检查连接是否持久或是否正在创建新连接Https 使用SpringWS客户端建立持久连接,https,spring-ws,connection,Https,Spring Ws,Connection,我正在使用SpringWS客户端以双向ssl模式调用web服务。我需要确保我不会每次都创建一个新的连接,而是重复使用连接。 我做了一些重新搜索,发现默认情况下HTTP1.1总是进行持久HTTP连接。这是真的吗 我的客户端是否需要任何代码来确保连接的持久性?如何在每次发送新请求时检查连接是否持久或是否正在创建新连接 <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:oxm="http://www.springframework.org/schema/oxm"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/oxm http://www.springframework.org/schema/oxm/spring-oxm-3.0.xsd">
<bean id="messageFactory" class="org.springframework.ws.soap.saaj.SaajSoapMessageFactory"/>
<bean id="webServiceTemplate" class="org.springframework.ws.client.core.WebServiceTemplate">
<constructor-arg ref="messageFactory"/>
<property name="marshaller" ref="jaxb2Marshaller" />
<property name="unmarshaller" ref="jaxb2Marshaller" />
<property name="messageSender" ref="httpSender" />
</bean>
<bean id="httpSender" class="org.springframework.ws.transport.http.CommonsHttpMessageSender">
</bean>
<oxm:jaxb2-marshaller id="jaxb2Marshaller" contextPath="com.nordstrom.direct.oms.webservices.addressval" />
<bean id="Client" class="test.ClientStub">
<property name="webServiceTemplate" ref="webServiceTemplate" />
</bean>
</beans>
HTTP/1.1具有保持活动的连接,但服务器可以在多次请求后决定关闭该连接,或者不支持保持活动 最简单的检查方法是使用tcpdump或wireshark并检查SYN[S]标志。这是新的联系 我使用的是以下代码,在J2SE1.6JDK上,它没有跨多个请求创建任何新的套接字。服务器未发送Connection:Keep Alive标头,但连接仍保持活动状态 Bean配置:
HTTP/1.1使连接保持活动,但服务器可以在多次请求后决定关闭连接,或者不支持保持活动 最简单的检查方法是使用tcpdump或wireshark并检查SYN[S]标志。这是新的联系 我使用的是以下代码,在J2SE1.6JDK上,它没有跨多个请求创建任何新的套接字。服务器未发送Connection:Keep Alive标头,但连接仍保持活动状态 Bean配置:
<bean id="wsHttpClient" factory-bean="customHttpClient"
factory-method="getHttpClient" />
<bean id="messageSender"
class="org.springframework.ws.transport.http.CommonsHttpMessageSender"
p:httpClient-ref="wsHttpClient" />
import org.apache.commons.httpclient.*;
import org.springframework.stereotype.*;
@Component public class CustomHttpClient {
private final HttpClient httpClient;
public CustomHttpClient() {
httpClient = new HttpClient(new MultiThreadedHttpConnectionManager());
httpClient.getParams().setParameter("http.protocol.content-charset",
"UTF-8");
httpClient.getHttpConnectionManager().getParams()
.setConnectionTimeout(60000);
httpClient.getHttpConnectionManager().getParams().setSoTimeout(60000);
httpClient.setHostConfiguration(new HostConfiguration());
}
public HttpClient getHttpClient() {
return httpClient;
}
}