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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/359620/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 12:04:25  来源:igfitidea点击:

Spring-WS: how to use WebserviceTemplate with pre-generated SOAP-envelope

javaweb-servicesspringws-securityspring-ws

提问by Hans-Peter St?rr

Can you use a Spring-WS WebserviceTemplate for calling a webservice and avoid that it generates a SOAP-envelope? That is, the message already contains an SOAP-Envelope and I don't want that the WebserviceTemplate wraps another one around it. :-)

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

The reason I want this is that I'd like to call a webservice that uses ws-security and do not want to put the ws-security stuff into the WebserviceTemplate, but just want to feed it a message with pre-generated ws-security information in the SOAP-envelope. I tried calling the method sendSourceAndReceiveToResultwith a Source already contains a Soap-Envelope with the WS-Security stuff and the webservice template wraps around another Soap-Envelope and thus destroys the message.

我想要这个的原因是我想调用一个使用 ws-security 的 web 服务,不想将 ws-security 的东西放入 WebserviceTemplate,但只想用预先生成的 ws-security 向它提供消息SOAP 信封中的信息。我尝试使用 Source调用方法sendSourceAndReceiveToResult已经包含一个带有 WS-Security 内容的 Soap-Envelope,并且 webservice 模板环绕另一个 Soap-Envelope 并因此破坏了消息。

采纳答案by Domchi

You're using ws-security in a strange way... I guess that you're trying to avoid ws-security dependancy by using pre-generated messages - for simple client might make sense, although it's definitely not by-the-book.

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

You can configure WebServiceTemplate to use plain XML without SOAP by setting messageFactory on WebServiceTemplate to this bean:

您可以通过将 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" />

回答by neesh

Interceptors can come in handy for the sort of thing you are trying to do. Take a look at the Interceptor hierarchy here: http://static.springframework.org/spring-ws/docs/1.0-m1/api/org/springframework/ws/EndpointInterceptor.htmlYou can register an EndpointInterceptor with spring-ws and manipulate the response to your liking.

拦截器可以派上用场,用于您尝试做的事情。在此处查看拦截器层次结构:http: //static.springframework.org/spring-ws/docs/1.0-m1/api/org/springframework/ws/EndpointInterceptor.html您可以使用 spring-ws 注册 EndpointInterceptor 和根据您的喜好操纵响应。