Advertisements



Service Bus 12.2.1 – REST Support

In this blog, we will review native REST service support added in 12.2.1. And you can refer to post to find information about same from 12.13 perspective.

Before discussing further, we will first see how 12.2.1 provides the backward compatibility with 12.1.3. In 12.1.3, REST Proxy Service converts native REST payload to SOAP before calling a Pipeline/Split-Join and REST Business Service convert SOAP to REST native payload i.e. the internal communication happen using WSDL interfaces only.

In 12.13, while creating REST binding as Proxy or Business service check the option as shown below and other steps remain same.

We can see WSDL and WADL gets created in your project.

wadl

req1

req2

To access REST resource use url like http://localhost:<<OSB Port>/<<proxy endpoint>>/<<resource name>>  so it will be http://localhost:7003/restDemo/REST1213WayPS/employees

To access design-time WADL use url like http://localhost:<<OSB Port>/sbresource?WADL/<>/<>  so it will be http://localhost:7003/sbresource?WADL/RESTIn1213way/WSDL/REST1213WayPS

To access effective WADL use url like http://localhost:<<OSB Port>/sbresource?(PROXY or BIZ)/<<project path>>/<<proxy or biz service name>>  so it will be http://localhost:7003/sbresource?PROXY/RESTIn1213way/ProxyServices/REST1213WayPS

Now in 12.2.1, we have native REST support and no need of creating WSDL for internal communication. This native support is broadly classified into following categories:

  • Un-typed Proxy/Business Service –  For which method information is available at design time so no WADL is involved.
  • Typed Proxy/Business Service – For which the method information is available at design time so WADL is used/created having this information.

REST binding can be used to create both Proxy and Business services that fall into above categories. In this post, we discuss from Proxy Service perspective and same can be followed for business services.

Creating Typed Proxy Service:

We use REST binding to create native REST service. So drag REST binding from Components to Proxy Services swim lane or right click to choose REST option.

typedbind1

Provide name for REST binding and do not select WSDL interfaces check box as we are creating native REST services. Click Next.

typed1

Create a new REST resource as shown below.

typedemp

typedemp2

Create a REST method using following steps by clicking + icon in Methods.

typedreq

typedresp

typedfinish

Now verify that WADL file is generated automatically with method information as defined above. Now create pipeline using the following steps.

typedpp

typedpp1

typedpp2

typedpp3

Connect Proxy Service, Pipeline and Business Service as shown below. Use the same business service as we used earlier.

sboverview

Finish the message flow as shown below.

ppmflow

routing

Deploy and test your project in Service Bus console. Observe that you can see all media types supported by REST service are shown in Accept choice list.

typedtestreq

typedtestresp

Now we will see how to use an existing WADL to create Typed REST services.

Again drag the REST binding from Components to Proxy Services swim lane or right click in swim lane to choose REST option.

untypedbind1

Provide name for REST binding and do not select WSDL interfaces check box as we are creating native REST services. Click Next.

typedproxy

Choose REST1213WayPS.wadl. This confirms that WADLs generated by 1213 REST services are supported here. Observe that REST methods are populated automatically from selected WADL.

typed

wadlselect

wadloper

Click Finish and verify that new WADL is generated again for this Proxy Service.

wadl

Now finish pipeline message flow as above using WADL created in above step.

typedexistingpp

sboverview1

To access REST resource use url http://localhost:7003/restDemo/typedService/typedEmployees

To access design-time WADL use url http://localhost:7003/sbresource?WADL/RESTTypedServices/TypedRestService

To access effective WADL use url http://localhost:7003/sbresource?PROXY/RESTTypedServices/TypedRestService

Observations:

  • WADL is always created for Typed native REST services when one is not chosen during creation.
  • No where we are able to give the input/output message structure (XML or JSON schema) for REST methods. I think this may be improved in later releases.
  • When a native REST Proxy Service supports multiple content types (XML, JSON), automatic payload conversion (XML to JSON and vice-versa) is not happening as we see in WSDL based REST services. I will try to cover more on this in later posts.
  • Content-Type HTTP header is used by OSB for content parsing and we can see this set automatically when media type is chosen in test console.
  • Value given for soa:name in WADL is populated for $operation context variable in pipeline.
  • 1213 WADL is not supported for creating pipelines but can be used to create Proxy, however a new WADL will be generated by OSB as we saw above.

Creating Un-typed Proxy Service:

Create a Proxy Service using following steps. Observe the usage of Transport and no where we define REST resource or methods.

untypedps

untypedps1

untypedps2

untypedps3

