Please refer Consume OData using SOA 11g post for SOA 11g version.
As part of this post, we will see how to consume JSON based OData Service using SOA 12c.
OData
OData (Open Data Protocol), promoted by Microsoft, now an OASIS Standard, helps service providers to expose their data using RESTful APIs. OData supports, exposing of data in two Formats, Atom and JSON. Please refer OData WebSite for information about OData.
Public OData Services
One of the publicly available OData Service can be accessed at Public OData Service
URI Notations
Let us create a SOA 12c composite to consume the service for the following scenarios.
Following are the URI notations for
- List All Categories in JSON Format
- Filter and display Categories
- Display Category by Primary Key
Consume using REST Adapter
Let us create a SOA Application. Add a REST adapter to refer to Public ODATA Service.
- Add a Reference
- Configure Base URI as http://services.odata.org/V3/OData/OData.svc
- Configure Resource for Categories
- Add Method and query parameters
- Configured Reference Details
For the sake of simplicity, let us hard code values for OData Service Parameters like format and filter, inside the composite. Create BPEL Component (Synchronous, default values for rest of options).
Wire BPEL Component to OData Reference.
Inside BPEL, add variables for Input and Output
Add an invoke activity to ODATA Partner link.
Add an assign activity before the reply activity to copy from OData Service output to Output variable
Test Scenario 1 – List all categories in JSON Format.
Configure “Properties” in invoke to add value for “$format”. Providing value ‘json’ will make ODATA service to return data in JSON format. Otherwise it will return in Atom Format. Refer “URI Notations” section for the format of URIs.
Deploy and test the composite. As values are hard coded inside BPEL, give random string for composite input during testing. Composite should list all categories in JSON format.
Test Scenario 2 – Filter Categories with Name as Food.
Let us modify the composite to filter the results using $filter query parameter. Let us get Category with “Name” as Food”. “Name” is one of the property of “Category”. ODATA URI Notation for this scenario is
http://<base-uri>/Categories?$format=json&&$filter=Name eq 'Food'
Edit Invoke Activity to specify value for “$filter” query parameter
Deploy and test the composite. Result should show Category with Name “Food”.
Test Scenario 3 – Display Category using Primary Key
OData Protocol allows to list entities by primary key values using the notation
http://<base-uri>/entity(<keyvalue>).
“ID” field is the primary key in “Categories” entity. To list Category refered by ID 1, URI notation is
http://services.odata.org/V3/OData/OData.svc/Categories(1)?$format=json
To be able to query using this format , we need to build the URI dynamically and assign it to “rest.binding.requestURI” property of Invoke activity.
Already Configured “query” parameters will be ignored and only value of “rest.binding.requestURI” will be executed against REST Service. In our case, $format is needed. So, we will add it as part of the value that is assigned to “rest.binding.requestURI” property.
Deploy and test the composite. Category with ID=1 will be shown in the result.
With SOA 12c’s REST adapter we should be able to call OData Services successfully. If there is any use case for which REST adapter is not compatible, we can consider using Java Libraries for OData listed in Java Libraries for OData . Please refer this post which shows usage of OData4j library in SOA 11g environment.
hello,
could you please tell me the version of SOA you are using? I’m using 12.1.3 and have trouble setting the query parameters with $expand . It is throwing XML validation error as $ is not accepted for XML element names. Could you please advise on this issue?
Appreciate if you could share some sample code.
thanks
Maneesha M
It was with 12.2.1. Are you getting same kind of screens in 12.1.3?. If I could find the sample project , I will send it to your email.
Hi Krishna,
Do you mind sending me the sample project? Thank you!
—
Dilip
Hi Dilip,
Sorry, I don’t seem to have the sample project. Please try it in a 12.2.1 version.
Hi Krishna,
In 12.2.1.2, your steps worked like a charm! Thank you for sharing this blog!
Hi Maneesha,
I’m also unable to resolve the issue in 12.1.3 with query string parameter containing a $ in the name. Did you find a workaround or did you use 12.2.1?
Thank you.
—
Dilip
Hi Krishna,
I followed same steps for PUT operation in 12.2.1 oracle vm.
Request is getting submitted properly to the target system and data is being updated but I am getting “501 not implemented” error in BPEL where I am invoking this service.
any pointers to tackle this situation.
– Harshal
Hi Harshal
Based on the error, 501, I guess “PUT” method is not implemented on the target system . Please try different target system which supports PUT method.
How does ODataSVC_IP work?
It goes as null and invoke fails. Isnt that the case with everyone?
I mean how does empty input variable to invoke work?
Can someone please respond?
Hi Krishna,
I am using OSB 12.2.1.2 version and trouble setting the query parameters with $.
Rest Adapter wizard doesn’t show RunTime Properties
i.e
rest.query.$filter
rest.query.$format
Is there any patch required or any steps needs to be followed to make this property visible.
Regards
Manish
The blog is about SOA and not OSB. Although you design this in the same JDeveloper, the options for SOA are different than OSB Rest Reference!
It is quite interesting that Warren Buffet owns 10% with the Chinese Greely electric
and hybrid car company, and he is attempting to purchase really it.
Some with the drawbacks of those systems is that it isn’t necessarily dependable.
Around $117 billion was committed to projects emphasizing alternative energy like wind,
biofuel, solar and geothermal.
As part of this post, let us implement a simple REST service to demonstrate this new feature – End to End JSON with Javascript.