Pedro Ivo Dantas
Pedro Ivo Dantas

Reputation: 67

capturing endpoint timeout in WSO2 EI 6.2

I have an API in EI 6.2 that calls a backend endpoint. Sometimes this EP is offline, and therefore the call timeouts. I want to capture this timeout and encapsulate it in a customized response before sending it back to the client. The idea seems simple enough, but I'm having a hard time implementing it. I've tried adding the following section to the EP declaration. As I understand it, the action=fault property should make the EP raise a fault when the request timeouts (and therefore be caught by the fault handler sequence) but that is not happening. Anyone has any suggestion on how to handle this situation?

Thanks.

Pedro

My EP:

<?xml version="1.0" encoding="UTF-8"?>
<endpoint name="wacs_parameters.endpoint" xmlns="http://ws.apache.org/ns/synapse">
    <loadbalance algorithm="org.apache.synapse.endpoints.algorithms.RoundRobin">
        <endpoint name="WACS_CpeGm_Parameters_Master">
            <http method="GET" uri-template="http://xpto
                <suspendOnFailure>
                    <initialDuration>-1</initialDuration>
                    <progressionFactor>1.0</progressionFactor>
                </suspendOnFailure>
                <markForSuspension>
                    <retriesBeforeSuspension>0</retriesBeforeSuspension>
                </markForSuspension>
                <timeout>
                    <duration>3000</duration>
                    <action>fault</action>
                </timeout>
            </http>
        </endpoint>
    </loadbalance>
    <description/>
</endpoint>

And this is the log from the request, edited for clarity:

[2020-02-26 16:38:33,962] [EI-Core]  WARN - TimeoutHandler Expiring message ID : urn:uuid:8b9c9632-ef0b-423d-9827-84eee517b75d; dropping message after ENDPOINT_TIMEOUT of : 3 seconds for Endpoint [WACS_CpeGm_Parameters_Master], URI : xpto, Received through API : ClientEquipmentsAPI
[2020-02-26 16:38:41,318] [EI-Core]  WARN - ConnectCallback Connection refused or failed for : /10.217.49.10:8280
[2020-02-26 16:38:41,318] [EI-Core]  WARN - SynapseCallbackReceiver Synapse received a response for the request with message Id : urn:uuid:8b9c9632-ef0b-423d-9827-84eee517b75d But a callback is not registered (anymore) to process this response
[2020-02-26 16:40:33,967] [EI-Core]  WARN - TimeoutHandler Expiring message ID : urn:uuid:2a928d56-cf7f-4950-a5f4-8033798e205e; dropping message after GLOBAL_TIMEOUT of : 120 seconds for Endpoint [API_ClientEquipments_Endpoint_Master], URI : xpto, Received through API : ClientEquipmentsAPI
[2020-02-26 16:41:20,394] [EI-Core]  INFO - SourceHandler Writer null when calling informWriterError
[2020-02-26 16:41:20,394] [EI-Core]  WARN - SourceHandler Connection time out after request is read: http-incoming-10 Socket Timeout : 180000 Remote Address : /127.0.0.1:53092
[2020-02-26 16:41:20,408] [EI-Core]  INFO - SourceHandler Writer null when calling informWriterError
[2020-02-26 16:41:20,408] [EI-Core]  WARN - TargetHandler Connection time out after while in state : REQUEST_DONE Socket Timeout : 180000 Remote Address : localhost/127.0.0.1:8280
[2020-02-26 16:41:20,408] [EI-Core]  WARN - SourceHandler Connection time out after request is read: http-incoming-11 Socket Timeout : 180000 Remote Address : /127.0.0.1:53093
[2020-02-26 16:41:20,409] [EI-Core]  WARN - SynapseCallbackReceiver Synapse received a response for the request with message Id : urn:uuid:2a928d56-cf7f-4950-a5f4-8033798e205e But a callback is not registered (anymore) to process this response

Upvotes: 1

Views: 1143

Answers (1)

Pedro Ivo Dantas
Pedro Ivo Dantas

Reputation: 67

So, just to inform others that might have the same problem: when an endpoint timeouts, EI activate the fault sequence. There you can catch the fault and treat it properly. The property ERROR_MESSAGE details the kind of error, as explained here

https://docs.wso2.com/display/EI640/Error+Handling

This example sequence catches timeouts and returns a customized error code (with HTTP 502):

<?xml version="1.0" encoding="UTF-8"?>
<sequence name="faultSequence_ClientEquipmentsAPI" trace="disable" xmlns="http://ws.apache.org/ns/synapse">
    <switch source="get-property('ERROR_CODE')">
        <case regex="101503|101504">
            <call-template target="faultTemplate_clientEquipmentsAPI">
                <with-param name="res_messageCode" value="801"/>
                <with-param name="res_message" value="Timeout waiting answer of backend system"/>
            </call-template>
            <property name="HTTP_SC" scope="axis2" type="STRING" value="502"/>
            <respond/>
        </case>
   </switch>
</sequence>

Upvotes: 1

Related Questions