Thursday, February 09, 2012

BPEL - How to handle an embeded XML message in a fault

In the development, the third part service returns a fault with a XML as a fault detail.
In order to get the real error message, I have to parse this XML to get the error code and error message.

In SOA Suite, there is a function named as parseXML.

This function parses a string to a DOM element.
contentString - The string that this function parses to a DOM element.
Property IDs: 
namespace-prefix: oratext

First, I need to get the XML message in the element <WL_FAULT_DETAIL>. The code is the follow. By this, I will be able to get a XML element <WL_FAULT_DETAIL>, which contains a XML string.

The follow code will parse the XML string held by element <WL_FAULT_DETAIL> to a XML.

The above expression means:
1. Parse the detail to a XML and this XML contains another XML string like the follow.
<ser:ServiceFault xmlns:ser=""><ser:Error id="1" lang="en"><ser:ErrorCode>SYSTEM FAILURE</ser:ErrorCode><ser:Description>[com.bea.nonxml.common.MFLException.create( at com.bea.nonxml.common.MFLException.create( at com.bea.nonxml.readers.NonXMLReaderVisitor.nextToken( at com.bea.nonxml.readers.TokenNonXMLReader.nextToken( at at com.bea.wli.variables.util.TokenSourceSerializer.process( at com.bea.wli.variables.ProcessXML.storeXML( at com.bea.wli.variables.ProcessXML.storeTokenSource( at com.bea.wli.variables.ProcessXML.&lt;init>( at com.bea.wli.variables.XmlObjectVariableFactory.createProxy( at com.bea.wli.variables.XmlObjectVariableFactory.createProxy( at com.bea.wli.variables.MflObject.convertToXmlObject( 
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) a...]</ser:Description><ser:Value>RSSP</ser:Value></ser:Error></ser:ServiceFault>.

2. Pass the above text as a string to parseXML to get another XML and the root element will be <ser:ServiceFault>.

Then, it will be very esay to get the error code and error message by getChildElement function.
Error Code is
Error Message is

No comments: