Skip to main content

Oracle

OSB-12C REST Adapter Implementation

Istock 682295824

Implementing REST Adapter in Service Bus

This article covers the implementation of REST adapter in Oracle Service Bus (12C). REST adapter allows an easy way of calling/exposing REST services based on a Web Application Description Language (WADL).

In this implementation, we are going to call Weather API which is a public REST API by creating a REST-based proxy and business services. This API is used to find the weather report of a given location. To do this we have created two sample schemas, one for request and other for response.

  • Request schema contains only two elements city name and Id. We can either pass a city name or an ID of the location as input.

12C_001

  • Response schema contains weather report elements like wind, clouds, temperature, weather, longitude, latitude, etc.

12C_002

 

Creating Service Bus Application and Project

  • Open Oracle 12c JDeveloper, go to File -> New -> Application
  • Select Service Bus Application in the list of items and click OK.
  • Enter a name in the Application name field and click Finish.

12C_003

  • Right-click the application and select New -> Project.
  • Select Service Bus Project in the list of items and click Ok.
  • Enter the Project name, leave the Directory at its default value and click Finish.

12C_004

  • We can see the SOA composite (.jpr file) under the project.

12C_005

 

Creating REST-based Business Service

  • Open the SOA Composite Editor (.jpr file), right-click the External Services lane and select REST.

12C_006

  • Enter a name for Rest Reference.
  • In the Base URI section, enter the REST API Endpoint URI.
  • Select to Enforce XML Schema Ordering. When selected, this reorders JSON payloads to match the order of elements in the XML schema. This includes inbound request payloads and responses from outbound requests.

12C_007

  • Add a new Resource Path in the Resources section or double click the default resource (/) to update.
  •  In the Create Resource dialog, enter the resource path in the Relative Path field.
  • In the Full Path field, we can see the URI which we have entered in the Base URI field.

12C_008

  • Click the Add icon in the Operation Bindings section, and select Add Operation Binding.

12C_009

  • Enter the Operation name in the Operation field.
  • Select the existing resource path in the Resource List.
  • In the HTTP Verb, select the operation (POST, GET, DELETE, or PUT).

12C_010

  • In the Request Section, click the Define Schema for Native Format icon to create a new schema from a sample.
  • Enter the Schema name, Directory Name will be generated automatically and click Next.

12C_011

  • Select JSON Interchange Format in the file type and click Next.

12C_012

  • Enter the JSON input in the Sample text box and click Next. We have to provide the JSON input in a detailed manner including all elements, attributes, etc. so that the generated schema defines the structure of JSON data for interaction.

12C_013

  • In the next dialog, we can see a schema generated based on the JSON input. Click Next
Oracle - Guide to Oracle Cloud: 5 Steps to Ensure a Successful Move to the Cloud
Guide to Oracle Cloud: 5 Steps to Ensure a Successful Move to the Cloud

Explore key considerations, integrating the cloud with legacy applications and challenges of current cloud implementations.

Get the Guide

12C_014

  • Click Finish. In the URI Parameters section, we can see the parameter list with style, type, and expression.
  • Click the Response Tab.

12C_015

  • Enter the operation name in the Operation field.
  • Select the existing resource path in the Resource List.
  • In the HTTP Verb, select the operation (POST, GET, DELETE, or PUT).
  • Select XML and JSON checkboxes in the Payload type.

12C_016

  • Similar to Request, In the Response section, click the Define Schema for Native Format icon.
  • Enter the Schema name and the Directory path will be generated automatically under the project and click Next.
  • Select JSON Interchange Format in the file type and click Next
  • Enter the JSON input in the Sample text box and click Next
  • In the next dialog, we can see a schema generated based on the JSON input. Click Next

12C_017

  • Request and Response configurations are done. Click OK to finish.

12C_018

  • We can see the REST-based Business Service in external Services. Also, we can see the Resources folder under the project with WADL, WSDL, API Request and Response Schemas.

12C_019

 

Creating REST-based Proxy Service

  • Open the SOA Composite (.jpr file). Right-click the Proxy Services lane and select REST

12C_020

  • Enter the Proxy name, leave the Resource Path as it is.
  • Click the Add icon in the Operation Binding section and select Add new operation binding.

12C_021

  • Enter the Operation Name in the Operation field.
  • Select POST method in the HTTP Verb.
  • In the Request tab, click the Browse for Schema File icon and select the Request Schema

12C_022

  • Click on the Response tab and select the Response schema.

12C_023

  • Click Ok to finish, we can see the Proxy service generated with WADL and WSDL files.

12C_024

 

Creating a WSDL based Pipeline for Proxy

  • Open the .jpr file, in the Pipelines/Split Joins lane, Right Click -> Insert -> Pipeline.

12C_025

  • Enter the Pipeline name and click Next.

12C_026

  • Select WSDL as Service Type and click the Browse WSDLs icon.

12C_027

  • Select the Proxy Service WSDL and click Finish.

12C_028

  • We can see the Pipeline added in the .jpr file.

