I am trying to add some logic in the WSO2 ESB that will attempt to call a service as normal and return the response, but if for whatever reason there is a problem with the service I would like to check another service to see if it is down due to maintenance and then show the error message accordingly.
I tried using a fault sequence added to the proxy target. And with in this sequence I make a send call to a servlet, but it errors out saying that the response is not JSON which I know it is because it is hard coded.
Is this the correct way of doing this? What is the correct way of achieving this functionality?
Here is the servlet that will return an error code or message, currently it is hard coded:
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
System.out.println("hit the servlet.......");
response.setContentType("application/json");
response.getWriter().append("{\"result\": \"1234\"}");
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
}
Here is the Proxy:
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse" name="mjstest" transports="https http" startOnLoad="true" trace="disable">
<target faultSequence="json_fault_handler">
<inSequence>
<log level="full"/>
<property name="messageType" value="application/json" scope="axis2" type="STRING"/>
<log level="full" category="TRACE"/>
<send>
<endpoint>
<address uri="http://10.180.63.195:9088/rest/badServiceThatWillFailForThisTest" format="rest">
<timeout>
<duration>30000</duration>
<responseAction>fault</responseAction>
</timeout>
<suspendOnFailure>
<errorCodes>-1</errorCodes>
<initialDuration>0</initialDuration>
<progressionFactor>1.0</progressionFactor>
<maximumDuration>0</maximumDuration>
</suspendOnFailure>
<markForSuspension>
<errorCodes>-1</errorCodes>
</markForSuspension>
</address>
</endpoint>
</send>
</inSequence>
<outSequence>
<log level="full" separator=","/>
<send/>
</outSequence>
</target>
Here is the sequence:
<sequence xmlns="http://ws.apache.org/ns/synapse" name="json_fault_handler">
<log category="INFO" level="custom" separator=",">
<property name="failS" value="=======False Sequence==========="/>
</log>
<send>
<endpoint>
<address uri="http://localhost:8080/UGC_Images/BACMaintananceWindow" ></address>
</endpoint>
</send>
<property name="messageType" value="application/json" scope="axis2"></property>
Any help is greatly appreciated.