I have a use-case for end to end JSON based REST services i.e. REST Client -> ESB -> Rest Service (all on JSONs) which I am planning to handle using APIs & PayLoad factory for transformations
In this scenario, will WSO2 ESB convert JSON into XML before invoking the target Rest Service?
If no for #1, then how will it prepare MessageContext object which looks having all XML constrcuts like SOAPEnvevelope, Body etc.?
Update 1 : To further clarify my question, I have updated this my sample API & custom Mediator
api/TestRestAPI.xml
<api xmlns="http://ws.apache.org/ns/synapse"
name="TestRestAPI"
context="/testrest">
<resource methods="POST GET">
<inSequence>
<class name="com.example.wso2.esb.mediators.custom.MyCustomerMediator"/>
<send>
<endpoint>
<address uri="http://jsonplaceholder.typicode.com/posts"/>
</endpoint>
</send>
</inSequence>
<outSequence>
<class name="com.example.wso2.esb.mediators.custom.MyCustomerMediator"/>
<send/>
</outSequence>
</resource>
</api>
Custom Mediator Class
public class MyCustomerMediator extends AbstractMediator {
public boolean mediate(MessageContext context) {
System.out.println("In My Custom Mediator 44 $$" + context.getEnvelope().getBody() +"$$");
return true;
}
}
Console Output
In My Custom Mediator 44 $$<soapenv:Body
xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope"/>$$
In My Custom Mediator 44 $$<soapenv:Body
xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope"/>$$
I am getting proper response when invoking the API, however the printed Body of message context is not having any content. So where is the JSON message being stored in MessageContext?
Update 2 My builder and formatter configuration in axis2.xml which were actually default in WSO2 ESB 4.9.0 SNAPSHOT
<!--JSON Message Formatters-->
<messageFormatter contentType="application/json"
class="org.apache.synapse.commons.json.JsonStreamFormatter"/>
<!--JSON Message Builders-->
<messageBuilder contentType="application/json"
class="org.apache.synapse.commons.json.JsonStreamBuilder"/>
The complete configuration file is available @ http://www.pastebin.ca/3038336 I have set application/json as the content type in the request to ESB API.
Thanks, Harish