Ujjwal
Ujjwal

Reputation: 613

Invoking RESTful service from WSO2 ESB using method POST

I have a simple RESTful service that I want to expose as SOAP based Web Service using WSO2 ESB.

My simple RESTful service can be invoked like http://<<my system>>:8080/myapp/person/read As response, I get JSON data of the Person entity.

Problem: I am not able to pass parameters to the RESTful service. I am to strip the param value from the SOAP input, but don't know how to pass it to my RESTful; service using ESB.

I have configured the following in WSO2 ESB

<proxy xmlns="http://ws.apache.org/ns/synapse" name="PersonProxy" transports="https,http" statistics="enable" trace="enable" startOnLoad="true">
   <target>
      <inSequence>
         <property xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" name="PERSON_ID" expression="//soapenv:Body/person/id"/>
         <log level="full">
            <property name="PERSON_ID" expression="get-property('PERSON_ID')"/>
         </log>
         <filter xpath="//person">
            <then>
               <property name="REST_URL_POSTFIX" value="read" scope="axis2" type="STRING"/>
               <property name="HTTP_METHOD" value="POST" scope="axis2" type="STRING"/>
               <property name="id" expression="get-property('PERSON_ID')" scope="axis2" type="STRING"/>
               <property name="ContentType" value="application/x-www-form-urlencoded" scope="axis2" type="STRING"/>
            </then>
            <else/>
         </filter>
         <send>
            <endpoint>
               <address uri="http://<<my system>>:8080/myapp/person" format="rest"/>
            </endpoint>
         </send>
      </inSequence>
      <outSequence>
         <send/>
      </outSequence>
   </target>
   <description></description>
</proxy>

My SOAP request looks like following

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
   <soapenv:Header/>
   <soapenv:Body>
    <person>
      <id>3</id>
    </person>
   </soapenv:Body>
</soapenv:Envelope>

I have another RESTful service with GET method and id as part of the URL itself, and that works fine. The ESB config looks like

<property name="REST_URL_POSTFIX" expression="get-property('PERSON_ID')" scope="axis2" type="STRING"/>
<property name="HTTP_METHOD" value="GET" scope="axis2" type="STRING"/>

<endpoint>
    <address uri="http://<<my system>>:8080/cfs/person" format="rest"/>
</endpoint>

Appreciate any pointers or help.

Upvotes: 4

Views: 5380

Answers (2)

RaviU
RaviU

Reputation: 1213

You can also try using the HTTP Endpoint which is new in ESB 4.7.0. You can define a URI Template much like in the REST API. Populating the template variables is done via property mediators - so anything you can do with a property mediator can be used to define the endpoint URL during mediation run time.

Upvotes: 1

Nufail
Nufail

Reputation: 1598

If your service can be invoked as http://<<my system>>:8080/myapp/person/id, you can read the id from the SOAP request and send it using "REST_URL_POSTFIX" property as below.

<property name="REST_URL_POSTFIX" expression="//person/id" scope="axis2" type="STRING"/>

Take a look at this example which implements a similar scenario.

Upvotes: 2

Related Questions