Handle dynamic params in metadata for REST connectors in OSB 12C

September 18, 2017

Reading time ~2 minutes

In this post, we will learn how to get the value of some path parameters from the URI of a REST Service using OSB 12C. There we go:

Use case

First, lets think that we have to consume a sample REST service to create one employee in a specific organization, so we will have a dynamic path parameter after organizations that we are going to send in the URI.

URI:

  • https://RestServices.com/api/organizations/1/employees

Method:

  • POST

ContentType:

  • application/json

ContentBody

 {         
   "employeeNumber":123,
   "fullName":"Christopher Laurente",
   "Age":27,
   "Country":"Norway"
   ....
  }

Then we start, open JDeveloper (In my case is 12.2.1), create a Service bus project and add a Rest component to External services in the composite as the image below.

Set the name, for instance CompaniesAPI and check the box “Reference will be invoked by components using WSDL interfaces”.

Set the Base URI as https://RestServices.com/api and add a Resource Path as organizations/{organization_id}/employees. See the image below.

Then create a Operation Binding, call it CreateEmployee and select the HTTP Verb as POST.

Now, we need to reference the path param called organization_id, for this we are going to use the variable $property according to oracle documentation https://docs.oracle.com/middleware/1213/osb/develop/GUID-C346DF7D-041D-4E10-BE1C-451F50719106.htm#OSBDV88240

The variable called organizationId will be set in the metadata of the outbound request as the following structure:

<ctx:transport>
 <ctx:request>
   <headers >
   <ctx:user-metadata name="organizationId" value="1" />
 </ctx:request>
</ctx:transport>

One of the challenges that I got was that I could not insert the metadata directly into the outbound variable, because I got CData error everytime that I tried. So what I did was assigning the whole value of the outbound in an auxiliar variable, insert the metadata into that aux variable and replace the outbound with the value of the auxiliar outbound.

Assign to auxiliar variable

Insert metadata

Replace Outbound

Conclusion

I’m gonna say that I had to review oracle documentation to understand how to use this REST component correctly and not always will be necessary to use this solution to send dynamic params in the URI (even for query params), because if is possible to use the content body to send these params then it will be straightforward to manage them rather than the solution that I described above.

Christopher is part of middleware Sysco. He is CTO of his own startup in South America. He was working with differents open source solutions. Also He was participating in several programming tournaments related to algorithms of Computer Science. Actually these last years, he gained experience with Oracle MAF, ADF ,OSB and other Oracle solutions.

Dalibor is a software technology consultant, developer and trainer that is now part of the middleware team at Sysco. He has many years of experience in the field developing software applications for production automation, for telecommunication, as well as developing financial and ERP software applications. Over the years he has been teaching many Oracle University classes in Norway and abroad. His specialties are Java web development with Oracle ADF framework, Oracle Fusion Middleware and SOA administration, optimization and development. Through his career Dalibor has used many different programming languages such as: Visual Basic, C/C++, Delphi, SQL and PL/SQL, Java and PHP. He has worked with different databases on various projects, like: Oracle, MS SQL, Interbase and MySQL, and different application servers like: Apache, GlassFish, Oracle iAS and BEA WebLogic

Customized OSB Training

Sysco have had several customers migrating to SOA Suite 12c or Service Bus 12c - and we have also presented about the topic at OUGN, OghT...… Continue reading

OUGN Integration SIG - DevOps

Published on December 10, 2017