我目前正在开发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
注释,但似乎没有效果。
我也尝试@Endpoint(value = SOAPBinding.SOAP12HTTP_BINDING)
来设置它,但这不会像启动日志中看到的那样起作用
INFO --- [nio-8080-exec-1] o.s.ws.soap.saaj.SaajSoapMessageFactory :
Creating SAAJ 1.3 MessageFactory with SOAP 1.1 Protocol
当然,如果我向服务器发布SOAP请求,我会收到以下错误
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)
感谢任何帮助。
谢谢!
答案 0 :(得分:27)
您正在将Spring-WS与来自JAX-WS(包javax.xml.ws
)的注释混合在一起。那不会奏效。要将Spring-WS配置为使用SOAP 1.2,请添加以下bean定义:
@Bean
public SaajSoapMessageFactory messageFactory() {
SaajSoapMessageFactory messageFactory = new SaajSoapMessageFactory();
messageFactory.setSoapVersion(SoapVersion.SOAP_12);
return messageFactory;
}
答案 1 :(得分:2)
如果messageFactory Bean在单例范围内不是,则在豆实例化时不会调用 SaajSoapMessageFactory 中的 afterPropertiesSet()方法
afterPropertiesSet()方法设置内部消息工厂。因此,如果您的messageFactory bean有自己的作用域,则需要这样设置内部消息工厂:
@Bean
@Scope("custom-scope")
public SaajSoapMessageFactory messageFactory() {
SaajSoapMessageFactory messageFactory = new SaajSoapMessageFactory();
messageFactory.messageFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
return messageFactory;
}
答案 2 :(得分:0)
messageFactory()@Bean是必需的步骤,但添加它也不是必不可少的
wsdl11Definition.setCreateSoap12Binding(true);
到服务定义,以生成适当的soap 1.2绑定?
无论如何,多亏了Andreas Veithen