使用 CXF 生成 SOAP 1.2 端点的 Java Spring Boot

标签 java spring web-services spring-boot soap

几天来我一直在尝试使用 spring boot 和 Apache CXF 来生成 SOAP 1.2 端点,但是即使 WSDL 不使用 SOAP 1.1 命名空间,spring 仍会在同一位置生成 SOAP 1.1 和 SOAP 1.2 端点!

我的 wsdl 定义只有 SOAP 1.2 的端点

<wsdl:service name="MyService"> 
  <wsdl:port name="IMyServicePort" binding="tns:IMyServiceBinding"> 
    <soap12:address location="http://localhost:8080/MyService/services/IMyServicePort"/> 
  </wsdl:port> 
</wsdl:service> 

Web 服务 Bean 文件包含以下内容;

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:util="http://www.springframework.org/schema/util" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jaxws="http://cxf.apache.org/jaxws" xmlns:soap="http://cxf.apache.org/bindings/soap"
xsi:schemaLocation="http://www.springframework.org/schema/beans      
   http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
   http://www.springframework.org/schema/util
   http://www.springframework.org/schema/util/spring-util-2.0.xsd
   http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd
   http://cxf.apache.org/bindings/soap http://cxf.apache.org/schemas/configuration/soap.xsd">

<!-- Import the necessary CXF configuration files -->
<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />

<bean id="messageFactory" class="org.springframework.ws.soap.saaj.SaajSoapMessageFactory">
    <property name="soapVersion">
        <util:constant static-field="org.springframework.ws.soap.SoapVersion.SOAP_12" />
    </property>
    <property name="messageFactory">
        <null />
    </property>
</bean>


<jaxws:endpoint id="service" implementor="#ImyServiceImpl"
    address="/myService/v1" wsdlLocation="wsdl/MyService.wsdl">
    <jaxws:binding>
        <soap:soapBinding mtomEnabled="true" version="1.2"/>
    </jaxws:binding>
    <jaxws:properties>
        <entry key="schema-validation-enabled" value="true" />
        <entry key="jaxb-validation-event-handler">
            <bean
                class="myservice.OutSoapFaultInterceptor"></bean>
        </entry>
    </jaxws:properties>
</jaxws:endpoint>
</beans>

但是,当我浏览到 wsdl 时,我看到 SOAP 1.1 和 SOAP 1.2 端点

<wsdl:service name="MyService"> 
  <wsdl:port binding="tns:IMyServiceBinding" name="IMyServicePort"> 
    <soap12:address location="http://localhost:8080/services/services/myservice/v1"/> 
  </wsdl:port> 
</wsdl:service> 
<wsdl:service name="IMyServiceService"> 
  <wsdl:port binding="tns:IMyServiceSoapBinding" name="IMyServicePort"> 
    <soap:address location="http://localhost:8080/services/services/myservice/v1"/> 
  </wsdl:port> 
</wsdl:service> 

令人烦恼的是,两者都定义为相同的端点位置,因此我无法访问 SOAP 1.2 端点,所有请求都被拒绝,并显示“发送到仅 SOAP 1.1 端点时,SOAP 1.2 消息无效”。

我可以通过在 Java 中定义端点来解决这个问题(尽管我无法弄清楚如何在 Java 代码中复制 jaxb-validation-event-handler!),但我宁愿使用 XML 配置。

是否有人对仅生成 SOAP 1.2 端点或知道如何分离端点位置以便我可以将请求发送到 SOAP 1.2 端点有任何建议?

最佳答案

嗯,我不知道为什么 WSDL 会生成 SOAP 1.1 接口(interface)...但是,为了解决我的问题,我只是从 jaxws:endpoint 定义中删除了 wsdlLocation,所以;

<jaxws:endpoint id="service" implementor="#ImyServiceImpl"
    address="/myService/v1" wsdlLocation="wsdl/MyService.wsdl">

成为;

<jaxws:endpoint id="service" implementor="#ImyServiceImpl"
    address="/myService/v1">

如果我浏览到/myService/v1,现在那里只有 SOAP 1.2 定义。

关于使用 CXF 生成 SOAP 1.2 端点的 Java Spring Boot,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50844946/

相关文章:

Java swing mousemove 只触发一次

Tomcat集群中的Spring Websocket

Java webapp 响应我的登录页面的源代码

java - 在spring拦截器中获取请求映射对象,获取实际的url字符串模式

java - 当我尝试将我的应用程序连接到网络服务时失败

java - 无法从http请求获取JSON

java - 文件输入流/对象输入流 : StreamCorruptedException: Wrong format

java - 将 GeoTIFF 元数据从一个文件写入另一个文件

java - 面板占据相同的空间

java - 无法使用 jackson API 将 json 字符串映射到 java 对象