Spring-WS:如何将WebserviceTemplate与预先生成的SOAP-envelope一起使用

时间:2008-12-11 14:56:13

标签: java web-services spring ws-security spring-ws

您是否可以使用Spring-WS WebserviceTemplate来调用Web服务并避免它生成SOAP信封?也就是说,消息已经包含SOAP-Envelope,我不希望WebserviceTemplate包围另一个。 : - )

我想要这个的原因是我想调用一个使用ws-security的web服务而不想把ws-security的东西放到WebserviceTemplate中,但只想给它一个带有预生成的消息SOAP信封中的ws-security信息。我尝试调用方法sendSourceAndReceiveToResult,其中Source已包含带有WS-Security内容的Soap-Envelope,而webservice模板包含另一个Soap-Envelope,因此会破坏该消息。

2 个答案:

答案 0 :(得分:3)

你正在以一种奇怪的方式使用ws-security ...我想你正试图通过使用预先生成的消息来避免ws-security依赖性 - 对于简单的客户端可能有意义,尽管它绝对不是 - 所述书

通过将WebServiceTemplate上的messageFactory设置为此bean,可以将WebServiceTemplate配置为使用不带SOAP的纯XML:

<bean id="webServiceTemplate" class="org.springframework.ws.client.core.WebServiceTemplate">
    <property name="messageFactory" ref="poxMessageFactory" />
</bean>    

<bean id="poxMessageFactory" class="org.springframework.ws.pox.dom.DomPoxMessageFactory" />

答案 1 :(得分:0)

对于你想要做的事情,拦截器可以派上用场。在这里查看Interceptor层次结构:http://static.springframework.org/spring-ws/docs/1.0-m1/api/org/springframework/ws/EndpointInterceptor.html 您可以使用spring-ws注册EndpointInterceptor并根据自己的喜好操作响应。