Calling a RESTful service from a WSO2 ESB using the POST method

I have a simple RESTful service that I want to publish as a SOAP-based web service using the WSO2 ESB.

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

Problem: I cannot pass parameters to the RESTful service. I have to remove the parameter value from SOAP input, but donโ€™t know how to pass it to my RESTful; using ESB.

I installed the following in a 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 is as follows

 <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 a GET and id method as part of the url itself, and this works fine. ESB configuration 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.

+4
source share
2 answers

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

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

See this example that implements a similar scenario.

+2
source

You can also try using the HTTP endpoint , which is new in ESB 4.7.0. The URI pattern can be defined in the same way as in the REST API. Template variables are populated with property brokers - so anything you can do with the property broker can be used to determine the endpoint URL during mediation.

+1
source

Source: https://habr.com/ru/post/1487616/


All Articles