具有可靠消息传递的 Apache CXF3.0.4 Soap Web 服务抛出异常

Apache CXF3.0.4 Soap web service with reliable Messaging throws exception

您好,我使用 apache CXF 3.0.4spring4.0 创建了 SOAP Web 服务 它对我来说工作正常,是用 wsdl 文件创建的。 现在我想向此 Web 服务添加 Apache CXF 关于 WS-RM(Web 服务可靠消息传递)的额外功能。

我尝试先添加一些代码,例如启用 WS-Addressing,然后在其中定义策略,但我没有任何方法可以这样做。

请分享您的想法。

    <?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:cxf="http://cxf.apache.org/core"
       xmlns:wsa="http://cxf.apache.org/ws/addressing"
       xmlns:http="http://cxf.apache.org/transports/http/configuration"
       xmlns:wsrm-policy="http://schemas.xmlsoap.org/ws/2005/02/rm/policy"
       xmlns:wsrm-mgr="http://cxf.apache.org/ws/rm/manager"
        xmlns:jaxws="http://cxf.apache.org/jaxws" xmlns:jaxrs="http://cxf.apache.org/jaxrs"
       xsi:schemaLocation="
       http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd
        http://cxf.apache.org/jaxrs                     http://cxf.apache.org/schemas/jaxrs.xsd
        http://cxf.apache.org/jaxws                     http://cxf.apache.org/schemas/jaxws.xsd
       http://cxf.apache.org/transports/http/configuration http://cxf.apache.org/schemas/configuration/http-conf.xsd
       http://schemas.xmlsoap.org/ws/2005/02/rm/policy http://schemas.xmlsoap.org/ws/2005/02/rm/wsrm-policy.xsd
       http://cxf.apache.org/ws/rm/manager http://cxf.apache.org/schemas/configuration/wsrm-manager.xsd
       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">    
    <bean id="test" class="com.msp.webservices.impl.TestWSImpl"
        scope="prototype"></bean>
        <jaxws:endpoint id="testService" implementor="#test"
            address="/TestService" publishedEndpointUrl="${tomcat.url}/${context.name}/TestService">
            <jaxws:properties>
                <entry key="mtom-enabled" value="true" />
            </jaxws:properties>             
        </jaxws:endpoint>


<cxf:bus>
    <cxf:features>
        <wsa:addressing/>
        <wsrm-mgr:reliableMessaging>
            <wsrm-policy:RMAssertion>
                <wsrm-policy:BaseRetransmissionInterval Milliseconds="4000"/>           
                <wsrm-policy:AcknowledgementInterval Milliseconds="2000"/>          
            </wsrm-policy:RMAssertion> 
            <wsrm-mgr:sourcePolicy>
                <wsrm-mgr:sequenceTerminationPolicy maxLength="5"/>                    
            </wsrm-mgr:sourcePolicy>     
            <wsrm-mgr:destinationPolicy acceptOffers="false">            
            </wsrm-mgr:destinationPolicy>
        </wsrm-mgr:reliableMessaging>
    </cxf:features>
</cxf:bus>

    </beans>

添加到上下文文件的额外代码在 tomcat 上部署时失败。

并在启动时尝试创建抛出异常的序列。

