OSB 11g - exposing an existing SOAP service as REST service on OSB with XML payload

Among many forms of 'service virtualization' provided by OSB, one form is exposing existing SOAP services (eg: SOAP hosted on SOA Suite) as REST service to the callers. In this post, lets walk through the detailed steps of this variant of 'service virtualization'. 


1. Developer Summary

Expertise level - medium

Familiarity needed - development exposure on oracle Fusion Middleware tools like like SOA suite 11g, OSB 11g, OEPE 11g, Weblogic Server, etc. Some familiarity with XML and XSD schemas. Some understanding and appreciation of REST as a WebService style. 

Out of Scope - Coverage of REST theory, installation details of any of the tools used, basic development details using the tools, etc., are out of scope of this tutorial.

2. Technologies / Tools used


  • Weblogic Server 10.3.6
  • OSB 11.1.1.6
  • OEPE 11.1.1.8 (alternatively, you may use OSB console based development env itself)
  • Externally hosted readily available SOAP WebService - thanks to the providers of this readily available service -that converts temperature from one unit to another. 

3. Detailed steps

3.1. Preparation of project in OEPE 


In the IDE (OEPE), create a 'OSB configuration project', with any name, eg: "OSB Configuration 1". With in that, create a OSB project and name it "TempConversionProj" (or any other name of your choice). After this, the project may look something like the following:




3.2. Create a OSB Business Service for the externally available WebService


For simplicity of this tutorial, as well as to focus on the REST details of OSB, we are not developing here our own SOAP service (that is to be exposed as REST service), and instead using a SOAP service that is freely available on the web.  You may wish to develop our own SOAP service for this use, and host it on any technology platform of your choice.

For this tutorial, a temperature conversion service available at 
http://www.webservicex.net/ConvertTemperature.asmx?WSDL
has been choosen, and this tutorial virtualizes this service as REST service.

Expose this service as business service. As this is a simple task in OSB deveopment, details of this step are not covered here. In our case, I named it as TempConvBS


Test this business service and make sure its working good. 

Here is a sample input:


and output:


So far whatever has been done is nothing to do with REST style. Now, lets move on to developing proxy service in REST style.

3.2. Develop a OSB proxy service

Create a proxy service in OSB, with a name like TempConvXMLRESTPS.(Note - I have followed a convention to suffix BS for business service and PS for proxy service)

Drag and drop a 'conditional branch' and form the condition on http-method value avaialble in the transport, i.e., on the value of 
$inbound/ctx:transport/ctx:request/http:http-method/text()


Create a branch with name 'POST' as follows if the http-method value matches 'POST':




And, in that (POST) branch, add a pipe line pair, and add a stage to each of the pipelines. Also name them sensibly :-)



We get the XML payload of the REST service into the $body. So, in the 'InputProcessingStage', assign the contents of $body to a variable, named BSReqVar in our case.


Subsequently make a 'Service Callout' to our BS, and send BSReqVar data to it and get resp data back into BSRespVar 


In the response pipe line, use a 'Replace' activity to copy the data from BSRespVar to body. Be sure you are not replacing the body itself, but replacing its contents only (choose 'Replace node contents')


We are good to go. 
Deploy the project on to OSB.

3.3. Testing the REST service

This REST can be tested from multiple test clients, including the test client provided in OSB. In this post, lets test it from OSB test interface as well as Google Chrome 'Advanced REST client'.

3.3.1. Testing from OSB console test interface

Launch test interface for the PS, and provide the payload to be tested


Go to the 'Transport' details below, and provide the http-method as 'POST'. May need to supply login credentials to weblogic - but not applicable in this case.


'Execute' the test.

Below is a snapshot of successful execution:


3.3.1. Testing from Google chrome 'Advanced REST client'


In the google chrome browser store, find and Install 'Advanced Rest Client'



Launch the Advanced REST client

Provide the REST service end point URL in the URL box, choose http 'POST' method, and provide the payload in the 'body'

'Send' the request

On a successful execution, we get a response something like below snapshot -with http response code 200, and response payload:


4. Notes

For simpler requirements like querying something with a few parameters (may not need XML payload), implementation with http GET method with input key value pairs in URL itself, and reading the input with relative-URI option in the OSB, and providing response using $body variable would work.




Comments

  1. appreciate your effort ...informative

    ReplyDelete
  2. My test from the Chrome Rest client does not work. gives me HTTP 500 error. Can u please suggest if there are any specific settings needs to be done

    ReplyDelete

Post a Comment