Oracle Service Bus, Generic fault handling

For a usecase i needed a construction which would give me the option to implemenent generic service error handling in which i could conditionally execute activities like alerts, reports, logging, etc
One place which will contain all the error handling logic and which could be easily extended both in implementation of the logic for handling errors and being able to easily add new errors to be handle which the metadata for this error.

In case third party applications decide to trigger new type of exceptions/faults i don’t want to change the fault handling logic of all the process which do a call to this service. I want to be able to add the to be executed logic for this new specific error to some sort of error repository together with some setup-settings.

Definition of the error repository
In our case the error repository is nothing more then a xml metadata storage which stores settings for the errors to be handled.
The definition of the metadata can be extended with other settings which can be retrieved at one central place again and logic for handling the settings will also be centrally defined.

Definition of the error handling service
In our case the error handling service will be the central point in which we retrieve instance data from the process in which the occured fault.
Based on this data we will retrieve metadata for the fault and decide in the message flow handling what the logic will be to execute.

Error Repository

Schema definition

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns="http://nl.xenta/services/errorRepository" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://nl.xenta/services/errorRepository">
	<xs:element name="service_error_handling">
		<xs:complexType>
			<xs:sequence>
				<xs:element ref="error" maxOccurs="unbounded"/>
			</xs:sequence>
		</xs:complexType>
	</xs:element>
	<xs:element name="indReporting">
		<xs:simpleType>
			<xs:restriction base="xs:string">
				<xs:enumeration value="Y"/>
				<xs:enumeration value="N"/>
			</xs:restriction>
		</xs:simpleType>
	</xs:element>
	<xs:element name="description">
		<xs:simpleType>
			<xs:restriction base="xs:string"/>
		</xs:simpleType>
	</xs:element>
	<xs:element name="sourceSystem">
		<xs:simpleType>
			<xs:restriction base="xs:string">
				<xs:enumeration value="SYSTEM-X"/>
				<xs:enumeration value="OSB"/>
				<xs:enumeration value="NA"/>				
			</xs:restriction>
		</xs:simpleType>
	</xs:element>
	<xs:element name="indLogging">
		<xs:simpleType>
			<xs:restriction base="xs:string">
				<xs:enumeration value="Y"/>
				<xs:enumeration value="N"/>
			</xs:restriction>
		</xs:simpleType>
	</xs:element>
	<xs:element name="faultTransformer">
		<xs:simpleType>
			<xs:restriction base="xs:string"/>
		</xs:simpleType>
	</xs:element>
	<xs:element name="externalCode">
		<xs:simpleType>
			<xs:restriction base="xs:string">
				<xs:enumeration value="XXX_DEFAULT_ERROR"/>
				<xs:enumeration value="GENERIC-1234"/>
				<xs:enumeration value="VALIDATE-9999"/>
			</xs:restriction>
		</xs:simpleType>
	</xs:element>
	<xs:element name="error">
		<xs:complexType>
			<xs:sequence>
				<xs:element ref="code"/>
				<xs:element ref="externalCode"/>
				<xs:element ref="description"/>
				<xs:element ref="sourceSystem"/>
				<xs:element ref="faultTransformer"/>
				<xs:element ref="indAlert"/>
				<xs:element ref="indAlertOverwriteDestionation"/>
				<xs:element ref="alertDestination"/>
				<xs:element ref="indLogging"/>
				<xs:element ref="indReporting"/>
			</xs:sequence>
		</xs:complexType>
	</xs:element>
	<xs:element name="code">
		<xs:simpleType>
			<xs:restriction base="xs:string">
				<xs:enumeration value="BEA-382505"/>
				<xs:enumeration value="DEFAULT"/>
				<xs:enumeration value="BEA-380000"/>
			</xs:restriction>
		</xs:simpleType>
	</xs:element>
	<xs:element name="indAlertOverwriteDestionation">
		<xs:simpleType>
			<xs:restriction base="xs:string">
				<xs:enumeration value="Y"/>
				<xs:enumeration value="N"/>
			</xs:restriction>
		</xs:simpleType>
	</xs:element>
	<xs:element name="indAlert">
		<xs:simpleType>
			<xs:restriction base="xs:string">
				<xs:enumeration value="Y"/>
				<xs:enumeration value="N"/>
			</xs:restriction>
		</xs:simpleType>
	</xs:element>
	<xs:element name="alertDestination">
		<xs:complexType/>
	</xs:element>
</xs:schema>

Modeling the error handling proxy service

