codepuppet
codepuppet

Reputation: 55

wso2 ESB oauthService fault handling

I have a simple pass-thru API defined that includes the oauthService to validate an access token. Similar to this:

<api xmlns="http://ws.apache.org/ns/synapse" name="aservice" context="/aservice/v1">
    <resource methods="POST PUT GET" uri-template="/*" faultSequence="ServiceFault">
        <inSequence>
            <oauthService remoteServiceUrl="https://identityserver:9444/services/" username="admin" password="admin" description="oauth2"/>
            <send>
                <endpoint name="aservice-endpoint">
                    <address uri="http://aservice:8080/aservice/v1"/>
                </endpoint>
            </send>
        </inSequence>
        <outSequence>
            <send/>
        </outSequence>
    </resource>
</api>

It includes a ServiceFault sends a general message back to the client.

My question is, is it possible to have a separate fault handler that will handle validation errors from the oauthService? I'd also like to handle errors from the address endpoint as well (i.e. host down, etc). Call all of these be handled in one fault sequence definition?

I want to be able to set different HTTP response codes and headers depending on if the error is an oauth2 error or some other error type.

Upvotes: 1

Views: 182

Answers (1)

Philipp
Philipp

Reputation: 4729

There is a way you can achieve it by using separate sequences. You could put the oauthService to a separate sequence which then has its own faultSequence in the tag onError:

<api xmlns="http://ws.apache.org/ns/synapse" name="aservice" context="/aservice/v1">
<resource methods="POST PUT GET" uri-template="/*" faultSequence="ServiceFault">
    <inSequence>
        <sequence key="oauthSequence"/>
        <send>
            <endpoint name="aservice-endpoint">
                <address uri="http://aservice:8080/aservice/v1"/>
            </endpoint>
        </send>
    </inSequence>
    <outSequence>
        <send/>
    </outSequence>
</resource>
</api>

<sequence xmlns="http://ws.apache.org/ns/synapse" name="oauthSequence" onError="myOauthFaultSequence">
   <oauthService remoteServiceUrl="https://identityserver:9444/services/" username="admin" password="admin" description="oauth2"/>
</sequence>

See the onError description of the Sequence: https://docs.wso2.com/display/ESB481/Mediation+Sequences

Upvotes: 1

Related Questions