使用带有Soap v1.2的spring-w而不是默认的v1.1来生成SOAP Web服务

问题描述 投票:9回答:2

我目前正在研究Spring soap服务器项目。我从Spring的http://spring.io/guides/gs/producing-web-service/开始使用Spring的入门指南来构建一个基本的SOAP服务。

默认的SOAP协议是SOAP v1.1。有没有办法可以通过注释将协议设置为v1.2?

我在@BindingType(javax.xml.ws.soap.SOAPBinding.SOAP12HTTP_BINDING)类上尝试了@Endpoint注释,但它似乎没有用。

我也尝试过qazxsw poi来设置它,但是这在开机日志中看不到

@Endpoint(value = SOAPBinding.SOAP12HTTP_BINDING)

当然,如果我向服务器发布SOAP请求,我会收到以下错误

INFO --- [nio-8080-exec-1] o.s.ws.soap.saaj.SaajSoapMessageFactory  :
 Creating SAAJ 1.3 MessageFactory with SOAP 1.1 Protocol

任何帮助表示赞赏。

谢谢!

soap spring-ws soapserver
2个回答
27
投票

您正在将Spring-WS与来自JAX-WS(包2015-01-19 15:50:17.610 ERROR 20172 --- [nio-8080-exec-1] c.sun.xml.internal.messaging.saaj.soap : SAAJ0533: Cannot create message: incorrect content-type for SOAP version. Got application/soap+xml; charset=utf-8, but expected text/xml 2015-01-19 15:50:17.611 ERROR 20172 --- [nio-8080-exec-1] c.sun.xml.internal.messaging.saaj.soap : SAAJ0535: Unable to internalize message 2015-01-19 15:50:17.617 ERROR 20172 --- [nio-8080-exec-1] a.c.c.C.[.[.[.[messageDispatcherServlet] : Servlet.service() for servlet [messageDispatcherServlet] in context with path [] threw exception [R equest processing failed; nested exception is org.springframework.ws.soap.SoapMessageCreationException: Could not create message from InputStream: Unable to internalize message; nested exception is com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl: Unable to internalize message] with root cause com.sun.xml.internal.messaging.saaj.soap.SOAPVersionMismatchException: Cannot create message: incorrect content-type for SOAP version. Got: application/soap+xml; charset=utf-8 Expected: text/xml at com.sun.xml.internal.messaging.saaj.soap.MessageImpl.init(Unknown Source) at com.sun.xml.internal.messaging.saaj.soap.MessageImpl.<init>(Unknown Source) at com.sun.xml.internal.messaging.saaj.soap.ver1_1.Message1_1Impl.<init>(Unknown Source) at com.sun.xml.internal.messaging.saaj.soap.ver1_1.SOAPMessageFactory1_1Impl.createMessage(Unknown Source) )的注释混合在一起。那不行。要将Spring-WS配置为使用SOAP 1.2,请添加以下bean定义:

javax.xml.ws

2
投票

如果messageFactory Bean不在单例作用域中,则不会在Bean即时中调用SaajSoapMessageFactory中的afterPropertiesSet()方法。

afterPropertiesSet()方法设置内部消息工厂。因此,如果您的messageFactory bean有自己的范围,您需要设置内部消息工厂,如下所示:

@Bean
public SaajSoapMessageFactory messageFactory() {
    SaajSoapMessageFactory messageFactory = new SaajSoapMessageFactory();
    messageFactory.setSoapVersion(SoapVersion.SOAP_12);
    return messageFactory;
}
© www.soinside.com 2019 - 2024. All rights reserved.