How to pass JSON in Open ESB

946 Views Asked by At

I am creating a simple OpenESB application. On left I have a rest inbound partner link and on the right I am calling a rest outbound partner link. I am trying to pass json to the service but openESB automatically parses it and converts it into XML.

So the question is how do I stop open esb from converting the json string into xml since the service doesn't accept xml input.

4

There are 4 best solutions below

2
On BEST ANSWER

OpenESB can process XML only.

For consume-types=[ "application/json" ] JSON input is automatically converted into XML for further processing and invoke any external partner links if required.

For produce-types=[ "application/json" ] XML data is converted into JSON by OpenESB.

To achieve the same your JSON has to be in a format that when converted to XML, produces valid XML. For example, {"name":äbc"} looks like <name>abc</name> when converted to XML.

JSON input like,

{
    "name1":äbc",
    "name2":äbc"
}

looks like

<name1>abc</name1>
<name2>abc</name2>

Now name1 and name2 XML elements does not have root element so OpenESB can not process it.

If you give JSON input as

{
     "someRootElement":{
         "name1":äbc",
         "name2":äbc"
      }
}

, converted XML would be like,

<someRootElement>
   <name1>abc</name1>
   <name2>abc</name2>
</someRootElement>

This should work in your case. :)

0
On

You can create your own component that will be simplest way to process json to xml, xml to json. let me know you if need more detail on this.

0
On

It seems that your open ESB application is configured to xml format and hence if you call json service it gets converted into xml. This link might be able to help you to implement JSON in ESB https://docs.wso2.com/display/ESB403/ESB+and+JSON.

0
On

If you have JSON in String you can pass it by setting its value into the following property of your variable.

        <copy>
             <from>'{"name" : "abc", "age" : "23"}'</from>
            <to variable="RestOutboundIn" part = "part1"/>
        </copy>
        <copy>
             <from variable="RestOutboundIn" part = "part1"/>
            <to variable="RestOutboundIn" sxnmp:nmProperty="org.glassfish.openesb.rest.entity"/>
        </copy>

NOTE: This property is not available in OpenESB bpel Editor. you will have to set its value through XML source.