Friday, 6 January 2017

REST service in Oracle Service Bus

In this blog, I'm gonna to write a very basic example on the Oracle Service Bus 12.1.3.

After this blog, you should have learned to:

1) How to create SB(Service Bus) application with SB project
2) How to create simple REST service
3) Understanding of some basis components involved in the example
4) How to run and test REST service.

To complete this example, you must have Jdeveloper 12.1.3 installed on you computer with the integrated weblogic.

Let's get started.

Below are step by step procedure how to createe REST service and provide response in XML/JSON both:

1) Go to File -> New -> From Gallery -> Application-> Service Bus Application with Service Bus Project:


2) Enter Application Name : RestServiceApplication and click Next


3) Enter Project name RestServiceProject and click Finish.


4) Create the folder structure like below.


5) Create a schema called Rest.xsd under Schemas folder with below structure. The is very simple schema definition that will be used during REST adapter.

6) Double click on the RestServiceProject composite

7) Right click on the Proxy service swim lane and select REST adapter. REST adapter is used to create REST service.




8) Click on the + sign in the Operation Bindings section and click Add operation binding. This will allow us to create REST service operation.




9) Select GET  from HTTP verb drop down as we are gonna to create simple GET operation

10) Click browse for schema file icon and select input element of  Rest.xsd schema


11) Click on the Response tab. Select XML and JSON if you need output in both format. Click on the browse for schema file icon and select output element of the Rest.xsd schema


12) Click OK twice

13) Right Click on the middle swim lane of the composite and select Insert -> Pipeline. 




14) Select WSDL radio button and click Browse WSDLs icon and select RestService.wsdl. Uncheck Expose as a proxy service and click Finish



15) Wire RestService and RestPipeLine together.



16) Double click on the RestPipeline and drop Pipeline pair node from the component pallet.

17) Drop Replace activity from component pallet in the Response pipeline



18) Select Replace activity and enter the expression as below:


Value expression:

<output>
<greeting>
{fn:concat("Hello ", $body/exam:input/exam:name)}
</greeting>
</output>

19) Composite will look like.


Service has been completed. It's time to test the service.

20 ) Right click on RestService and click Run



21) Enter name and click Execute button, you will see the output in XML format.




23) Go back and select application/json from Accept drop down to get response in json format.



24) Click Execute



So we have completed a very basic example of Service Bus.

More helpful example:


REST Service with DB adapter Oracle Service Bus


Consume REST service in Oracle Service Bus


Poll database using DB adapter in Oracle Service Bus


Secure REST service in Oracle Service Bus using OWSM(Oracle Webservcie Manager)



5 comments:

  1. Hi,
    Sir your blogs is very helpful for learner..Thank you so much...

    ReplyDelete
  2. Hi Ankur,

    Thanks for sharing... I have some issues while implementing above service...

    1. I have followed same steps as you showed in this blog. I am able to get response in xml format. But when i am excepting response in json format, OSB is throwing below error.


    The invocation resulted in an error: .
    { "errorMessage" : "Translation Failure.
    Failed to translate XML to JSON. Cannot write start element: Output
    The data does not conform to the NXSD schema. Please correct the problem.
    ", "errorCode" : "OSB-382000" }


    Please assist me with this issue

    ReplyDelete
    Replies
    1. This issue is caused by any small mismatch ... I had this issue when i try to map xsd:decimal to xsd:integer ...

      Delete
    2. I Have the same problem, and booth types are string.

      Delete