Tinker's thoughts~

About Blog GitHub

16 Sep 2015
Return 404 by default in WSO2 ESB

WSO2 ESB by default responds to requests with 202 HTTP status code behavior. This behavior can be specially nuisance when exposing APIs or Proxy services from the ESB. In this post I am explaining two changes to be done to change this behavior where a 404 HTTP status code is returned.

Main sequence change

In the ESB - there are 2 main sequences called main sequence and fault sequence. ESB invokes the main sequence if no matching API or Proxy service is found. If an error occurs inside a sequence and no fault sequence has been defined, the fault sequence is called. The 2 sequences are present in the /repository/deployment/server/synapse-configs/default/sequences.

We are going to change the main sequence to return 404.

main.xmllink
<sequence xmlns="http://ws.apache.org/ns/synapse" name="main">
<description>The main sequence for the message mediation</description>
<in>
<!-- Log all messages passing through -->
<log level="full"/>
<!-- Return 404 -->
<property name="HTTP_SC" value="404" scope="axis2"></property>
<respond/>
<drop></drop>
</in>
</sequence>

404 from APIs

APIs are special implementations in synapse that has couple of resources attached to it. API implementation of Synapse looks for a very specific sequence with the name - _resource_mismatch_handler_ to call when no resource inside the API is invoked from the request. Otherwise it returns 202 HTTP response. Due to this - we have to create the below sequence and deploy.

_resource_mismatch_handler_.xmllink
<!-- Exact sequence name as below should be there. This name is used inside the API implementation in Synapse -->
<sequence xmlns="http://ws.apache.org/ns/synapse" name="_resource_mismatch_handler_">
<log level="full"/>
<property name="HTTP_SC" value="404" scope="axis2"></property>
<respond/>
<drop></drop>
</sequence>

The historical reason of returning 202 lies back where the main sequence was shipped as a sample not as the default behavior of the WSO2 ESB product. It should be customized to suite the needs required. The same applies to resourcemismatchhandler sequence.


Till next time mate,
Dulitha at 16:46

About Blog GitHub