Saturday, September 23, 2017

Oracle Service Bus 12c provide the feature to handle JSON messages inside pipeline, although this feature was not there in first version of 12c but later version provides full JSON support. In this post, I will show how to handle JSON message inside pipeline. JavaScript is new action introduced inside message flow that help us to read/write and manipulate JSON messages.

Let’s start with this sample. I will show how to read below JSON message inside pipeline using JavaScript action and how to generate below JSON response using JavaScript action.

Request JSON

{ “inputVal" : "world" }

Response JSON

{ "result":  "Hello world" }

First of all, create new OSB project under OSB application. Now create Rest proxy service that accept JSON message and send JSON as response, to do that right click and choose "REST" option and provide proxy name. In next screen you need to provide resource path for this rest proxy.

OSB 12c JavaScript Action Create Proxy

OSB 12c JavaScript Action Proxy Resource Path

Now click on "Add a new Rest Method" option. Provide method name in next screen and choose "POST: method. Also choose "JSON" option for both request and response as we are dealing with JSON message here.

OSB 12c JavaScript Action Proxy add rest method

OSB 12c JavaScript Action Proxy Request and Response
 Add Pipeline where service type is REST and choose the proxy WADL file for the same. Ensure that expose as proxy option is unchecked.

OSB 12c JavaScript Action PipeLine

Link pipeline with proxy service. Inside pipeline, add pipeline node and first in request pipeline add one JavaScript action. Open the JavaScript action and click on Value expression.

In Expression, add below text.

var $request = process.body
process.response= "Hello " + $request.inputVal

Here $request is variable and process.body contains the request JSON data so I assign request JSON to request variable.

imputVal is the element name that we receive in request so to access that I used $request.inputVal expression and "Hello " is appended to that and assigned to process.response.

OSB 12c JavaScript Action

OSB12c JavaScript Action Expression

Now add another JavaScript action in response pipeline to create response JSON, click on Value expression and add below text.

"result" : process.response

OSB 12c JavaScript Action Response

Test the flow by using the request JSON and you see the response JSON as shown below.

OSB12c JavaScript Action Testing


Post a Comment