Create pipeline using following steps and observe that we are not selecting any WADL as we did earlier.

untypepp

untypedpp1

Connect all these pieces as shown below and complete Message Flow as we did earlier.

sboverview2

Deploy and test your project in Service Bus console. Observe that you can see all media types supported by REST service are shown in Media Type choice list as we have not specified supported types any where. Service Bus uses the Content-Type HTTP header for parsing the payload and you can see this is set automatically when we choose the media type in Test Console.

typedtest

untypedtestresp

To access REST resource use url http://localhost:7003/restDemo/untypedService

Observations:

  • No WADL is used during creation of Un-typed native REST services.
  • Again, no where we are able to give the input/output message structure (XML or JSON schema) for REST methods.
  • Again, no automatic payload conversion will happen when REST Proxy supports multiple Content Types.
  • Content-Type HTTP header is used by OSB for content parsing and we can see this set automatically when media type is chosen in test console.

In above 2 sections, we created  both Proxy and Pipeline separately and we can observe that WADL is optional for REST based pipelines. So even Pipelines are classified into Typed and Un-typed  depending on usage of WADL.

So now the Q arises about compatibility between Proxy and Pipelines as both of them can be Typed /Un-Typed. Since Typed is more restrictive having REST methods we will be able to call both Un-Typed and Typed pipelines provided they used same WADL. In the same way, Un-Typed will be able to call both Un-typed and Typed Pipelines.

The source code used in this post can be downloaded from here and please note that you need to create DB connection pool to run this project with JNDI eis/DB/LocalDB.

Reference:

https://docs.oracle.com/middleware/1221/osb/develop/GUID-C346DF7D-041D-4E10-BE1C-451F50719106.htm#OSBDV89235

Advertisements

11 Responses to “Service Bus 12.2.1 – REST Support”


  1. 1 kuttimahesh July 19, 2017 at 7:40 PM

    Hi Siva, Can you revisit and make corrections, Hope you find what are the mistakes in flow explanation, i got so much confused but now able to correlate flow explanation. if needed let me know will tell what are the errors.

  2. 3 Tomas April 28, 2017 at 4:59 AM

    Siva this is excellent post. It helped me with my first native REST in 12.2.
    I wonder if you have an example of how to deal with errors returned by a plsql procedure. Currently when my POST fails due to any database error the http return code is still 200. I would like this to actually be showing a 500 or other error code.

    • 4 svgonugu April 28, 2017 at 11:13 AM

      are you making use of db adapter for using plsql?

      • 5 Tomas April 28, 2017 at 10:02 PM

        Yes. Actually I’m using the Oracle E-Business Suite adapter but it works the same as just DB adapter.
        My adapter calls stored procedure accepting bunch of parameters and outputting few others (including status – failed, success, duplicate). In all cases my http return code is always 200 which is kind of correct since the http call worked but I would like to force 409 or 500 in not success cases.
        This adapter is exposed as REST API (POST) accepting parameters as needed by the plsql procedure.
        Currently I do not have pipeline. Do I have to introduce the pipeline for this to work?

  3. 7 John March 1, 2017 at 11:15 PM

    Hi Siva,
    Any idea how this can be achieved in BPEL 12.2.1 -Orchestrate a set of RESTful state transitions (Hypermedia as the Engine of Application State (HATEOAS) approach).? Or implement HATEOAS approach for set of services using Oracle Service Bus 12.2.1. I have seen Oracle docs to use http link header but wondering how we can expose set of REST service using HATEOAS approach. Can you suggest an approach to provide a set of HATEOAS REST api over service bus? For ex: Employees{empid? provide the basic info on a particular employee with a self link on more information like Addresses etc. Hope you got it.

    • 8 svgonugu March 2, 2017 at 11:12 AM

      Hi John, I understand the HATEOAS approach you are talking about. Frankly, i never gave a thought about it from OSB perspective. I used ADF BC REST services recently where this kind of support is built-in.

  4. 9 subash September 16, 2016 at 2:11 AM

    Excellent explanation. Thanks Siva.
    I am trying to access a rest java project which returns XML file, now I want to convert the response to JSON format. Coudl you please advice how the rest proxy binding need to be done for this, I need to pass the query parameters by using http GET method. I did the rest binding on the business service but I am gettign the 406 error from the business service, where it would be wrong?


  1. 1 Branching in Native REST Services | Siva's Blog Trackback on October 15, 2016 at 3:30 PM

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s




Advertisements

Pages

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 337 other followers

Enter your email address to follow this blog and receive notifications of new posts by email.