Wednesday, July 4, 2012

Sending a Dummy Response from WSO2 ESB

When you play with WSO2 ESB, you might need to send some dummy data as the response of a proxy service or an REST API. In order to do that you will need to specify To, RESPONSE and NO_ENTITY_BODY properties in the inSequence. If the sequence doesn't get called via an HTTP GET, then the property NO_ENTITY_BODY can be removed from the sequence.

Then, the sequence will directly send the response to the client even without going through the outSequence. Using either Enrich or Payload Factory mediator, you can create the response massage manually.

Following is a sample inSequence.
<inSequence>
    <header name="To" action="remove"/>
    <property name="RESPONSE" value="true"/>
    <property name="NO_ENTITY_BODY" scope="axis2" action="remove"/>
    <payloadFactory>
        <format>
            <ns:getQuoteResponse xmlns:ns="http://services.samples">
                <ns:return xmlns:ax21="http://services.samples/xsd">
                    <ax21:change>4.212070096051944</ax21:change>
                    <ax21:earnings>-9.567415587431361</ax21:earnings>
                    <ax21:high>-148.1740146577308</ax21:high>
                    <ax21:symbol>IBM</ax21:symbol>
                </ns:return>
            </ns:getQuoteResponse>
        </format>
    </payloadFactory>
    <send/>
</inSequence>

No comments:

Post a Comment