Using JSON with Oracle Service Bus REST Services

I have recently posted 2 new samples for the Oracle Service Bus onto the Oracle Technical Network site. The first sample project is osb-205-SimpleREST and it shows how to fully implement a REST service using OSB. By "fully" I mean it shows how to implement the following HTTP verbs: GET, POST, PUT, DELETE, HEAD and OPTIONS using OSB.

I just finished posting another REST sample for OSB, this one is osb-206-JSONREST which shows you how to have OSB accept and reply with JSON messages. JSON (JavaScript Object Notation) is primarily used on web browsers. Providing XML to javascript clients is not the only way to communicate. JSON is often a preferred method of data exchange, especially with web developers because Javascript can easily parse a JSON object, whereas parsing an XML response requires more infrastructure on the client side.

Due to the nature of JSON, the osb-206-JSONREST sample really focuses on the GET and POST HTTP verbs (the ones easily executed from a web browser). With a little effort, you could easily create robust, production ready REST services thst are able to handle either XML or JSON payloads, depending on the Content-type HTTP header.

You can find all of the OSB samples at the SOA Suite sample site on OTN at: http://java.net/projects/oraclesoasuite11g/pages/OSB Just click on the OSB section on the left side of the page to see the OSB specific samples. The site also provides many samples for other components of the Oracle SOA Suite. It definitely worth a look.

Comments:

Hi Jeff,

I don't see the osb-206-JSONREST on the sample-code site. I only see the REST2REST related zip file.

Could you point me to the location of the osb-206-JSONREST archive please?

-Alen

Posted by Alen on July 17, 2011 at 08:05 PM PDT #

You can find the sample code for the JSONREST project here: https://www.samplecode.oracle.com/sf/go/page1498

Posted by Jeff Davies on July 18, 2011 at 01:52 AM PDT #

Respected Sir

i want to insert json data into oracle table using plsql procedure/function .if u have any related example plz send it on my mail.

thanks .

Anish Sahare

Posted by Anish on August 25, 2011 at 06:15 PM PDT #

Respected sir

I cannot able to see sample example .

Posted by Anish Sahare on October 14, 2011 at 04:56 PM PDT #

I downloaded the osb-206-JSONREST archive. But i didn't see the folders proxy, xquery, xsd mentioned in readme file.

Posted by Khanh on October 26, 2011 at 09:04 PM PDT #

The OSB samples has been moved to
http://java.net/projects/oraclesoasuite11g/pages/OSB

I have found a small glitch in the JSONREST sample. The http parameter expression should be as follows:
$inbound/ctx:transport/ctx:request/http:query-parameters/http:parameter[@name='id']/@value

Cheers.

Posted by Marek Kratky on July 17, 2012 at 11:33 AM PDT #

Anyone get a problem when running this example:
<Callout to java method "public static java.lang.String com.oracle.osb.samples.rest.json.JSONXMLConverter.xml2json(java.lang.String)" resulted in exception: null
java.lang.reflect.InvocationTargetException
Caused By: java.lang.NoClassDefFoundError: net/sf/json/xml/XMLSerializer

Is there a lib i have to add to the jars folder? Or should this be working.

Posted by James on June 21, 2013 at 03:09 PM PDT #

Hi Jeff,

We used your sample JSON project to convert my SOAP response to JSON response . But the JSON response also contains SOAP namespaces .

We just want the key value pairs in JSON response .
Can you please help us in removing these SOAP namespaces from JSON response .

Regards,
Neeraj

Posted by Neeraj on April 07, 2014 at 02:35 AM PDT #

The JSON Converter has no concept of namespaces, it just blindly converts the XML that you pass to it. You will need to remove the namespace in the XML before you convert it to JSON. Take a look at these links for some sample XQuery code that does exactly that:

http://en.wikibooks.org/wiki/XQuery/Filtering_Nodes#Removing_unwanted_namespaces
http://beatechnologies.wordpress.com/2008/09/25/stripping-namespace-from-an-xml-using-xquery/

- Jeff

Posted by Jeff Davies on April 07, 2014 at 09:07 AM PDT #

Post a Comment:
  • HTML Syntax: NOT allowed
About

A site for SOA thought and discussion.

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today