wso2 - Will JSON based REST - ESB - REST communication build AXIS 2 XML MessageContext -
i have use-case end end json based rest services i.e. rest client -> esb -> rest service (all on jsons) planning handle using apis & payload factory transformations
in scenario, wso2 esb convert json xml before invoking target rest service?
if no #1, how prepare messagecontext object looks having xml constrcuts soapenvevelope, body etc.?
update 1 : further clarify question, have updated 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 custom mediator 44 $$" + context.getenvelope().getbody() +"$$"); return true; } }
console output
in custom mediator 44 $$<soapenv:body xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope"/>$$ in custom mediator 44 $$<soapenv:body xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope"/>$$
i getting proper response when invoking api, printed body of message context not having content. json message being stored in messagecontext?
update 2 builder , formatter configuration in axis2.xml 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 available @ http://www.pastebin.ca/3038336 have set application/json content type in request esb api.
thanks, harish
internally of rest api automatically have content in xml. when accessing api rest data, automatically transformed xml.
then can use payload factory mediator change content. response automatically again transformed json.
and need. no "conversion" side necessary. please create specific rest api , post here in case of effective issue.
Comments
Post a Comment