这是控制台日志。

    Nov 00, 2015 00:00:00 AM org.apache.cxf.ws.rm.Proxy invoke
    INFO: Sending out-of-band RM protocol message {http://schemas.xmlsoap.org/ws/2005/02/rm}CreateSequence.
    Nov 00, 2015 00:00:00 AM org.apache.cxf.services.SequenceAbstractService.SequenceAbstractSoapPort.SequenceAbstractPortType
    INFO: Outbound Message
    ---------------------------
    ID: 1
    Encoding: UTF-8
    Content-Type: application/soap+xml; action="http://schemas.xmlsoap.org/ws/2005/02/rm/CreateSequence"
    Headers: 
    Payload: <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:wsa="http://www.w3.org/2005/08/addressing" xmlns:tns="http://docs.oasis-open.org/ws-dd/ns/discovery/2009/01"><soap:Header><Action xmlns="http://schemas.xmlsoap.org/ws/2004/08/addressing">http://schemas.xmlsoap.org/ws/2005/02/rm/CreateSequence</Action><MessageID xmlns="http://schemas.xmlsoap.org/ws/2004/08/addressing">urn:uuid:6394efee-06ca-44c3-a165-38112b4f9b71</MessageID><To xmlns="http://schemas.xmlsoap.org/ws/2004/08/addressing">soap.udp://239.255.255.250:3702</To></soap:Header><soap:Body><CreateSequence xmlns:ns2="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns="http://schemas.xmlsoap.org/ws/2005/02/rm"><AcksTo><ns2:Address>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</ns2:Address></AcksTo><Expires>PT0S</Expires><Offer><Identifier>urn:uuid:ce23294b-3117-450a-89f2-d35d013b33d2</Identifier><Expires>PT0S</Expires></Offer></CreateSequence></soap:Body></soap:Envelope>
    --------------------------------------
    Nov 00, 2015 00:00:00 AM org.apache.cxf.phase.PhaseInterceptorChain doDefaultLogging
    WARNING: Interceptor for {http://schemas.xmlsoap.org/ws/2005/02/rm}SequenceAbstractService#{http://schemas.xmlsoap.org/ws/2005/02/rm}CreateSequence has thrown exception, unwinding now
    org.apache.cxf.interceptor.Fault: Could not send Message.
.
.
.
.
.
Nov 00, 2015 00:00:00 AM org.apache.cxf.ws.rm.Proxy invoke
SEVERE: Failed to send RM protocol message {http://schemas.xmlsoap.org/ws/2005/02/rm}CreateSequence.
org.apache.cxf.interceptor.Fault: Could not send Message.
.
.
.
.

配置cxf2.5.4版本时工作正常,但我想使用cxf3.0.4

我没有在总线级别尝试过,但它可以在端点级别使用以下代码工作,

    <wsp:Policy wsu:Id="RM" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
    <wsrm:RMAssertion xmlns:wsrm="http://schemas.xmlsoap.org/ws/2005/02/rm/policy">
        <wsrm:AcknowledgementInterval Milliseconds="2000" />
    </wsrm:RMAssertion>
    <wsam:Addressing xmlns:wsam="http://www.w3.org/2007/02/addressing/metadata">
        <wsam:NonAnonymousResponses />
    </wsam:Addressing>
   </wsp:Policy>


<jaxws:endpoint id="Service" implementor="#Serv" address="/TrcAndGrnWebservice" publishedEndpointUrl="${tomcat.url}/${context.name}/service">
    <jaxws:features>
        <cxf:logging/>
        <p:policies>
            <wsp:PolicyReference URI="#RM" />
        </p:policies>
    </jaxws:features>
</jaxws:endpoint>

你可以参考我下面的命名空间

<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util"
xmlns:context="http://www.springframework.org/schema/context" xmlns:int-sftp="http://www.springframework.org/schema/integration/sftp" xmlns:jaxws="http://cxf.apache.org/jaxws"
xmlns:jaxrs="http://cxf.apache.org/jaxrs" xmlns:p="http://cxf.apache.org/policy" xmlns:cxf="http://cxf.apache.org/core" xmlns:wsa="http://cxf.apache.org/ws/addressing"
xmlns:http="http://cxf.apache.org/transports/http/configuration" xmlns:wsrm-policy="http://schemas.xmlsoap.org/ws/2005/02/rm/policy" xmlns:wsrm-mgr="http://cxf.apache.org/ws/rm/manager"
xmlns:wsp="http://www.w3.org/2006/07/ws-policy"
xsi:schemaLocation="http://www.springframework.org/schema/beans     http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/util      http://www.springframework.org/schema/util/spring-util.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://cxf.apache.org/jaxrs                     http://cxf.apache.org/schemas/jaxrs.xsd
http://cxf.apache.org/jaxws                     http://cxf.apache.org/schemas/jaxws.xsd
            http://cxf.apache.org/policy                            http://cxf.apache.org/schemas/policy.xsd
             http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd         
            http://schemas.xmlsoap.org/ws/2005/02/rm/policy http://schemas.xmlsoap.org/ws/2005/02/rm/wsrm-policy.xsd
   http://cxf.apache.org/ws/rm/manager http://cxf.apache.org/schemas/configuration/wsrm-manager.xsd
http://www.w3.org/2006/07/ws-policy http://www.w3.org/2006/07/ws-policy.xsd         
xsi:schemaLocation=http://www.springframework.org/schema/integration/sftp http://www.springframework.org/schema/integration/sftp/spring-integration-sftp.xsd">

<!-- Apache CXF Configuration for Webservices -->
<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-jaxws.xml" />