1

我在 http 出站流中使用 jaxws-client 在 mule 通信中使用以下 XML(POJO 是出站 Jaxws 客户端的输出)。

确保在 maven 中使用 wsdl2java 插件生成 WS 代码,生成的代码具有来自 WS 的异常类,该类是:

com.nsn.ossbss.charge_once.wsdl.entity.tis.wsdl._1.TisException

当我们在 WS 引发此异常后得到 SOAPFault 时,肯定 http 响应为 500

com.nsn.ossbss.charge_once.wsdl.entity.tis.wsdl._1.TisException

INFO  2012-11-08 11:08:08,008 [[cxf].TCP_C_L.receiver.02] org.mule.transport.http.HttpClientMessageDispatcher: Received a redirect, but followRedirects=false. Response code: 500 Server Error
ERROR 2012-11-08 11:08:13,008 [[cxf].TCP_C_L.receiver.02] org.mule.exception.CatchMessagingExceptionStrategy: 
********************************************************************************
Message               : error. Failed to route event via endpoint: org.mule.module.cxf.CxfOutboundMessageProcessor. Message payload is of type: PostMethod
Code                  : MULE_ERROR--2
--------------------------------------------------------------------------------
Exception stack is:
1. error (com.nsn.ossbss.charge_once.wsdl.entity.tis.wsdl._1.TisException)
  sun.reflect.NativeConstructorAccessorImpl:-2 (null)
2. error. Failed to route event via endpoint: org.mule.module.cxf.CxfOutboundMessageProcessor. Message payload is of type: PostMethod (org.mule.api.transport.DispatchException)
  org.mule.module.cxf.CxfOutboundMessageProcessor:148 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/transport/DispatchException.html)
--------------------------------------------------------------------------------
Root Exception stack trace:
com.nsn.ossbss.charge_once.wsdl.entity.tis.wsdl._1.TisException: error
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
    + 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
********************************************************************************

INFO  2012-11-08 11:08:13,009 [[cxf].TCP_C_L.receiver.02] org.mule.api.processor.LoggerMessageProcessor: org.apache.commons.httpclient.methods.PostMethod@d02649
INFO  2012-11-08 11:08:13,010 [[cxf].TCP_C_L.receiver.02] org.mule.api.processor.LoggerMessageProcessor: org.apache.commons.httpclient.methods.PostMethod@d02649

使用以下命令处理异常时出现上述错误:

<catch-exception-strategy>
            <logger message="#[payload]" level="INFO" doc:name="Logger" />
            <transformer ref="ByteArrayToString" />
            <append-string-transformer message="&#xD;&#xA;" />
            <logger message="#[payload]" level="INFO" doc:name="Logger" />
        </catch-exception-strategy>

当然,我需要处理与 apache camel 相同的异常,我需要指定 mule 异常,并且 mule 不应在控制台中引发上述异常,因为它将由 XML 配置处理。

来自 jaxWs-client 出站的传入消息的类型是

org.apache.commons.httpclient.methods.PostMethod@d02649

我怎样才能让 Mule ESB 理解 WS 异常,我试过这个

它也没有用。

你能给些建议么 。

在 Fuse ESB 中,我这样做了:

<onException>
<exception>com.nsn.ossbss.charge_once.wsdl.entity.tis.wsdl._1.TisException</exception>  
            <handled>
                <constant>true</constant>
            </handled>
            <to uri="log:test" />
            <setBody>

                <simple>${exception.getFaultInfo}</simple>

            </setBody>
            <to uri="log:exception" />
            <convertBodyTo      type="com.nsn.ossbss.charge_once.wsdl.entity.tis.xsd._1.FaultMessage" />
            <marshal ref="decExc" />
            <convertBodyTo type="String" />
            <bean ref="nulladd" />
        </onException>

我怎样才能在 Mule ESB 中做同样的事情。

