Showing posts with label HTTP Adapter. Show all posts
Showing posts with label HTTP Adapter. Show all posts

Monday, 9 January 2017

HTTP binding in Soa Suite 11g PS2

With Patch Set 2 of Soa Suite 11g Oracle added the HTTP Binding to the supported Adapters. This Adapter was already a feature of Soa Suite 10g, so it is great news that is back. So when your HTTP Service returns a XML message then you can use this binding in your composite application. When the HTTP Service has a  JSON response then you can use the Spring Context Component ( With PS2 Spring Context is supported ). Lucas made a great example how you can achieve this.

In this blogpost I will show how you can use this HTTP Binding as a Service or as a Reference Adapter. I start with a Service so I can use this Service later in the Reference Adapter.
Drag the HTTP Binding from the Component Palette to the Service part of the Composite. Use Service as Type and when you want to have this Service, to return a message then you should select Request-Response as Operation Type.
Provide the Request and Response XSD and choose the right element. For the Request Message Schema you can also use the wizard. 
Next step is to wire this Service to a component. Choose a BPEL component and use the Define Service Later template.

Make a wire between the Service and the BPEL component.
Open the BPEL component and a Receive and Reply Activity and finish your BPEL. When everything is valid then you can deploy this to the Soa Suite Server.

For this HTTP Binding Service Soa Suite adds two Port types to the WSDL. This means you can also invoke this Service with a SOAP message.
  1. <wsdl:service name="execute">  
  2.         <wsdl:port name="Request_Response_pt" binding="tns:Request_Response_ptHttpGET">  
  3.             <http:address xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"  location="http://laptopedwin.wh.lan:8001/soa-infra/services/default/HttpBinding/execute"/>  
  4.         </wsdl:port>  
  5.         <wsdl:port name="Request_Response_pt_soappt"   
  6. binding="tns:Request_Response_pttBinding">  
  7.             <soap:address xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"   
  8. location="http://laptopedwin.wh.lan:8001/soa-infra/services/default/HttpBinding/execute"/>  
  9.         </wsdl:port>  
  10.     </wsdl:service>  

The Best way to test this HTTP Service is to open the endpoint url in a browser 
http://laptopedwin.wh.lan:8001/soa-infra/services/default/HttpBinding/execute
This one is better then the tester of the Enterprise manager.
Here you can choose for the normal Invoke ( Soap message ) or use REST POST or GET

Or you can use the HTTP analyzer of JDeveloper, this is a great way to see the raw request and response


The HTTP binding can also be used as a Reference adapter. For example you can use the just created Service as Endpoint. Provide the Request and Response Schema's.

To test this Reference Adapter you can add a Mediator component with the same Request and Response Schema's. Expose this Mediator as a Service and wire the Reference Adapter to the Mediator and complete the routing rule. 
Deploy this composite application, invoke the Mediator Service and take a look at the instances in the Enterprise Manager.

You can download my example at github
https://github.com/biemond/soa11g_examples/tree/master/SoaHTTPBinding
and in here I also have a txt file with all the request I did with the Wfetch tool.


Update by Rakesh


Testing of HTTP Binding adapter works from the browser just fine. It's just that how you pass the parameters.

Here's what I did:
I created a simple composite application with one input parameter and exposed it as REST service using HTTP binding adapter (GET). The service does nothing but add a string to the input parameter and returns back.

The endpoint looks like this:

soatestserver:8001/soa-infra/services/default/TestPatchProject/HTTPBindingService

When you go to test console it forms the test URL string like this

soatestserver:8001/soa-infra/services/default/TestPatchProject/HTTPBindingService/Request-Response?input=Rakesh

All along until now I was trying to use this URL from test console or from the browser.

...but this never works. It's not the right way to use it. If you try this it will return page not found.

What you actually need to use this is below:

soatestserver:8001/soa-infra/services/default/HelloHTTPProject/HTTPBindingService?input=test&operationName=Request-Response

Notice the changes in above URL. The Request-Response is not just after HTTPBindingService (as before), instead its passed as a parameter of operationName.

The above URL works just fine from browser and test console. The auto generated Test URL in test console is misleading.

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 !!!!!!!!