-->

How can I access this message in fault sequence in

2019-02-27 23:56发布

问题:

How can I access this error text which is from wso2dss side standard error in WSO2 ESB fault sequence ERROR_CODE?

I am getting properly but this ERROR_MESSAGE giving NUll. How can I do this?

This is WSO2DSS standard ERROR message:

<soapenv:Fault xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
   <soapenv:Code>
      <soapenv:Value>soapenv:Receiver</soapenv:Value>
   </soapenv:Code>
   <soapenv:Reason>
      <soapenv:Text xml:lang="en-US" xmlns:xml="http://www.w3.org/XML/1998/namespace">The emp_DataService service, which is not valid, does not belong to the emp_DataService service group.</soapenv:Text>
   </soapenv:Reason>
   <soapenv:Detail/>
</soapenv:Fault>

I want to access the code of error as well as error text. Why? Because I need send a mail to backend department which will help them to trace a error as soon as possible.

How can I do this in WSO2ESB?

I want this two nodes to show:

  1. <soapenv:Code>
              <soapenv:Value>soapenv:Receiver</soapenv:Value>
           </soapenv:Code>
    
  2. 2.
 &ltsoapenv:Text xml:lang="en-US"
 xmlns:xml="http://www.w3.org/XML/1998/namespace">The emp_DataService
 service, which is not valid, does not belong to the emp_DataService
 service group. &lt/soapenv:Text>

How can I access this? Anyone know this?

回答1:

In ESB as default the SOAP error is not recognized. It just passes it as a basic soap Message. In order to identify it as a SOAP_FAULT you should set the property

<property name="FORCE_ERROR_ON_SOAP_FAULT" value="true">

After wards it will trigger fault sequence for the incoming SOAP_FAULT. So you have to declare coming message is a SOAP_FAULT so you hace to say it is a SOAP_FAULT and force it to error sequence. This is explained in [1] a blog past my Amila.

For the second part of the question you can use payload Factory transformation. You can use following sequence.

<sequence xmlns="http://ws.apache.org/ns/synapse" name="ErrorTransformSequence">
   <log level="full">
      <property name="SEQUENCE" value="----------------DSS FAULT------------------"/>
   </log>
   <payloadFactory>
      <format>
         <m:errorMessage xmlns:m="http://dss.error">                  
            <m:error>                     
               <m:message>$1</m:message>                  
            </m:error>
         </m:errorMessage>
      </format>
      <args>
         <arg value="/soapenv:Fault/soapenv:Reason/soapenv:Text/text()"/>
      </args>
   </payloadFactory>
   <header name="Action" value="urn:errormsg"/>
   <property name="OUT_ONLY" value="true" scope="default" type="STRING"/>
   <send>
      <endpoint>
         <address uri="http://localhost:9765/services/DssService.SOAP11Endpoint/"/>
      </endpoint>
   </send>
</sequence>

canbe pointed to any of your email client. The given xpath directly pointing to the error message of the SOAP response you have posted in your question.

And to senf the email you can use wso2 esb mail transport in [2].

[1]. http://maharachchi.blogspot.com/2012/09/now-you-can-send-soapfaults-to-fault.html.

[2]. http://wso2.org/library/knowledge-base/use-mail-transport-esb-convert-soap-message-plain-text-mail



回答2:

Please use the following code as the faultSequence.

<faultSequence>
<log level="custom">
<property name="message" expression="get-property('ERROR_MESSAGE')"/>
</log>
</faultSequence>