<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:vm="http://www.mulesoft.org/schema/mule/vm" xmlns:file="http://www.mulesoft.org/schema/mule/file"
    xmlns:mulexml="http://www.mulesoft.org/schema/mule/xml" xmlns:tcp="http://www.mulesoft.org/schema/mule/tcp"
    xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:http="http://www.mulesoft.org/schema/mule/http"
    xmlns:cxf="http://www.mulesoft.org/schema/mule/cxf" xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking"
    xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
    xmlns:spring="http://www.springframework.org/schema/beans" xmlns:core="http://www.mulesoft.org/schema/mule/core"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="EE-3.3.0"
    xmlns:script="http://www.mulesoft.org/schema/mule/scripting"
    xsi:schemaLocation="
http://www.mulesoft.org/schema/mule/vm http://www.mulesoft.org/schema/mule/vm/current/mule-vm.xsd 
http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd 
http://www.mulesoft.org/schema/mule/xml http://www.mulesoft.org/schema/mule/xml/current/mule-xml.xsd 
http://www.mulesoft.org/schema/mule/scripting http://www.mulesoft.org/schema/mule/scripting/3.2/mule-scripting.xsd
http://www.mulesoft.org/schema/mule/tcp http://www.mulesoft.org/schema/mule/tcp/current/mule-tcp.xsd 
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd 
http://www.mulesoft.org/schema/mule/cxf http://www.mulesoft.org/schema/mule/cxf/current/mule-cxf.xsd 
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd 
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd 
http://www.mulesoft.org/schema/mule/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd ">
    <spring:beans>
        <spring:bean name="samlCallbackHandler"
            class="com.mulesoft.mule.example.security.SAMLCallbackHandler" id="samlCallbackHandler" />
    </spring:beans>




    <sub-flow name="Jaxws" doc:name="Jaxws">
        <cxf:jaxws-client operation="ExecuteCommand"
            serviceClass="com.nsn.ossbss.charge_once.wsdl.entity.tis.wsdl._1.TisInterface"
            doc:name="UsernameToken SOAP client">
            <!-- <cxf:ws-security> <cxf:ws-config> <cxf:property key="action" value="UsernameToken 
                Timestamp" /> <cxf:property key="user" value="joe" /> <cxf:property key="passwordCallbackClass" 
                value="com.mulesoft.mule.example.security.PasswordCallback" /> <cxf:property 
                key="mustUnderstand" value="false" /> </cxf:ws-config> </cxf:ws-security> -->
        </cxf:jaxws-client>
    </sub-flow>

    <sub-flow name="usernameToken1" doc:name="usernameToken1">
        <!-- <cxf:jaxws-client operation="ExecuteCommand" serviceClass="com.nsn.ossbss.charge_once.wsdl.entity.tis.wsdl._1.TisInterface" 
            doc:name="UsernameToken SOAP client"> <cxf:ws-security> <cxf:ws-config> <cxf:property 
            key="action" value="UsernameToken Timestamp" /> <cxf:property key="user" 
            value="joe" /> <cxf:property key="passwordCallbackClass" value="com.mulesoft.mule.example.security.PasswordCallback" 
            /> <cxf:property key="mustUnderstand" value="false" /> </cxf:ws-config> </cxf:ws-security> 
            </cxf:jaxws-client> -->
        <http:outbound-endpoint exchange-pattern="request-response"
            host="localhost" port="8899" path="cxf/services"
            doc:name="Invoke NSNusernameToken Web Service">
            <cxf:jaxws-client operation="ExecuteCommand"
                serviceClass="com.nsn.ossbss.charge_once.wsdl.entity.tis.wsdl._1.TisInterface"
                doc:name="UsernameToken SOAP client">
                <cxf:ws-security>
                    <cxf:ws-config>
                        <cxf:property key="action" value="UsernameToken Timestamp" />
                        <cxf:property key="user" value="joe" />
                        <cxf:property key="passwordCallbackClass"
                            value="com.mulesoft.mule.example.security.PasswordCallback" />
                        <cxf:property key="mustUnderstand" value="false" />
                    </cxf:ws-config>
                </cxf:ws-security>
                <cxf:inInterceptors />
                <cxf:outInterceptors />



            </cxf:jaxws-client>




        </http:outbound-endpoint>





        <logger message="#[payload]" level="INFO" doc:name="Logger" />

        <mulexml:jaxb-object-to-xml-transformer
            jaxbContext-ref="xmltoobj" />
        <object-to-string-transformer />
        <append-string-transformer message="&#xD;&#xA;" />

        <logger message="#[payload]" level="INFO" doc:name="Logger" />

    </sub-flow>
    <object-to-string-transformer name="ObjectToString" />
    <byte-array-to-string-transformer
        name="ByteArrayToString" />



    <tcp:connector name="TCP_C_L" validateConnections="false"
        receiveBufferSize="102400" sendBufferSize="102400" doc:name="TCP">
        <tcp:xml-protocol />
    </tcp:connector>



    <mulexml:jaxb-context name="myJaxbContext"
        packageNames="com.nsn.ossbss.charge_once.wsdl.entity.tis.xsd._1" />





    <mulexml:jaxb-context name="xmltoobj"
        packageNames="com.nsn.ossbss.charge_once.wsdl.entity.tis.xsd._1" />


    <flow name="NSNServiceClient" doc:name="NSN IN Unified Client Service">
        <tcp:inbound-endpoint host="localhost" port="51000"
            connector-ref="TCP_C_L" />
        <transformer ref="ByteArrayToString" />

        <logger message="#[payload]" level="INFO" doc:name="Logger" />
        <mulexml:jaxb-xml-to-object-transformer
            jaxbContext-ref="myJaxbContext" />

        <flow-ref name="usernameToken1" doc:name="usernameToken1" />

        <logger message="#[payload]" level="INFO" doc:name="Logger" />

        <!-- <default-exception-strategy> <choice> 
        <when evaluator="groovy" expression='payload.getException().getClass().getName().equals("com.nsn.ossbss.charge_once.wsdl.entity.tis.wsdl._1.TisException")'> 
            <logger message="#[payload]" level="INFO" doc:name="Logger" /> <object-to-string-transformer/> 
            <append-string-transformer message="&#xD;&#xA;" /> <vm:outbound-endpoint 
            path="error.notification"/> </when> </choice> </default-exception-strategy> -->



        <catch-exception-strategy>

            <logger message="#[payload]" level="INFO" doc:name="Logger" />

            <transformer ref="ByteArrayToString" />


            <append-string-transformer message="&#xD;&#xA;" />
            <logger message="#[payload]" level="INFO" doc:name="Logger" />




        </catch-exception-strategy>




        <!-- <auto-transformer returnClass="com.nsn.ossbss.charge_once.wsdl.entity.tis.wsdl._1.TisException"/> -->






        <!-- <custom-exception-strategy class="com.nsn.ossbss.charge_once.wsdl.entity.tis.wsdl._1.TisException"> 
            <logger message="#[payload]" level="INFO" doc:name="Logger" /> </custom-exception-strategy> -->

    </flow>




    <flow name="SecurityClients" doc:name="SecurityClients">
        <http:inbound-endpoint exchange-pattern="request-response"
            host="localhost" port="63080" path="client" doc:name="HTTP Inbound Endpoint" />
        <set-payload
            value="#[message.inboundProperties['http.query.params']['name']]"
            doc:name="Set payload with 'name' query param" />
        <set-variable variableName="clientType"
            value="#[message.inboundProperties['http.query.params']['clientType']]"
            doc:name="Set clientType" />
        <choice doc:name="Choice">
            <when expression="#[clientType == 'unsecure']">
                <processor-chain>
                    <flow-ref name="unsecure" doc:name="Invoke unsecure sub-flow" />
                </processor-chain>
            </when>
            <!--<when expression="#[clientType == 'usernameToken']"> <processor-chain> 
                <flow-ref name="usernameToken1" doc:name="usernameToken1" /> </processor-chain> 
                </when> -->
            <when expression="#[clientType == 'usernameTokenSigned']">
                <processor-chain>
                    <flow-ref name="usernameTokenSigned" doc:name="Invoke usernameToken Signed sub-flow" />
                </processor-chain>
            </when>
            <when expression="#[clientType == 'usernameTokenEncrypted']">
                <processor-chain>
                    <flow-ref name="usernameTokenEncrypted" doc:name="Invoke usernameToken Encrypted sub-flow" />
                </processor-chain>
            </when>
            <when expression="#[clientType == 'samlToken']">
                <processor-chain>
                    <flow-ref name="samlToken" doc:name="Invoke samlToken sub-flow" />
                </processor-chain>
            </when>
            <when expression="#[clientType == 'samlTokenSigned']">
                <processor-chain>
                    <flow-ref name="samlTokenSigned" doc:name="Invoke samlToken Signed sub-flow" />
                </processor-chain>
            </when>
            <otherwise>
                <processor-chain>
                    <set-payload value="Client type is not supported"
                        doc:name="Client type is not supported" />
                </processor-chain>
            </otherwise>
        </choice>
        <set-property propertyName="Content-Type" value="text/plain"
            doc:name="Set response Content-Type" />
        <catch-exception-strategy doc:name="Catch Exception Strategy">
            <set-payload value="There has been an Error processing the request"
                doc:name="Set Payload" />
            <set-property propertyName="Content-Type" value="text/plain"
                doc:name="Set response Content-Type" />
        </catch-exception-strategy>



    </flow>
    <sub-flow name="unsecure" doc:name="unsecure">
        <cxf:jaxws-client operation="greet"
            serviceClass="com.mulesoft.mule.example.security.Greeter" doc:name="Unsecure SOAP client"
            doc:description="Unsecure SOAP client" />
        <http:outbound-endpoint exchange-pattern="request-response"
            host="localhost" port="63081" path="services/unsecure" doc:name="Invoke unsecure Web Service" />
    </sub-flow>
    <!-- <sub-flow name="usernameToken" doc:name="usernameToken"> <cxf:jaxws-client 
        operation="greet" serviceClass="com.mulesoft.mule.example.security.Greeter" 
        doc:name="UsernameToken SOAP client"> <cxf:ws-security> <cxf:ws-config> <cxf:property 
        key="action" value="UsernameToken Timestamp"/> <cxf:property key="user" value="joe"/> 
        <cxf:property key="passwordCallbackClass" value="com.mulesoft.mule.example.security.PasswordCallback"/> 
        </cxf:ws-config> </cxf:ws-security> </cxf:jaxws-client> <http:outbound-endpoint 
        exchange-pattern="request-response" host="localhost" port="63081" path="services/username" 
        doc:name="Invoke usernameToken Web Service"/> </sub-flow> -->
    <sub-flow name="usernameTokenSigned" doc:name="usernameTokenSigned">
        <cxf:jaxws-client operation="greet"
            serviceClass="com.mulesoft.mule.example.security.Greeter" doc:name="UsernameToken Signed SOAP client">
            <cxf:ws-security>
                <cxf:ws-config>
                    <cxf:property key="action" value="UsernameToken Signature Timestamp" />
                    <cxf:property key="signaturePropFile" value="wssecurity.properties" />
                    <cxf:property key="user" value="joe" />
                    <cxf:property key="passwordCallbackClass"
                        value="com.mulesoft.mule.example.security.PasswordCallback" />
                </cxf:ws-config>
            </cxf:ws-security>
        </cxf:jaxws-client>
        <http:outbound-endpoint exchange-pattern="request-response"
            host="localhost" port="63081" path="services/signed"
            doc:name="Invoke usernameToken Signed Web Service" />
    </sub-flow>
    <sub-flow name="usernameTokenEncrypted" doc:name="usernameTokenEncrypted">
        <cxf:jaxws-client operation="greet"
            serviceClass="com.mulesoft.mule.example.security.Greeter" doc:name="UsernameToken Encrypted SOAP client">
            <cxf:ws-security>
                <cxf:ws-config>
                    <cxf:property key="action" value="UsernameToken Timestamp Encrypt" />
                    <cxf:property key="encryptionPropFile" value="wssecurity.properties" />
                    <cxf:property key="user" value="joe" />
                    <cxf:property key="encryptionUser" value="joe" />
                    <cxf:property key="passwordCallbackClass"
                        value="com.mulesoft.mule.example.security.PasswordCallback" />
                </cxf:ws-config>
            </cxf:ws-security>
        </cxf:jaxws-client>
        <http:outbound-endpoint exchange-pattern="request-response"
            host="localhost" port="63081" path="services/encrypted"
            doc:name="Invoke usernameToken Encrypted Web Service" />
    </sub-flow>
    <sub-flow name="samlToken" doc:name="samlToken">
        <cxf:jaxws-client operation="greet"
            serviceClass="com.mulesoft.mule.example.security.Greeter" doc:name="SAMLToken SOAP client">
            <cxf:ws-security>
                <cxf:ws-config>
                    <cxf:property key="action" value="SAMLTokenUnsigned Timestamp" />
                    <cxf:property key="samlPropFile" value="saml.properties" />
                    <cxf:property key="samlCallbackClass"
                        value="com.mulesoft.mule.example.security.SAMLCallbackHandler" />
                </cxf:ws-config>
            </cxf:ws-security>
        </cxf:jaxws-client>
        <http:outbound-endpoint exchange-pattern="request-response"
            host="localhost" port="63081" path="services/saml" doc:name="Invoke SAMLToken Web Service" />
    </sub-flow>
    <sub-flow name="samlTokenSigned" doc:name="samlTokenSigned">
        <cxf:jaxws-client operation="greet"
            serviceClass="com.mulesoft.mule.example.security.Greeter" doc:name="SAMLToken Signed SOAP client">
            <cxf:ws-security>
                <cxf:ws-config>
                    <cxf:property key="action" value="SAMLTokenSigned" />
                    <cxf:property key="samlPropFile" value="saml.properties" />
                    <cxf:property key="signatureKeyIdentifier" value="DirectReference" />
                    <cxf:property key="user" value="joe" />
                    <cxf:property key="passwordCallbackClass"
                        value="com.mulesoft.mule.example.security.PasswordCallback" />
                    <cxf:property key="samlCallbackClass"
                        value="com.mulesoft.mule.example.security.SAMLCallbackHandler" />
                </cxf:ws-config>
            </cxf:ws-security>
        </cxf:jaxws-client>
        <http:outbound-endpoint exchange-pattern="request-response"
            host="localhost" port="63081" path="services/signedsaml"
            doc:name="Invoke SAMLToken Signed Web Service" />
    </sub-flow>

</mule>

第一个子流 usernameToken1 正在调用我在 apache camel 上部署的 Web 服务,我刚刚在上面的问题中提到了已引发的异常类。

请让我知道您的反馈,

4

1 回答 1

2

您遇到的问题是,当 Payload 到达异常策略块时,消息已经被 jaxws-client 使用,您无法再获取它。

您可以做的是将 jaxws 客户端置于出站端点之外(就在之前)。在出站端点之后,您将获得 Soap 消息。您只需检查 http 状态即可检查它是否是异常。如果状态为错误,您可以将消息转换为字符串并将其存储在变量中。一旦消息在返回的途中到达客户端,它将解释 Soap 消息并抛出将由异常策略块处理的异常。在异常中,您可以读取存储 Soap Fault 的变量并使用它做任何您想做的事情。

我知道这是一个非常麻烦的解决方案,但这是我唯一能想到的。正如我之前所说的,问题是 HTTP 从服务接收到一个流,然后该流由 jaxws 客户端在解组和抛出异常之前使用。保留 Soap Fault 的唯一方法是 Mule 每次都对输入进行序列化,这可能非常昂贵。

HTH,伊娃

于 2012-11-27T18:23:24.223 回答