【问题标题】:Java Spring WS Core with Maven POM带有 Maven POM 的 Java Spring WS 核心
【发布时间】:2018-02-10 06:00:42
【问题描述】:

我在我的 java 项目中使用 spring 服务并使用 maven pom 管理依赖项。像这样的:

 <dependency>
        <groupId>org.springframework.ws</groupId>
        <version>2.3.1-RELEASE</version>
 </dependency>

问题在于默认情况下它使用 SOAP V1.1 进行通信。 是否可以通过更改 pom 文件中的某些属性使其使用 V1.2?我在问这样的错误:

Cannot process the message because the content type 'text/xml; 
charset=utf-8' was not the expected type 'application/soap+xml; 
charset=utf-8'

据我了解,这是因为我的 SOAP 版本是 V1.1(text/xml) 而另一端想要 V1.2 (application/soap+xml) 另外,有没有办法将内容类型动态设置为“text/xml”或“application/soap+xml”?还是依赖于 SOAP 版本,无法动态配置?

谢谢!

【问题讨论】:

    标签: java spring maven web-services soap


    【解决方案1】:

    您可以像下面的示例一样在 SaajSoapMessageFactory 上设置肥皂版本,并为您的 WebServiceTemplate 设置它

    <!-- Configure the SOAP version to 1.2 -->
    <bean id="soapMessageFactory" class="org.springframework.ws.soap.saaj.SaajSoapMessageFactory">
        <property name="soapVersion">
            <util:constant static-field="org.springframework.ws.soap.SoapVersion.SOAP_12"/>
        </property>
    </bean>
    
    <oxm:jaxb2-marshaller id="marshaller" contextPath="myproject.wsdl.ws"/>
    
    <bean id="webServiceTemplate" class="org.springframework.ws.client.core.WebServiceTemplate">
        <constructor-arg ref="soapMessageFactory"/>
        <property name="marshaller" ref="marshaller"/>
        <property name="unmarshaller" ref="marshaller"/>
        <property name="defaultUri" value="http://my.web.service?wsdl"/>
    </bean>
    

    礼貌 - https://myshittycode.com/category/spring/spring-web-services/

    【讨论】:

      【解决方案2】:

      所以这对我有用。如果你想在你的代码中动态改变它,你可以这样做:

      MessageFactory msgFactory = MessageFactory.newInstance(SOAP_VERSION);
      SaajSoapMessageFactory newSoapMessageFactory = new SaajSoapMessageFactory(msgFactory);
      WebServiceTemplate wsTemplate = new WebServiceTemplate(newSoapMessageFactory);
      

      然后您就可以像往常一样使用 SOAP 函数了。因此,您可以通过这种方式对其进行参数化,并根据您的要求使用 SOAP 1.1 或 1.2

      【讨论】:

        猜你喜欢
        • 2013-01-27
        • 2011-07-19
        • 2016-08-30
        • 1970-01-01
        • 1970-01-01
        • 2021-12-13
        • 2015-11-15
        • 2016-12-07
        • 2014-11-05
        相关资源
        最近更新 更多