The error handling proxy service will be the central point of executing location based on the incoming occured fault.

  • Create a new proxy service called ErrorHandler of Service Type ‘Any XML Service’

    The input we will send to this service will be in the format of

    <errorData>
    	<body>{$body}</body>
    	<inbound>{$inbound}</inbound>
    	<fault>{$fault}</fault>
    </errorData>
    

    The flow will eventually look something like this

    Let’s look at the individual steps

    1. retrieveErrorMetadata

    The first step will contain 2 assigns.

    The first assign will assign the ErrorRepository.xq to variable errorList

    The content of the ErrorRepository.xq is the next

    xquery version "1.0" encoding "Cp1252";
    (:: pragma  type="xs:anyType" ::)
    
    declare namespace xf = "http://nl.xenta/services/errorRepository";
    
    declare function xf:service_error_handling()
        as element(*) {
    		<service_error_handling xmlns="http://nl.xenta/services/errorRepository" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    			<error>
    				<code>BEA-382505</code>
    				<externalCode>VALIDATE-9999</externalCode>
    				<description>Validation of the XML payload failed</description>
    				<sourceSystem>OSB</sourceSystem>
    				<faultTransformer>ErrorHandling/errorRepository/GenericFault_To_SOAPFault</faultTransformer>
    				<indAlert>Y</indAlert>
    				<indAlertOverwriteDestionation>N</indAlertOverwriteDestionation>
    				<alertDestination/>
    				<indLogging>Y</indLogging>
    				<indReporting>Y</indReporting>
    			</error>
    			<error>
    				<code>BEA-380000</code>
    				<externalCode>GENERIC-1234</externalCode>
    				<description>General transport error occured</description>
    				<sourceSystem>SYSTEM-X</sourceSystem>
    				<faultTransformer>ErrorHandling/errorRepository/GenericFault_To_SOAPFault2</faultTransformer>
    				<indAlert>Y</indAlert>
    				<indAlertOverwriteDestionation>N</indAlertOverwriteDestionation>
    				<alertDestination/>
    				<indLogging>Y</indLogging>
    				<indReporting>Y</indReporting>
    			</error>
    			<error>
    				<code>DEFAULT</code>
    				<externalCode>XXX_DEFAULT_ERROR</externalCode>
    				<description>Something went wrong!</description>
    				<sourceSystem>NA</sourceSystem>
    				<faultTransformer>ErrorHandling/errorRepository/GenericFault_To_SOAPFault</faultTransformer>
    				<indAlert>Y</indAlert>
    				<indAlertOverwriteDestionation>N</indAlertOverwriteDestionation>
    				<alertDestination/>
    				<indLogging>Y</indLogging>
    				<indReporting>Y</indReporting>
    			</error>
    		</service_error_handling>
    };
    
    xf:service_error_handling()
    
    

    At this point we have the list of faults together with metadata about what to execute when they occure available in the Message Flow.

    In the second assign we retrieve only the the metadata from our occured fault, so we just retrieve 1 error-element from the list.

    For this we execute the lookupError xquery which receives the errorList content and the errorCode and will return the error-element.
    If we can’t retrieve any metadata based on the errorCode we will return a default set of metadata (the error-element of which the code = DEFAULT).
    The result we will assign to the errorMetadataDetails variable.

    Content of lookupError xquery

    (:: pragma bea:global-element-parameter parameter="$errorList" element="err:service_error_handling" location="ErrorRepository.xsd" ::)
    (:: pragma bea:global-element-return element="ns0:error" location="ErrorRepository.xsd" ::)
    
    declare namespace err = "http://nl.xenta/services/errorRepository";
    declare namespace xf = "http://nl.xenta/services/faults/lookupError/";
    
    declare function xf:lookupError2($errorCode as xs:string,
        $errorList as element(err:service_error_handling))
        as element(err:error) {
        
    		if(string-length($errorList/err:error[err:code=$errorCode]) > 0)
       		then (
    			let $resolvedError := $errorList/err:error[err:code=$errorCode]
    	   		return $resolvedError
       		) else (
       			let $resolvedError := $errorList/err:error[err:code='DEFAULT']
       			return $resolvedError
       		)    
    };
    
    declare variable $errorCode as xs:string external;
    declare variable $errorList as element(err:service_error_handling) external;
    
    xf:lookupError2($errorCode,$errorList)
    

    2. conditionalReporting

    In all the conditional stages we will now re-use the errorMetadataDetails variable to verify if we want to execute certain login.

    If we configurated the indReporting=Y in the error repository xquery file then the if-then loginc will evaluate to the if-tree and the Report-activty will be executed.
    In the same way all the other condition stages (conditionalAlert, conditionalSomethingElse) will work. We re-use the errorMetadataDetails-variable and just do a simple if-then check to see if certain logic needs to be executed.

    3. constructResponse

    The last step of the message flow is the step in which we construct the response of the errorHandler process back to the client process.
    In this step we will be using Dynamic Xquery to be able the construct response messages based on the incoming fault.
    The example of our ErrorReposity defines 2 faults and 1 default.
    In case for example error BEA-380000 occures, we will use the xquery located at ErrorHandling/errorRepository/GenericFault_To_SOAPFault2 to be executed. This xquery will construct our soap fault.

    To be able to use Dynamic Xquery all the to be used xquery transformations need to have the same interface. Depending on the backend system and the returning faults from it we will use different tranformation files.
    But all of them will be using the input paramters ‘body, inbound and fault’. In the expression field we will use the faultTransformer-element from the errorMetadataDetails. So for every fault for which we want to create a
    different fault response we do need to define a faultTransformer-value in the errorRepository.

    And that’s all what is needed to implement in the errorHandler process to receive the metadata, handle the fault and construct the response.

    Testcase

    For this testcase we created a simple EmployeeService. Create a new proxy service based on the next wsdl/xsd content.

    <?xml version="1.0" encoding="UTF-8"?>
    <wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:tns="http://new.webservice.namespace" xmlns:ns="http://nl.xenta/services/employee" targetNamespace="http://new.webservice.namespace">
    	<wsdl:import namespace="http://nl.xenta/services/employee" location="EmployeeService.xsd"/>
    	<wsdl:message name="NewMessageRequest">
    		<wsdl:part name="parameter" element="ns:employee_request"/>
    	</wsdl:message>
    	<wsdl:message name="NewMessageResponse">
    		<wsdl:part name="parameter" element="ns:employee_response"/>
    	</wsdl:message>
    	<wsdl:portType name="EmployeeServicePort">
    		<wsdl:operation name="getEmployee">
    			<wsdl:input message="tns:NewMessageRequest"/>
    			<wsdl:output message="tns:NewMessageResponse"/>
    		</wsdl:operation>
    	</wsdl:portType>
    	<wsdl:binding name="EmployeeServiceBinding" type="tns:EmployeeServicePort">
    		<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
    		<wsdl:operation name="getEmployee">
    			<soap:operation soapAction="urn:#NewOperation"/>
    			<wsdl:input>
    				<soap:body use="literal"/>
    			</wsdl:input>
    			<wsdl:output>
    				<soap:body use="literal"/>
    			</wsdl:output>
    		</wsdl:operation>
    	</wsdl:binding>
    	<wsdl:service name="EmployeeService">
    		<wsdl:port name="EmployeeServiceSOAPPort" binding="tns:EmployeeServiceBinding">
    			<soap:address location="No Target Adress"/>
    		</wsdl:port>
    	</wsdl:service>
    </wsdl:definitions>
    
    <?xml version="1.0" encoding="UTF-8"?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" targetNamespace="http://nl.xenta/services/employee" attributeFormDefault="unqualified">
    	<xs:element name="employee_request">
    		<xs:annotation>
    			<xs:documentation>Comment describing your root element</xs:documentation>
    		</xs:annotation>
    		<xs:complexType>
    			<xs:sequence>
    				<xs:element name="emp_id" type="xs:int"/>
    			</xs:sequence>
    		</xs:complexType>
    	</xs:element>
    	<xs:element name="employee_response">
    		<xs:complexType>
    			<xs:sequence>
    				<xs:element name="employee">
    					<xs:complexType>
    						<xs:sequence>
    							<xs:element name="firstname"/>
    							<xs:element name="lastname"/>
    							<xs:element name="birthdate" type="xs:date"/>
    						</xs:sequence>
    					</xs:complexType>
    				</xs:element>
    			</xs:sequence>
    		</xs:complexType>
    	</xs:element>
    </xs:schema>
    

    And the message flow will eventually look like this

    The first assign will assign the body to body_temp so in case of an error situation we still have the original body content stored

    The second activity is the validation activity. This one we will be using lateron to trigger a fault which will be processed by the errorHandler process.
    Based on the same wsdl as the proxy service i defined a new business service. In the EmployeeService proxy we will be routing to this business service.
    Since we won’t be implementing any logic on this side we just update the endpoint of the business service to something useless so the route will fail on this one.

    This part is used to the second fault triggering moment in our process. Also this situation will fail and the occured fault will get processed by the errorHandler.

    The ‘normal’ message flow of our proxy service is now done.
    Let’s have a look at the service error handler.

    The first assign will use the next xquery and assign the result to errorhandler_request

    xquery version "1.0" encoding "Cp1252";
    (:: pragma  parameter="$body" type="xs:anyType" ::)
    (:: pragma  parameter="$fault" type="xs:anyType" ::)
    (:: pragma  parameter="$inbound" type="xs:anyType" ::)
    (:: pragma  type="xs:anyType" ::)
    
    declare namespace xf = "http://tempuri.org/ErrorHandling/proxy/constructErrorHandlingInput/";
    
    declare function xf:constructErrorHandlingInput($body as element(*),
        $fault as element(*),
        $inbound as element(*))
        as element(*) {
            <errorData>
    			<body>{$body}</body>
    			<inbound>{$inbound}</inbound>
    			<fault>{$fault}</fault>
    		</errorData>
    };
    
    declare variable $body as element(*) external;
    declare variable $fault as element(*) external;
    declare variable $inbound as element(*) external;
    
    xf:constructErrorHandlingInput($body, $fault, $inbound)
    

    In the binding we will use the body_temp variable so we have the original body content of the process.

    The next activity is the service callout to the errorHandler process

    The third activity is an assign which will assign the constructed body from the errorHandler process to the body variable

    And the last activity will be a ‘Reply with Failure’

    Testrun

    In the ErrorRepository we defined 2 faults, BEA-382505 and BEA-380000.
    For both faults we defined a different faultTransformer.

    BEA-382505 = ErrorHandling/errorRepository/GenericFault_To_SOAPFault
    BEA-380000 = ErrorHandling/errorRepository/GenericFault_To_SOAPFault2

    GenericFault_To_SOAPFault will return

    		<soapenv:Fault>
    		<faultcode>soapenv:Server</faultcode>
    		(:<faultstring>{data($errorMetadataDetails/err:omschrijving)}</faultstring>:)
    		<faultstring>some resource path</faultstring>
    		<faultactor>{fn:concat($inbound/ctx:transport/ctx:request/tp:headers/http:Host/text(),"/",$inbound/ctx:transport/ctx:uri/text())}</faultactor>
    		   <detail>
    				<custom_details>
    					<payload>{$body, $fault, $inbound}</payload>
    				</custom_details>				
    		   </detail>
    		</soapenv:Fault>	
    

    GenericFault_To_SOAPFault2 will return

    		<soapenv:Fault>
    		<faultcode>soapenv:Server</faultcode>
    		(:<faultstring>{data($errorMetadataDetails/err:omschrijving)}</faultstring>:)
    		<faultstring>some resource path</faultstring>
    		<faultactor>{fn:concat($inbound/ctx:transport/ctx:request/tp:headers/http:Host/text(),"/",$inbound/ctx:transport/ctx:uri/text())}</faultactor>
    		   <detail>
    				<custom_details2>
    				  <payload>{$body, $fault, $inbound}</payload>
    				</custom_details2>				
    		   </detail>
    		</soapenv:Fault>	
    

    Deploy the process.

    Now test the process either by using the testconsole of some testclient.

    The first testcase will have a valid input message. So the process will pass the Validation activity and will fail when routing to the business service.
    Since we used a non-existing host in here the process will trigger a BEA-380000 fault. As we defined in the errorRepository this errorCode will have the next set of metadata configured

    			<error>
    				<code>BEA-380000</code>
    				<externalCode>GENERIC-1234</externalCode>
    				<description>General transport error occured</description>
    				<sourceSystem>SYSTEM-X</sourceSystem>
    				<faultTransformer>ErrorHandling/errorRepository/GenericFault_To_SOAPFault2</faultTransformer>
    				<indAlert>Y</indAlert>
    				<indAlertOverwriteDestionation>N</indAlertOverwriteDestionation>
    				<alertDestination/>
    				<indLogging>Y</indLogging>
    				<indReporting>Y</indReporting>
    			</error>
    

    The generated soap fault is correct. It contains the custom_details2-element, which is generated by the GenericFault_To_SOAPFault2 transformer.
    Next check the sbconsole to see if there is also a report triggered for this error (indReporting=Y).

    Next check the weblogic console to see if the alert got executed (indAlert=Y). For this one i created an alert with JMS Destionation.

    For the second testcase we will use an invalid input message. The validation will throw an error (BEA-382505).
    Check the generated soap fault (custom_details-element should get generated now).

    And verify the alert and report too, to see if they got handled correctly.

    Extensibility

    In our xsd definition of the errorRepository we only defined a few settings just to show how it could work.
    Eventually this model can be extend with every setting you need in your error handling processes. Since all the logic of reading those settings and decide what logic to execute is defined on only
    one place, the errorHandler proxy service itself, it’s little work to extend the current logic for handlin the errors with new functionality. Just a new if-then activities for new settings and you’re ready to go.

    Conclusion

    The functionality as defined in the blog for handling the errors and creating a single point of error processing was enough for my testcase.
    I needed all the logic on one place and not in every process. I needed a single place in which i could define all the errors i wanted to handle and what actions to execute when such an error occurs.
    Besides that i needed a way in which other persons could easily add new defined errors to the file and the process would just ‘handle’ them without adding extra logic to processes.
    In case you don’t want someone else to manipulate the errorRepository file directly from within the sbconsole itself we could also just read the content of this file from some other external location by use of the doc() function, see this blog.

    I hope the solution described will help you a bit on implementation error handling in the Oracle Service Bus.
    As i’m always keen on learning from others, please leave comments on how to make the implementation better, or if the solution is totally useless please say so too :)

    download : OracleServiceBusGenericErrorHandling.zip

  • Share this Post:
    Digg Google Bookmarks reddit Mixx StumbleUpon Technorati Yahoo! Buzz DesignFloat Delicious BlinkList Furl

    65 Responses to “Oracle Service Bus, Generic fault handling”

    commenter

    Hi Eric,

    I am not able to see the error code BEA 382505 even after sending the invalid XML as suggested in your test case. Can you please let me know to what could be missing. I didn’t change anything in the project.

    Thanks,
    Moosvi

    commenter

    Hi Moosvi,

    What’s the return message you do see?

    commenter

    Hi Eric,

    Thanks for the reply. The error code that I see in the adminServer.log is perfectly fine, meaning it match the expected result as per the test case describe however this is not the case with SOAP UI. I see the same error code BEA382505 in SOAP UI whether I send the valid or invalid employee ID. Any reason do you know why SOAP is showing the same error code for valid and invalid ID but adminServer.log is showing the correct way.

    Thanks,
    Moosvi

    commenter

    Hi Moosvi,

    Can you try setting up a debug session from within Eclipse and follow the message to see what happens? Hard for me to find out what is going wrong.

    commenter

    Hi Eric,

    Thanks I am able to retrieve the message that I am looking for.

    Another quick one. Do you know the best possible way to extract the SOAP message. Currently I am sending the entire SOAP body and publishing it to my email service but I need a XQuery to just extract errorCode and route node info. I am new to XQuery so need your help.

    Thanks,
    Moosvi

    commenter

    Hi Eric.
    First, thank you very much for your blog. I have read several articles and it have helped me a lot.
    For generic fault handling I followed your instructions and it has worked fine. Now I wonder how I could have the definition of errors in a database.
    I could use a JCA resource for access to DB, ¿is this the best option?, Can you help?

    Greetings from Spain 😉

    commenter

    I think that’s indeed the best and easiest way to make a call to the database. You could add result caching to the db adapter to make it even more faster since most of the error configuration won’t change that often

    commenter

    Thank you very much Eric!.

    I’m trying to centralize in a single proxy (proxy manager), all the monitoring (alerts, reports, logs…), but I have a question:

    Is it possible to find out, a proxys or busines services operational configuration, from their execution context?

    The idea is to call the proxy manager only when the monitored parameter is activated.

    Best regards.

    commenter

    I think you need to create a java callout for that which will use some mbean to retrieve the proxyservice/business info.

    commenter

    Great Article!!Just one question here for most projects we use soa (bpel) and OSB services both. In such case do you recommend using this kind of framework for logging, auditing and error handling for both bpel and OSB components with OSB services used for this purpose.

    Thanks.

    commenter

    When a service is getting invoked, does this always happen on the OSB or do clients also invoke BPEL directly ?
    If it’s the first, then i would only log the error in the OSB and let BPEL propogate it back to the OSB. If you want to be able to retry both OSB and BPEL services,you will need to make the framework dynamic so you know which component logged/triggered the fault

    […] Oracle Service Bus, Generic fault handling – Oracle … – For a usecase i needed a construction which would give me the option to implemenent generic service error handling in which i could conditionally execute activities …… […]

    commenter

    Fantastic article.

    Leave a Reply:

    Name (required):
    Mail (will not be published) (required):
    Website:
    Comment (required):
    XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>