This would seem like a pretty common thing to do, but I am having trouble figuring out how to make it work. I wrote a custom filter for a request-response flow that has an inbound http endpoint. The custom filter checks if certain required query parameters are present and contain valid values. If the filter rejects a message, I would like to return an HTTP error status code, but I cannot figure out how to send a different response.
The Mule docs say:
If the inbound endpoint defined on a Flow has a request-response
exchange-pattern and there are no response blocks in your flow then
the response used is simply the result from the last Message Processor
in the flow, which will be null.
I am not sure if this is entirely accurate. My flow does have a <response> block, but it is not getting called if my custom filter returns false.
What is the best way to return a different response if the filter rejects a message?
Here is an example of my flow:
<flow name="Incoming_requests">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" path="incoming" />
<http:body-to-parameter-map-transformer />
<custom-filter class="com.mycompany.MyQueryParamFilter"/>
<!-- Process valid messages here -->
<response>
<!-- Return a successful response -->
</response>
</flow>
EDIT: Here is are the docs that inferred that <response> blocks would be executed.
http://www.mulesoft.org/documentation/display/MULE3USER/Using+Filters#UsingFilters-UsinginFlows
Using a choice router would be better in your case:
No
responseelements are necessary if thechoiceis at the end of theflow.