Monday, July 22, 2013

WSO2 ESB 4.7 HTTP Endpoint

WSO2 ESB 4.7 HTTP Endpoint

SOAP client to REST back-end service using HTTP End point

Step 1: Build "SimpleStockQuoteService" service and start "axis2Server"

$ESB_HOME\samples\axis2Server\src\SimpleStockQuoteService>ant
$ESB_HOME\samples\axis2Server>axis2server.sh (or .bat)

Step 2: Create a HTTP endpoint ((say, HTTPEndPoint)

<endpoint xmlns="http://ws.apache.org/ns/synapse" name="HTTPEndPoint">
   <http uri-template="https://localhost:9100/{uri.var.path}/{uri.var.name}" method="post">
      <suspendOnFailure>
         <progressionFactor>1.0</progressionFactor>
      </suspendOnFailure>
      <markForSuspension>
         <retriesBeforeSuspension>0</retriesBeforeSuspension>
         <retryDelay>0</retryDelay>
      </markForSuspension>
   </http>
</endpoint>

Step 3: Create a pass through proxy with the endpoint defined above(Say TestProxy)

<proxy xmlns="http://ws.apache.org/ns/synapse" name="TestProxy" transports="https,http" statistics="disable" trace="disable" startOnLoad="true">
   <target>
      <inSequence>
         <property name="uri.var.path" value="services"/>
         <property name="uri.var.name" value="SimpleStockQuoteService"/>
         <send>
            <endpoint key="HTTPEndPoint"/>
         </send>
      </inSequence>
      <outSequence>
         <send/>
      </outSequence>
   </target>
   <description></description>
</proxy>

Step 4: Place a client request from the AXIS2CLIENT folder ($ESB_HOME/samples/axis2Client)
e.g. ant stockquote -Dsymbol=IBM -Dmode=quote -Daddurl=http://localhost:8280/services/TestProxy

Note: TCPMon can be placed between Client & WSO2 ESB and WSO2 ESB & Back End Service to monitor the request and responses.

This is for HTTP Method 'POST' only. If you want to configure for rest of the methods such as GET|DELETE|PUT, etc change the HTTP method as appropriate.

<http uri-template="https://localhost:9100/{uri.var.path}/{uri.var.name}" method="get">

Also this can be invoked and verified for https as well. However due to encription TCPMon cannot be use for monitoring. Tools such as Wireshark with Fidler might be helpful for HTTPS traffic analysing.

HTTP GET

<endpoint xmlns="http://ws.apache.org/ns/synapse" name="HttpEpGET">
   <http uri-template="http://localhost:9765/jaxrs_basic/services/customers/customerservice/customers/{uri.var.id}" method="get">
      <suspendOnFailure>
         <progressionFactor>1.0</progressionFactor>
      </suspendOnFailure>
      <markForSuspension>
         <retriesBeforeSuspension>0</retriesBeforeSuspension>
         <retryDelay>0</retryDelay>
      </markForSuspension>
   </http>
</endpoint>

<proxy xmlns="http://ws.apache.org/ns/synapse" name="JAXRS" transports="https,http" statistics="disable" trace="disable" startOnLoad="true">
   <target>
      <inSequence>
         <property name="messageType" value="application/xml" scope="axis2"/>
         <property name="ContentType" value="application/xml" scope="axis2"/>
         <property name="uri.var.id" expression="$body/Customer/id"/>
         <log level="full"/>
         <log level="custom">
            <property name="ID" expression="get-property('uri.var.id')"/>
            <property name="$body" expression="$body/Customer/id"/>
         </log>
         <send>
            <endpoint key="HttpEpGET"/>
         </send>
      </inSequence>
      <outSequence>
         <send/>
      </outSequence>
   </target>
   <description></description>
</proxy>


HTTP DELETE

The above endpoint method can be set to 'delete' to test the DELETE method.

HTTP PUT

<endpoint xmlns="http://ws.apache.org/ns/synapse" name="HttpEpPUT">
   <http uri-template="http://localhost:9765/jaxrs_basic/services/customers/customerservice/{uri.var.service}" method="put">
      <suspendOnFailure>
         <progressionFactor>1.0</progressionFactor>
      </suspendOnFailure>
      <markForSuspension>
         <retriesBeforeSuspension>0</retriesBeforeSuspension>
         <retryDelay>0</retryDelay>
      </markForSuspension>
   </http>
</endpoint>

<proxy xmlns="http://ws.apache.org/ns/synapse" name="JAXRSPUT" transports="https,http" statistics="disable" trace="disable" startOnLoad="true">
   <target>
      <inSequence>
         <property name="messageType" value="application/xml" scope="axis2"/>
         <property name="ContentType" value="application/xml" scope="axis2"/>
         <property name="uri.var.service" value="customers"/>
         <log level="full"/>
         <send>
            <endpoint key="HttpEpPUT"/>
         </send>
      </inSequence>
      <outSequence>
         <send/>
      </outSequence>
   </target>
   <description></description>
</proxy>

HTTP POST

 The above endpoint method can be set to 'post' to test the POST method.


References:
1. http://docs.wso2.org/wiki/display/ESB470/Using+REST+with+a+Proxy+Service
2. http://docs.wso2.org/wiki/display/AS501/JAX-RS+Basics

No comments: