Usage of a Respond Mediator in WSO2 ESB


In a situation like you want to send a message back to the client depending on some conditions, we can use Respond Mediator. This mediator stops the processing on the current message and sends the message back to the client as a response. So just before this mediator we can use mediator like Payload Factory Mediator to construct the response.

Following is a simple use case for this,

<filter source="json-eval($.request.method)" regex="checkin">
<then>
<payloadFactory media-type="json">
<format>{"message":"Message to be sent A"}</format>
<args></args>
</payloadFactory>
</then>
<else>
<payloadFactory media-type="json">
<format>{"message":"Message to be sent B"}</format>
<args></args>
</payloadFactory>
<respond></respond>
</else>
</filter>
Advertisements