Monday, May 16, 2016

How to change API Managers authentication failure message to message default content type.


The error response format sent from WSO2 gateway is usually in xml format. Also if need we can change this behavior. To do this we have extension point to customize message error generation. For auth failures throttling failures we have handler to generate messages.

For auth failures following will be used.
/repository/deployment/server/synapse-configs/default/sequences/_auth_failure_handler.xml

The handler can be updated to dynamically use the content Type to return the correct response.
Once you changed it will work for XML and JSON calls.

Change the file to add a dynamic lookup of the message contentType i.e,
From

<sequence name="auth_failure_handler" xmlns="http://ws.apache.org/ns/synapse">

<property name="error_message_type" value="application/json"/>
<sequence key="cors_request_handler"/>
</sequence>

To
<sequence name="auth_failure_handler" xmlns="http://ws.apache.org/ns/synapse">

<property name="error_message_type" value="get-property('transport', 'Content-Type')"/>
<sequence key="cors_request_handler"/>
</sequence>


No comments:

Post a Comment