Wednesday 9 March 2016

HTTP Adapter in SOA 11g

HTTP Adapter in SOA 11g

At SOA 10g I faced a lot of difficulty while invoking a REST endpoint having POST or GET method as binding verb.You have to create your own custom wsdl and embed your message type and binding etc..
But SOA 11g comes with HTTP adapter , through this blog I’ll demonstrate invocation of Yahoo Geolocation REST service using HTTP adapter.
You can get the endpoint details in this location http://developer.yahoo.com/maps/rest/V1/geocode.html. If you pastehttp://local.yahooapis.com/MapsService/V1/geocode?appid=YD-9G7bey8_JXxQP6rxl.fBFGgCdNjoDMACQA--&street=701+First+Ave&city=Sunnyvale&state=CA in browser then you will get below result.
<?xml version="1.0"?>
<ResultSet xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:yahoo:maps" 
xsi:schemaLocation="urn:yahoo:maps http://local.yahooapis.com/MapsService/V1/GeocodeResponse.xsd">
<Result precision="address">
<Latitude>37.416397</Latitude>
<Longitude>-122.025055</Longitude>
<Address>701 1st Ave</Address>
<City>Sunnyvale</City>
<State>CA</State>
<Zip>94089-1019</Zip>
<Country>US</Country>
</Result></ResultSet>
<!-- ws01.ydn.ac4.yahoo.com compressed/chunked Sun Apr  3 00:08:24 PDT 2011 –>
But we need to achieve this using adapter.This service has got its input and 
output schema structure like below,

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
  targetNamespace="urn:yahoo:maps"
  xmlns="urn:yahoo:maps"
  elementFormDefault="qualified">

    <xs:element name="ResultSet">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="Result" type="ResultType" minOccurs="0" maxOccurs="50" />
            </xs:sequence>
        </xs:complexType>
    </xs:element>

    <xs:complexType name="ResultType">
        <xs:sequence>
            <xs:element name="Latitude" type="xs:decimal" />
            <xs:element name="Longitude" type="xs:decimal" />
            <xs:element name="Address" type="xs:string" />
            <xs:element name="City" type="xs:string" />
            <xs:element name="State" type="xs:string" />
            <xs:element name="Zip" type="xs:string" />
            <xs:element name="Country" type="xs:string" />
        </xs:sequence>
        <xs:attribute name="precision" type="xs:string" />
        <xs:attribute name="warning" type="xs:string" use="optional"/>
    </xs:complexType>
    <xs:element name="RequestSet">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="appid" type="xs:string"/>
                <xs:element name="street" type="xs:string"/>
                <xs:element name="city" type="xs:string"/>
                <xs:element name="state" type="xs:string"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
</xs:schema>
<!-- ws13.ydn.gq1.yahoo.com compressed Fri Oct 22 03:06:44 PDT 2010 –>

We’ll bind RequestSet to service input parameter and Result to service output.

Drag and drop an HTTP adapter in Reference lane ,

image

image

In HTTP Binding Configuration give the value as mentioned,

image

Bind input and output message type and click finish,

image

Then create a composite like below where adapter input parameter is same as process input and output parameter would be process output parameter,

image

Deploy the composite and test by passing proper value like below,

image

and in response you will get,

<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"xmlns:wsa="http://www.w3.org/2005/08/addressing">
    <env:Header>
        <wsa:MessageID>urn:D6C31E005DDA11E0BFCB817CB1165FA2</wsa:MessageID>
        <wsa:ReplyTo>
            <wsa:Address>http://www.w3.org/2005/08/addressing/anonymous</wsa:Address>
        </wsa:ReplyTo>
    </env:Header>
    <env:Body>
        <ResultSet xmlns:ns0="urn:yahoo:maps" xmlns="urn:yahoo:maps">
            <ns0:Result precision="address">
                <ns0:Latitude>37.416397</ns0:Latitude>
                <ns0:Longitude>-122.025055</ns0:Longitude>
                <ns0:Address>701 1st Ave</ns0:Address>
                <ns0:City>Sunnyvale</ns0:City>
                <ns0:State>CA</ns0:State>
                <ns0:Zip>94089-1019</ns0:Zip>
                <ns0:Country>US</ns0:Country>
            </ns0:Result>
        </ResultSet>
    </env:Body>
</env:Envelope>


So Invoking REST endpoint from composite is just one click away !!!!!!!!

No comments:

Post a Comment