Configuring REST service in SOA using HTTP Adapter - GET/POST

In this example, we will explore how to configure REST service in SOA for both GET and POST request.
For this example, we will create a XSD which takes firstname and lastname as input and returns Full Name as output.

First, we will create a new project call, RestNamingService.
Our XSD will look like below:
<?xml version="1.0" encoding="windows-1252" ?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.example.org"
            targetNamespace="http://www.example.org" elementFormDefault="qualified">
  <xsd:element name="request">
    <xsd:annotation>
      <xsd:documentation>A sample element</xsd:documentation>
    </xsd:annotation>
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element name="firstname" type="xsd:string"/>
        <xsd:element name="lastname" type="xsd:string"/>
      </xsd:sequence>
    </xsd:complexType>
  </xsd:element>
  <xsd:element name="response">
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element name="fullname" type="xsd:string"/>
      </xsd:sequence>
    </xsd:complexType>
  </xsd:element>
</xsd:schema>

Now drag HTTP binding to service end of Composite.xml. Name service: httpserviceGET



Since we are expecting the response, we will select request-response pattern. The request type is GET.


Select the request and response element defined in XSD.

Click Finish.
This will generate the service binding name httpserviceGET.

Now Drag the BPEL component in Composite. Name it as processGet.

Wire the httpserviceGet and processGet component.

Add receive and reply activity in processGet bpel service.

Add assign activity to concat the firstname and lastname and set it to response element.


Now deploy the RestNamingService project to SOA server.

Testing:
We can test our service by passing the parameters in request URL.


Response:

<response xmlns="http://www.example.org">
<fullname xmlns="http://www.example.org">John smith</fullname>
</response>


Post Service:

For testing the POST service we will modify existing service by changing the pattern to POST.
Double click the httpserviceGet service endpoint in composite xml and change the pattern to POST.


Now reploy the project on SOA server.

In order to test the POST service we will create a REST project in SOAP UI.


This how we can create REST service in SOA using http binding.



Popular posts from this blog

JAVA embedding in Oracle SOA 12c

API Design First approach: Implementing quick mock API's using swagger hub and postman

Passing/Receiving HTTP header in SOA BPEL