Reputation: 53
I'm trying to get familiar with WSO2 ESB 4.7.0. As simple test I'd like to convert JSON to XML using a proxy service. For now I have understood that the ESB converts JSON to XML implicitly. I created a simple mediation with the goal to write the converted XML message to a file. Unfortunatly the result of the JSON to XML conversion is empty (no data in file). Have I understand anything wrong regarding the JSON capabilities of WSO2 or is anything wrong with my mediation?
My mediation:
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse" name="MockJsonTest" transports="http https" startOnLoad="true" trace="disable">
<target>
<inSequence>
<property name="messageType" value="text/xml" scope="axis2" type="STRING"/>
<property name="ContentType" value="text/xml" scope="axis2" type="STRING"/>
<log level="full"/>
<property name="OUT_ONLY" value="true" scope="default" type="STRING"/>
<property name="transport.vfs.ReplyFileName" value="filename.xml" scope="transport" type="STRING"/>
<send>
<endpoint>
<address uri="vfs:file:///C:/wso2">
<timeout>
<duration>0</duration>
<responseAction>discard</responseAction>
</timeout>
</address>
</endpoint>
</send>
</inSequence>
<outSequence/>
<faultSequence/>
</target>
My curl client Post with the JSON data:
curl -v -H "Accept: application/json" -H "Content-type: application/json" -X POST -d '{"kind":"plus#person"}' http://mycomputer:8280/services/MockJsonTest
In axis2.xml I have tried both formatters for JSON:
<!--messageFormatter contentType="application/json"
class="org.apache.axis2.json.JSONMessageFormatter"/-->
<messageFormatter contentType="application/json"
class="org.apache.axis2.json.JSONStreamFormatter"/>
Kind regards,
Heiko
Upvotes: 1
Views: 1245
Reputation: 1598
I tested your scenario and I get the correct output as follows.
<kind>plus#person</kind>
Following is my proxy service.
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="MockJsonTest"
transports="https,http"
statistics="disable"
trace="disable"
startOnLoad="true">
<target>
<inSequence>
<property name="messageType" value="text/xml" scope="axis2" type="STRING"/>
<property name="ContentType" value="text/xml" scope="axis2" type="STRING"/>
<log level="full"/>
<property name="OUT_ONLY" value="true" scope="default" type="STRING"/>
<property name="transport.vfs.ReplyFileName"
value="filename.xml"
scope="transport"
type="STRING"/>
<send>
<endpoint>
<address uri="vfs:file:///home/user/test">
<timeout>
<duration>30000</duration>
<responseAction>discard</responseAction>
</timeout>
</address>
</endpoint>
</send>
</inSequence>
</target>
<description/>
</proxy>
It seems there's some small xml format errors in your proxy service. Compare it with the above. When you specify the proxy in source view, always click on 'switch to design view' at the end. Then it will alert you if there are any format errors.
I used the same curl command you provided. I have the default JSON message formatters and builders of ESB 4.7.0 in axis2.xml as follows.
<!--JSONBuilder Message Formatters-->
<messageFormatter contentType="application/json"
class="org.apache.axis2.json.JSONMessageFormatter"/>
<!--messageFormatter contentType="application/json"
class="org.apache.axis2.json.JSONStreamFormatter"/-->
<messageFormatter contentType="application/json/badgerfish"
class="org.apache.axis2.json.JSONBadgerfishMessageFormatter"/>
<messageFormatter contentType="text/javascript"
class="org.apache.axis2.json.JSONMessageFormatter"/>
Upvotes: 1