12C_029

  • Right-click on the Proxy Service and click Edit.

12C_030

  • Click the Search icon in the Target Service to add the Pipeline.

12C_031

  • Select the Pipeline and click Ok.

12C_032

  • We can see the wire between the Proxy Service and the Pipeline.

12C_033

  • Right-click the Pipeline and select Edit.
  • Add PipelinePairNode.
  • Right-click the Stage under Request Pipeline and add a Replace action.
  • Select the XSLT Resource to transform the Request to API request.

12C_034

  • Add a Service Callout action to call the REST Business Service.

12C_035

  • Again add a Replace action for API Response to Response transformation.

12C_036

  • We can see the wire between Pipeline and Business Service.

12C_037

  • Deploy the Project in Oracle 12c Service Bus Console
  • Go to Proxy Service and click on the Launch Test Console icon to test the project from the console.

12C_038

  • Enter the city name in the request to get the Weather report of that location.

12C_039

In the above implementation, we have used a REST API that obtained it’s parameters from GET request and returned a JSON response which is new in SOA Suite 12C. It is then converted into XML format for further processing

Thoughts on “OSB-12C REST Adapter Implementation”

  1. Hi friend,
    Can you share the XSLT file?
    I lost in that part, when you add a replace component.

    Thanks

  2. Hi again
    Dear friend
    Can you tell me, how can I obtain the URI of the proxy service based in REST? I’m looking for WALD but I can´t see anywhere
    Thks

  3. Venkatesan Jayaraman Post author

    Hi,
    It’s a simple one to one xsl that you can do it using 12c Jdev. In the replace action i have selected XSLT Resources to configure XSLT.

  4. Venkatesan Jayaraman Post author

    Right click on the proxy service, click Edit and then select Transport tab you will be able to see the Endpoint URI of the proxy. You can also modify the Endpoint URI based on your requirement.

  5. Hi ,
    CAn you share the artifacts for the above code . I’m new to this and would appreciate your help

  6. Anshul Mittal

    Hi,

    I want to configure a rest adapter with “PATCH” as a http verb, but there is no such option coming while creating rest service. Could you please tell me how do I configure rest service with http method as “PATCH”

  7. Hello,

    Have a small query. How to virtualize rest api webservice with our own uri/url. Can you please guide me on this.

    Thanks,
    Vivek

  8. Hi,

    I folowed the similar steps, now I see an error as Rest Business service returned HTTP rsponse with status code 406. Could yu please let me know what is wrong in the configuraion.

  9. Can you please provide the code for this service.I am trying consume REST service which takes JSON request and responds in JSON .I am using REST bidning and trying in OSB 12C in 12.2.1.0 version.

    REST reference binding is not able to convert XML to JSON.Proxy service is XML based proxy.Proxy service sends XML to REST based business service calling REST API that accepts JSON payload.

  10. Venkatesan Jayaraman Post author

    Hi,

    The business service is failing because the weather api which i have used in this blog is changed now its asking for a valid key, so to access this you need to register here https://home.openweathermap.org/users/sign_up once you registered you will get a valid key and you have to send it as a parameter to the api to get weather report.

    Example of API call:
    http://api.openweathermap.org/data/2.5/forecast/city?id=524901&APPID={APIKEY}

  11. Venkatesan Jayaraman Post author

    Hi,

    You have to do transformation before calling the REST business service, you have to create a xsl to transform the XML from proxy schema format to REST business service JSON format.

  12. Hi Venkat.. excellent blog it is to understsand the rest implementation in osb. Could you please advice on the post method and semantic url usage for rest service in osb. Thanks.

  13. This explanation is very good so thank you! Similar to the struggles of others I’m having difficulty with the XSLT. Can you share the file – or better, share the steps using the 12c features to convert the file. Thanks!

  14. Hi Venkat,

    Is it possible to test the Business Service(REST configured) alone from SBConsole?

    I created a Proxy/BusService similar way and while testing BusService from sbconsole(submitted thro SOAP request) I get below error message.
    Any help will be appreciated. (when I submit request using ‘REST’ tab it works fine)

    Error Message:
    soapenv:Server

    No acceptable representation for response with “text/plain;charset=utf-8” media type was found

    com.bea.alsb.ws.codec.CodecException: No acceptable representation for response with “text/plain;charset=utf-8” media type was found
    at com.bea.wli.sb.service.handlerchain.handlers.OutboundWsdlRestHandler$AbstractResponseMessage.g

  15. Hi All,
    Our requirement is to use text/xml in mediaType. However I unable to use this option in OSB, can you please guild me with this.

  16. Adilson Vahldick

    Hi

    After this moment, “Enter the JSON input in the Sample text box and click Next. “, the system throws an exception: noclassdeffounderror for JsonFactory in jackson. Do you have any idea how can I solved it?

  17. Hi Venkatesan ,

    Can you just share the Response Schema XSD so that it ll be helpful for me to practice

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Venkatesan Jayaraman

More from this Author

Categories
Follow Us
TwitterLinkedinFacebookYoutubeInstagram