Synapse handler is similar to axis2 handler , that can be used in RESTAPIs to handle incoming request and the responses.
Sample handler ;
Handler has to be registered in the RESTAPI configuration.
Sample configuration;
Sample handler ;
package test;
import org.apache.synapse.MessageContext;
import org.apache.synapse.rest.AbstractHandler;
public class TestSynapseHandler extends AbstractHandler {
@Override
public boolean handleRequest(MessageContext messageContext) {
String idKey = "idKey";
String idValue = "abc";
messageContext.setProperty(idKey, idValue);
return true;
}
@Override
public boolean handleResponse(MessageContext messageContext) {
// TODO Response handling
return true;
}
}
Handler has to be registered in the RESTAPI configuration.
Sample configuration;
<api xmlns="http://ws.apache.org/ns/synapse" name="calAPI" context="/cal">
<resource methods="GET">
<nSequence>
<send>
<endpoint>
<address uri="http://localhost:9763/services/calservice"/>
</endpoint>
</send>
</inSequence>
<outSequence>
<send>
<endpoint>
<default/>
</endpoint>
</send>
</outSequence>
</resource>
<handlers>
< handler class="test.TestSynapseHandler"/>
</handlers>
</api>
<resource methods="GET">
<nSequence>
<send>
<endpoint>
<address uri="http://localhost:9763/services/calservice"/>
</endpoint>
</send>
</inSequence>
<outSequence>
<send>
<endpoint>
<default/>
</endpoint>
</send>
</outSequence>
</resource>
<handlers>
< handler class="test.TestSynapseHandler"/>
</handlers>
</api>