There was a question on the ESB-USER mailing list recently asking how you could receive a SOAP message and send out a REST message (HTTP POST serialized as application/x-www-form-urlencoded) to another service. In order to do this you simply need to set two properties on the message. The HTTP_Method to be used and the messageType to be used. The following is a complete synapse.xml
- <syn:definitions xmlns:syn="<a href="http://ws.apache.org/ns/synapse">http://ws.apache.org/ns/synapse</a>">
- <syn:registry provider="org.wso2.esb.registry.ESBRegistry">
- <syn:parameter name="root">file:registry/</syn:parameter>
- </syn:registry>
- <syn:proxy name="RESTProxy" startOnLoad="true">
- <syn:target>
- <syn:endpoint name="RESTEndpoint">
- <syn:address uri="<a href="http://localhost:7763/services/keith/test/foo">http://localhost:7763/services/keith/test/foo</a>"/>
- </syn:endpoint>
- <syn:inSequence>
- <syn:property name="messageType" value="application/x-www-form-urlencoded" scope="axis2"/>
- <syn:property name="HTTP_METHOD" value="post" scope="axis2"/>
- </syn:inSequence>
- </syn:target>
- </syn:proxy>
- <syn:sequence name="main">
- <syn:send/>
- </syn:sequence>
- <syn:sequence name="fault">
- <syn:log/>
- </syn:sequence>
- </syn:definitions>
Here is the request sent into the ESB:
- POST /soap/RESTProxy/mediate HTTP/1.1
- Content-Type: application/soap+xml; charset=UTF-8; action="urn:anonOutInOp"
- User-Agent: WSO2 Mashup Server - Version 1.5.1
- Host: 127.0.0.1
- Content-Length: 191
- <?xml version='1.0' encoding='UTF-8'?>
- <soapenv:Envelope xmlns:soapenv="<a href="http://www.w3.org/2003/05/soap-envelope">http://www.w3.org/2003/05/soap-envelope</a>">
- <soapenv:Body>
- <foo>
- <param>keith</param>
- </foo>
- </soapenv:Body>
- </soapenv:Envelope>
Here is its response (or Request sent out to the REST service):
- POST http://localhost:7763/services/keith/test/foo HTTP/1.1
- Host: 127.0.0.1
- Content-Type: application/x-www-form-urlencoded; charset=UTF-8;action="urn:anonOutInOp";
- Transfer-Encoding: chunked
- Connection: Keep-Alive
- User-Agent: Synapse-HttpComponents-NIO
- b
- param=keith
- 0
1 comment:
Hi Keith,
What would I need to do if I want to receive POST from a form and send POST to the endpoint?
Thankyou
Post a Comment