Monday, December 10, 2012

Experiment JSON with OSB


Honestly, I never used json, other than hearing about it all the time. I am creating a Rest service with OSB, my colleague would like me to send the response back as json. So game is on. After trial and error, here is how I did it.
1.      Create a proxy service, select “Message Service”.
2.      For request message Type, you have multiple choices. Select “XML”. (if you want post up free text, then select “Text”)
3.      For response message type, select “Text”
4.      For transport, select “http” protocol
5.      Keep the default for the rest
Message flow:
1.      Process input:
Pick up your input XML from $body. Here is a quick note on parsing the $body, say you have payload like this:
<soapenv:Body xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
  <foo xmlns="foo">
    <bar xmlns="bar">car</bar>
  </foo>
</soapenv:Body>

To get “car”, use this xpath: $body/f:foo/b:bar/text()
Send Json response back:
[
    {{
        "PREM_ID":"111111",
        "PREM_TYPE_CD":"HOUSE",
        "ADDRESS1":"2222 Cypress Ave",
        "CITY":"Mountain Mesa",
        "POSTAL":"12345",
        "DESCR":"House",
        "operationArea":"KRV",
        "district":"MMS",
        "isMultiple":"N",
        "allowSelfService":"Y",
        "needAppointment":"N"
    }}
]

The only special thing I did was to escape “{“ with “{{“, and “}” with “}}”.
That’s it.



No comments:

Post a Comment