Reputation: 123
I'm working with wso2 ESB 6.3.0 My complete functionality is: make a call to a service rest api if getting any response to send the mail process was done but requriment is with out 200 status code remaimimg any status code sending the mail (ex: iam getting error code or success code to send send the mail reming 200 error code if any error code to send the mail.if any one please suggest me.
<?xml version="1.0" encoding="UTF-8"?>
<api context="/first" name="firston" xmlns="http://ws.apache.org/ns/synapse">
<resource methods="GET">
<inSequence>
<property description="http" name="HTTP_SC" scope="axis2" type="STRING" value="404"/>
<log level="full"/>
<send>
<endpoint key="firstapi"/>
</send>
</inSequence>
<outSequence>
<switch source="get-property('axis2','HTTP_SC')">
<case regex="200">
<log description="200log" level="custom">
<property expression="$ctx:ERROR_CODE" name="200reserrorcode"/>
<property expression="$ctx:ERROR_MESSAGE" name="200reserrormessage"/>
<property expression="get-property('axis2','HTTP_SC')" name="200reshttpsc"/>
</log>
</case>
<case regex="400">
<log description="400log" level="custom">
<property expression="$ctx:ERROR_CODE" name="400reserrorcode"/>
<property expression="$ctx:ERROR_MESSAGE" name="400reserrormessage"/>
<property expression="get-property('axis2','HTTP_SC')" name="400reshttpsc"/>
</log>
</case>
<case regex="404">
<log description="404log" level="custom">
<property expression="$ctx:ERROR_CODE" name="404reserrorcode"/>
<property expression="$ctx:ERROR_MESSAGE" name="404reserrormessage"/>
<property expression="get-property('axis2','HTTP_SC')" name="404reshttpsc"/>
</log>
</case>
<case regex="500">
<log description="500log" level="custom">
<property expression="$ctx:ERROR_CODE" name="500reserrorcode"/>
<property expression="$ctx:ERROR_MESSAGE" name="500reserrormessage"/>
<property expression="get-property('axis2','HTTP_SC')" name="500reshttpsc"/>
</log>
</case>
<default>
<log description="reslog" level="custom">
<property expression="$ctx:ERROR_CODE" name="reserrorcode"/>
<property expression="$ctx:ERROR_MESSAGE" name="reserrormessage"/>
<property expression="get-property('axis2','HTTP_SC')" name="reshttpsc"/>
</log>
</default>
</switch>
<clone continueParent="true">
<target>
<sequence>
<sequence key="sendthemail"/>
</sequence>
</target>
</clone>
<send/>
</outSequence>
<faultSequence>
<switch source="get-property('axis2','HTTP_SC')">
<case regex="200">
<log description="200log" level="custom">
<property expression="$ctx:ERROR_CODE" name="200errorcode"/>
<property expression="$ctx:ERROR_MESSAGE" name="200errormessage"/>
<property expression="get-property('axis2','HTTP_SC')" name="200httpsc"/>
</log>
</case>
<case regex="400">
<log description="400log" level="custom">
<property expression="$ctx:ERROR_CODE" name="400errorcode"/>
<property expression="$ctx:ERROR_MESSAGE" name="400errormessage"/>
<property expression="get-property('axis2','HTTP_SC')" name="400httpsc"/>
</log>
</case>
<case regex="404">
<log description="404log" level="custom">
<property expression="$ctx:ERROR_CODE" name="404errorcode"/>
<property expression="$ctx:ERROR_MESSAGE" name="404errormessage"/>
<property expression="get-property('axis2','HTTP_SC')" name="404httpsc"/>
</log>
</case>
<case regex="500">
<log description="500log" level="custom">
<property expression="$ctx:ERROR_CODE" name="500reserrorcode"/>
<property expression="$ctx:ERROR_MESSAGE" name="500reserrormessage"/>
<property expression="get-property('axis2','HTTP_SC')" name="500reshttpsc"/>
</log>
</case>
<default>
<log description="faultlog" level="custom">
<property expression="$ctx:ERROR_CODE" name="faulterrorcode"/>
<property expression="$ctx:ERROR_MESSAGE" name="faulterrormessage"/>
<property expression="get-property('axis2','HTTP_SC')" name="faulthttpsc"/>
</log>
</default>
</switch>
<clone continueParent="true">
<target>
<sequence>
<sequence key="sendthemail"/>
</sequence>
</target>
</clone>
<send/>
</faultSequence>
</resource>
</api>
ALL CODE IS WORKING ANY STATUS CODE 200 OR 404 OR 500 etc ANY STATUS CODE SEND THE MAIL MY REQUIREMENT IS STATUS CODE !=200 REMAINING ANY STATUS CODE SEND THE MAIL PLEASE ANY ONE SUGGEST ME
Upvotes: 0
Views: 472
Reputation: 495
That's quite simple, below is the code.
<switch source="get-property('axis2','HTTP_SC')">
<case regex="200"><!-- Do not do anything here as it's success -->
<log description="200log" level="custom">
<property expression="$ctx:ERROR_CODE" name="200reserrorcode"/>
</log>
</case>
<default><!-- Put your logic here to send mail -->
<log description="reslog" level="custom">
<property expression="$ctx:ERROR_CODE" name="reserrorcode"/>
<property expression="$ctx:ERROR_MESSAGE" name="reserrormessage"/>
<property expression="get-property('axis2','HTTP_SC')" name="reshttpsc"/>
</log>
</default>
</switch>
Upvotes: 1