OSB-12c : JSON Message Type
JSON (JavaScript Object
Notation) is a lightweight data-interchange format. It is easy for humans to
read and write.
We can use RESTful services in
order to read JSON files.
In below example a sample REST
service is created in OSB-12c and this service takes input and return response
in JSON format.
·
Create REST
adapter to take input.
Create sample HTTP
based REST service and add some logic in it.
Create new folder inside MessageType_Service
File -> New -> Folder -> JSON_MessageTypeServices
Create sub folders as mentioned below
Create few more extra folders like WSDL,WADL,XSDs inside Resources
Create a REST based adapter in design view
Design View (right click on Proxy Service Module) -> REST
Specify proper name for REST binding
Add a method. Let Method name be as
‘ExecuteRest’.
Click on radio button of ‘JSON’ and
‘XML’.
This indicates that input to REST
adapter can be in format of JSON or XML.
Specify HTTP verb as GET and Response as JSON
HTTP Verb: GET
Response Type: JSON
Cross check whether all configurations are done and click on ‘Finish’ button.
Method: ExecuteRest
Resource Path: /
HTTP Verb: GET
Complete: yes
Once REST adapter configuration is done, we can see error in SampleRestProxy(This proxy will get created during configuration of REST adapter).
This is expected as we have not targeted any of other resources like BusinessService or ProxyServices to this proxy.
Create new pipeline with help of WADL which is got created while creation of REST adapter and add some logic to it.
Service Name: RestServicePipeline
Service Type: REST
Uncheck radio button for ‘Expose as
proxy service’.
Select the WADL ‘SampleRestService.wadl’ which is
got created while creation of REST adapter.
Add pipeline pair and request and response stages in ‘RestServicePipeline.pipeline’
Add a assign activity and include
some logic into it.
In this example value of
user-metadata from $inbound is concatenated with string ‘Value of ID:’
concat (‘Value of ID :’
,$inbound/ctx:transport/ctx:request/tp:user-metadata/@value)
And assign this to a variable called
‘AssignedRequest’.
Create new nXSD schema which is used to convert XML to JSON.
Resources -> XSDs (Right Click) -> New -> nXSD schema
A pop-up window of Native Format builder will
open
Specify proper name for nXSD schema
Name: XMLtoJSON.xsd
Choose type as ‘JSON Interchange Format’
Specify sample structure of JSON
{
“Response” : “Value of ID =”
}
When we click on next we can see xsd structure
for JSON.
Click on Finish button to complete Native Builder
format activity.
You can locate XMLtoJSON.xsd got created inside
‘XSDs’ folder.
Add a nXSD translate activity to convert XML to native (JSON) format.
Right Click in response pipeline -> Insert Into -> nXSD translate
Specify below values in nXSD
translate activity
Translate: XML to native
Input: Add some logic like mentioned
below
<Root-Element
xmlns="http://TargetNamespace.com/ServiceName">
<Response>{$AssignedRequest}</Response>
</Root-Element>
nXSD schema: Select XMLtoJSON.xsd
schema (nXSD schema)
Output: contents of body
Deploy the service into local standalone weblogic server.
We can see deployed services in sbconsole
Run RestService
Pass value of ID
Accept: application/json
ID : <Some value>
Hit Execute button.
We can see that response is in JSON format.



































hi tapan,
ReplyDeletenice blog.
I tried all the steps as is it, but i am not getting proper output.
I am receiving : "binary-content": { "@ref": "cid:2c1372d4:16:1616feda21c:N8000" }
in response.
Kindly suggest me for the same.
Thanks & Regards
Mala.
I am facing the same issue while sending request.... nXSDTranslate convert the XML to binary data but i need the JSON readable format.
DeleteI am facing the same issue while sending request.... nXSDTranslate convert the XML to binary data but i need the JSON readable format.Need help on this
DeleteI am facing the same issue , please suggest the known solution .
ReplyDeleteYou can use binarytoTextConvert for the same
Deletehi tapan,
ReplyDeletehow do I do it vice versa json to xml
Hi Tapan I am also getting same issue
ReplyDeleteHi, I present the same problem, is there any solution?
ReplyDeleteIm also facing same issue.Any solution yet,please let me know/
ReplyDeleteIs it possible to read Json schema and validate and write Json schema using OSB
ReplyDeleteThe requirement is Read Json schema in Source side,Pull Old jsoc schema at target side compare the fields if they are matching,If matching it will initiate successful API call,If not matching it will initiate failure API call,Can this be achieved using OSB
ReplyDeleteuse utf-8 option instead of us ascii as encoding in your nxsd or u can use binary to text function.
ReplyDeleteHi James, Thanks for such encouraging words. In deed your site looks informative. Thanks for sharing. Lets keep up the good work.
ReplyDeleteHi I have a scenario where multiple xml messages are coming inbound. So I defined separate nxsd schemas for each message. But quite not sure of how to use the dynamic expression in nxsd translate. Can someone suggest on dynamic expression usage in nxsd translate. Could not find the syntax in Oracle docs as well Thanks
ReplyDelete