WSO2 ESB Endpoints Error Handling
Join the DZone community and get the full member experience.
Join For FreeThis post will illustrate error handling in wso2 esb in regards to Endpoints. It's an import topic to cover because WSO2 Enterprise Service Bus needs to send the message to a service provider in its final stage.
Usecase One:
WSO2 ESB sample proxy is pointing in to End point that can be time out. Proxy must able give nice valid message for to user regard to the is time out rather than false message. Response message is able to customize depending on the Error Code.
1. Create End Point (Web services that will make time out ) and host it. (I am using wso2 AS for to host time out services)
2. Create Proxy that end point
<proxy xmlns="http://ws.apache.org/ns/synapse" name="TimeoutProxy" transports="https,http" statistics="disable" trace="disable" startOnLoad="true"> <target faultSequence="fault"> <outSequence> <log> <property name="Out Sequence Testing " value="=============In Out Sequence============"/> </log> <send/> </outSequence> <endpoint> <address uri="http://localhsot:9763/services/TimeoutService/"> <timeout> <duration>1000</duration> <responseAction>discard</responseAction> </timeout> </address> </endpoint> </target> <description></description> </proxy>
3. Go to "Home > Manage > Service Bus > Sequences" and Click on fault Sequence Edit link
4. Update it with below code
<sequence xmlns="http://ws.apache.org/ns/synapse" name="fault"> <property xmlns:ns="http://org.apache.synapse/xsd" name="ErrorCode" expression="get-property('ERROR_CODE')" scope="default" type="INTEGER"/> <log level="custom"> <property name="failS" value="=======False Sequence==========="/> <property xmlns:ns="http://org.apache.synapse/xsd" name="testCode" expression="$ctx:ErrorCode"/> </log> <switch xmlns:ns="http://org.apache.synapse/xsd" source="$ctx:ErrorCode"> <case regex="303001"> <log> <property name="go" value="==== 303001 ==== Error msg transformation"/> </log> </case> <case regex="101503"> <log> <property name="go" value="==== 101503 ==== Error msg transformation"/> </log> </case> </switch> <drop/> </sequence >
NOTE
Transport Error Codes
Endpoint Failures
Here is console of wso2 ESB
5. You can do switch depending on your Error Code or Action
<property xmlns:ns="http://org.apache.synapse/xsd" name="Action" expression="get-property('Action')"/>
Or
<property xmlns:ns="http://org.apache.synapse/xsd" name="ErrorCode" expression="get-property('ERROR_CODE')" scope="default" type="INTEGER"/>
6. Rather Logging We need to get Respond Message where user can understand what was happen.
Here is sample Msg for that Error code 101503
<getBusRootResponse xmlns=""> <error> <errorCode>101503</errorCode> <errorMsgTitle>Network Connection Failure</errorMsgTitle> <errorMsg>We are unable to get Connection to BusRoot Services</errorMsg> </error> </getBusRootResponse>
Add payload for each case and build your message or add property each case have constracted message details to be show
7. Remove Header “TO”
8. Add Property "RESPONSE" as "true"
9. Replace Drop with Send
Here is fault sequence
<sequence xmlns="http://ws.apache.org/ns/synapse" name="fault"> <log level="full"/> <property xmlns:ns="http://org.apache.synapse/xsd" name="ErrorCode" expression="get-property('ERROR_CODE')" scope="default" type="INTEGER"/> <log level="custom"> <property name="failS" value="=======False Sequence==========="/> <property xmlns:ns="http://org.apache.synapse/xsd" name="testCode" expression="$ctx:ErrorCode"/> <property xmlns:ns="http://org.apache.synapse/xsd" name="Action" expression="get-property('Action')"/> </log> <switch xmlns:ns="http://org.apache.synapse/xsd" source="$ctx:ErrorCode"> <case regex="303001"> <log> <property name="go" value="==== 303001 ==== Error msg transformation"/> </log> <payloadFactory> <format> <getBusRootResponse xmlns=""> <error> <errorCode>301503</errorCode> <errorMsgTitle>EndPoint Connection Failure</errorMsgTitle> <errorMsg>We are unable to get Connection to BusRoot Services Provider</errorMsg> </error> </getBusRootResponse> </format> </payloadFactory> </case> <case regex="101503"> <log> <property name="go" value="==== 101503 ==== Error msg transformation"/> </log> <payloadFactory> <format> <getBusRootResponse xmlns=""> <error> <errorCode>101503</errorCode> <errorMsgTitle>Network Connection Failure</errorMsgTitle> <errorMsg>We are unable to get Connection to BusRoot Services</errorMsg> </error> </getBusRootResponse> </format> </payloadFactory> </case> </switch> <header name="To" action="remove"/> <property name="RESPONSE" value="true"/> <send/> </sequence>
Here is Out from Try it
Published at DZone with permission of Madhuka Udantha, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.
Trending
-
Incident Response Guide
-
Payments Architecture - An Introduction
-
Demystifying SPF Record Limitations
-
DevOps Midwest: A Community Event Full of DevSecOps Best Practices
Comments