Showing posts with label Synapse. Show all posts
Showing posts with label Synapse. Show all posts

Wednesday, October 15, 2008

Apache Synapse/WSO2 ESB calling a REST Endpoint

One of the features of Apache Synapse and the WSO2 ESB (Which is Apache Synapse + Monitoring + Management + WSO2 Registry Integration) is that it can change message formats.

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="http://ws.apache.org/ns/synapse">

<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="http://localhost:7763/services/keith/test/foo"/>

</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="http://www.w3.org/2003/05/soap-envelope">

<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

Thursday, September 25, 2008

HTTP Content Negotiation with Apache Axis2

Since the 1.3 release of Axis2, it supports HTTP Content Negotiation. It is not turned on by default but can be done so by adding the following parameter to your axis2.xml.

<parameter name="httpContentNegotiation">true</parameter>

Axis2 does not honor the content-type text/xml when its in the Accept Header. This is because the content-type text/xml is primarily used for SOAP 1.1 but when a request is sent via the browser it has the Accept header as "Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5 ". If we were to honor text/xml this would result in a SOAP 1.1 response. Not too good for a REST scenario ha! This is the result of the same content-type (text/xml) been used for two message formats (SOAP 1.1 and POX).

Now lets get back to HTTP Content Negotiation with Apache Axis2. Performing a GET request on the version service would result in the following request and response. You could capture them by using TCPMonitor.


Now try editing the Accept header to "application/json/badgerfish". You should have enabled JSON support for this to work. This would result in,


A blog post on how to enable JSON on Axis2 will follow. This configuration can be used to enable HTTP Content Negotiation on WSO2 WSAS as well as the Mashup Server. It should work with Synapse and the WSO2 ESB too but I haven't checked it.

Saturday, June 28, 2008

Learn About The Fastest Enterprise Service Bus (ESB) Around

You may have already seen how fast the WSO2 Enterprise service Bus (ESB) is. Want to learn how to use this ultra fast, light-weight and versatile Enterprise Service Bus (ESB) powered by the Apache Synapse ESB?

Well we got an answer for you. Join our free webinar series this July. There will be four webinars in total ranging from an "Introduction to the WSO2 ESB" to more advanced scenarios such as "Using the WSO2 ESB and FIX - supporting Financial messaging".

FIX support is the latest addition to the WSO2 ESB which is available in the recently released 1.7 version. This series of webinars will be presented by Paul Fremantle, CTO at WSO2 together with Asankha Perera ( ESB Architect), Asanka Abeysinghe (Architect) and Ruwan Linton (Senior Software Engineer).