使用 spring-ws 客户端建立持久连接
我正在使用 spring-ws 客户端以双向 ssl 模式调用 Web 服务。我需要确保我不会每次都创建新连接 - 相反,我会重复使用连接。 我做了一些重新搜索,发现默认情况下 HTTP 1.1 总是建立持久的 http(s) 连接。这是真的吗?
我的客户端中是否需要任何代码来确保连接持久?如何在发送新请求时检查连接是否持久或者是否正在创建新连接?
<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>
I am using a spring-ws client to invoke a web service in two way ssl mode. I need to make sure that I don't end up creating a new connection everytime - instead I re-use connections.
I did some re-search and found that by default HTTP 1.1 always makes persistent http(s) connections. Is that true?
Do I need any piece of code in my client to ensure connections are persistent? How can I check if the connections are persistent or if a new connection is being created vereytime I send a new request ?
<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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
HTTP/1.1 具有连接保持活动状态,但服务器可以在多次请求后决定关闭它,或者不支持保持活动状态。
最简单的检查方法是使用 tcpdump 或wireshark 并检查 SYN [S] 标志。那是新的联系。
我正在使用以下内容,在 J2SE 1.6 jdk 上,它没有跨多个请求创建任何新套接字。服务器未发送 Connection: Keep-Alive 标头,但连接仍保持活动状态。
Bean配置:
Java代码:
HTTP/1.1 has connection keep-alive but the server can decide to close it after a number of requests or does not support keep-alive
The easiest way to check is to use tcpdump or wireshark and check for SYN [S] flags. Thats new connections.
I am using the following and on J2SE 1.6 jdk it did not create any new sockets across multiple requests. The server did not send the Connection: Keep-Alive header but connections were kept alive anyway.
Bean configuration:
Java Code: