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

Dex*_*ter 9 soap spring-ws soapserver

我目前正在研究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
Run Code Online (Sandbox Code Playgroud)

当然,如果我向服务器发布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)
Run Code Online (Sandbox Code Playgroud)

任何帮助表示赞赏.

谢谢!

And*_*hen 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;
}
Run Code Online (Sandbox Code Playgroud)

  • 只是一个快速记录,可能会抓住一些人,消息工厂应该被声明为一个单独的bean(使用`@ Bean`),就像它在这里一样.如果你手动构造它将无法工作,因为它依赖于Spring生命周期方法`afterPropertiesSet()`被调用来构造内部消息工厂.这有点奇怪的设计,可能会让你失望. (4认同)
  • 我这样做了但是当春季启动时我仍然得到oswssaaj.SaajSoapMessageFactory.afterPropertiesSet - 使用SOAP 1.1协议创建SAAJ 1.3 MessageFactory (3认同)
  • @kenny 这意味着您无法注册该 bean。确保该 bean 已使用名称 messageFactory 注册,正如该答案中方法名称所暗示的那样。您还可以选择像“@Bean(name= DEFAULT_MESSAGE_FACTORY_BEAN_NAME)”那样注册 bean。还要确保您在注册 `messageDispatcherServlet` 时不会以某种方式更改默认消息工厂名称。`MessageDispatcherServlet` 有一个方法 `setMessageFactoryBeanName()`,如果您没有使用此处设置的名称注册 `MessageFactory` 实例,您将收到此错误。希望这对某人有帮助。 (2认同)