2012-11-08 112 views
1

我在使用內部http出站流中的jaxws-client的mule通信中使用以下XML(POJO是出站Jaxws客戶端的輸出)。Mule ESB CXF異常handeling

使用WSDL2Java的插件在行家確保生成WS代碼,生成的代碼具有用於異常從WS來類的類是:

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

肯定的HTTP響應500的時候,我們得到的SOAPFault的WS提出了這個例外

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: [email protected] 
INFO 2012-11-08 11:08:13,010 [[cxf].TCP_C_L.receiver.02] org.mule.api.processor.LoggerMessageProcessor: [email protected] 

使用HANDELING錯誤時拋出的時候,我發現了上述錯誤之後:

<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駝峯相同的異常,我需要指定騾子異常,並且mule不應在控制檯中引發上述異常,因爲它將由XML配置處理。

從JAXWS客戶端傳出傳入消息的類型是

[email protected]

如何管理,使騾子ESB瞭解WS例外,我試過這個

它沒有工作。

可以請您指教。

在保險絲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> 

我怎樣才能在騾子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的駱駝的Web服務,我只是在已經提出的異常類上面提到的問題。

請讓我知道你的反饋,

+0

您是否也可以共享流量配置? – genjosanzo

+0

請有人回答我已添加流量配置? – user1724562

+0

好吧,如果我理解正確,你想捕捉異常的catch-exception-strategy並克里特肥皂發回給客戶在那裏? – genjosanzo

回答

2

您遇到的問題是,由當時的有效載荷達到例外策略塊,消息已經被JAXWS客戶端消耗,你不能弄個它了。

你可以做的是讓出站端點之外的jaxws客戶端(之前)。在出站端點之後,您將擁有Soap消息。你可以通過檢查http狀態來檢查它是否是一個異常。如果狀態爲錯誤,則可以將消息轉換爲字符串並將其存儲在變量中。一旦消息在返回時到達客戶端,它將解釋Soap消息並拋出將由異常策略塊處理的異常。在例外情況下,您可以讀取存儲Soap Fault的變量並根據需要執行任何操作。

我知道這是一個非常麻煩的解決方案,但它是我能想到的唯一一個。正如我之前所說的,問題在於HTTP從服務接收到一個流,然後該流在解組並拋出異常之前被jaxws客戶端使用。保持Soap Fault的唯一方法是,如果Mule每次對輸入進行序列化,這可能非常昂貴。

HTH, Eva