Reputation: 3
I have created and deployed a java service for wso2. I need to create a sequence in WSO2 that will do failover to another endpoint in case a certain fault response is given by the java service. I would like to use the endpoint features "suspendOnFailure" and "markForSuspension" for certain error codes but I did not find a way to throw a certain error code from the Java service.
Is there any way I can throw an error code in java that will be interpreted by the endpoint in order to mark it as "suspended for failure" for a certain period of time ?
I tried using a makefault mediator, but I don't know how to throw an error with an error code from this(or other) mediator that can be interpreted later in "suspendOnFailure".
Below I tried to use the PGWFAULT service to always send a fault with an error code that will be interpreted by "suspendOnFailure". It doesn't work that way...
<proxy name="CommandClientService" transports="https http" startOnLoad="true"
trace="enable">
<description/>
<target>
<endpoint name="FaultyOne">
<address uri="http://localhost:8282/services/PGWFAULT">
<suspendOnFailure>
<errorCodes>101500</errorCodes>
<initialDuration>1</initialDuration>
<progressionFactor>1.0</progressionFactor>
<maximumDuration>1</maximumDuration>
</suspendOnFailure>
<markForSuspension>
<errorCodes>101500</errorCodes>
<retriesBeforeSuspension>20</retriesBeforeSuspension>
<retryDelay>1</retryDelay>
</markForSuspension>
</address>
</endpoint>
<faultSequence>
<log level="full">
<property name="text" value="Fault sequence activatesNOW"/>
<property name="message" expression="get-property('ERROR_MESSAGE')"/>
</log>
<send>
<endpoint key="errorProvider"/>
</send>
</faultSequence>
</target>
</proxy>
<proxy name="PGWFAULT" transports="https http" startOnLoad="true" trace="enable">
<description/>
<target>
<endpoint key="Local"/>
<outSequence>
<makefault version="soap12">
<code xmlns:soap12Env="http://www.w3.org/2003/05/soap-envelope"
value="soap12Env:Receiver"/>
<reason value="101500"/>
<node/>
<role>asdcasdf</role>
<detail>a fault to be taken into account</detail>
</makefault>
<send/>
</outSequence>
</target>
</proxy>
Upvotes: 0
Views: 1247
Reputation: 5946
Error codes referenced into endpoint definition for suspension are based on http error codes
You can set such an error code in your mediation like that :
<property name="HTTP_SC" value="500" scope="axis2"/>
For a list of error codes in Endpoint Error Handling, see http://docs.wso2.org/display/ESB480/Endpoint+Error+Handling
I think you will easily find how to set it in java...
For exemple on a HttpServletResponse object :
response.sendError(response.SC_NOT_FOUND, "No XXX specified.");
Upvotes: 1