Enter your keyword

post

Create 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 which shows how to create REST service in Oracle Service Bus.
 
After this blog, you should have learned to: 

  • How to create SB(Service Bus) application with SB project
  • How to create simple REST service
  • Understanding of some basis components of Service Bus
  • 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.

Below are step by step procedure how to create 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 as 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 button 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

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

23) Click Execute

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

Some 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)

Some Toughts (7)

  1. added on 7 Jan, 2017
    Reply

    Excellent…!!!

  2. added on 9 Jan, 2017
    Reply

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

  3. added on 1 Jun, 2017
    Reply

    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

  4. added on 1 Mar, 2018
    Reply

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

  5. added on 27 Mar, 2018
    Reply

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

  6. added on 29 Apr, 2019
    Reply

    Can this be done using SOAP ?

  7. added on 24 Jul, 2019
    Reply

    Hi Ankur,
    Thanks for share, I found below service execution issue

    com.bea.wli.config.component.NotFoundException: Validation of ServiceMetadataDerivedType SBProject/RestNService.ProxyService failed: ServiceMetadataDerivedType SBProject/RestNService.ProxyService does not exist
    at com.bea.wli.config.derivedcache.impl.DerivedCache.deriveTheValue(DerivedCache.java:545)

    Kindly assist on above issue

    Thanks

Leave a Reply

Your email address will not be published.