Wednesday, July 8, 2015


We are going to discuss on how we can handle HTTP GET methods with JMS Proxy services in WSO2. With this blog we are going to discuss following message flow.

Flow is like follows;

  • Client invokes an API defined in ESB
  • From the API it sends the message to a JMS queue specifying a "ReplyTo" queue
  • There is a JMS proxy consume message from the above queue 
  • After consuming message, it will invoke the backend and response will be sent back to JMS "Reply To" queue
  • Rest API will consume the message from that "Reply To" queue and send back the response to the client.

In order to have this flow working, you need to setup ActiveMQ with wso2 ESB. You can find the documentation to do it in this documentation page.

Lets see the API

<api xmlns="" name="WeatherAPI" context="/getQuote">
   <resource methods="POST GET" uri-template="/details?*">
         <property name="transport.jms.ContentTypeProperty" value="Content-Type" scope="axis2"></property>
            <property name="httpMethod" expression="get-property('axis2','HTTP_METHOD')"></property>
         <property name="HTTP_METHOD" expression="get-property('axis2','HTTP_METHOD')" scope="transport" type="STRING"></property>
               <address uri="jms:/SMSStore?transport.jms.ConnectionFactoryJNDIName=QueueConnectionFactory&java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory&java.naming.provider.url=tcp://localhost:61616&transport.jms.DestinationType=queue&transport.jms.ContentTypeProperty=Content-Type&transport.jms.ReplyDestination=SMSReceiveNotificationStore"></address>
         <property name="TRANSPORT_HEADERS" scope="axis2" action="remove"></property>

In the above API , there are few things to be focused on.
  • You can see that we are setting the HTTP_METHOD to a property extracted from the incoming message as follows.  By default, for HTTP POST method, API invocation works perfectly with out setting this property at the end. But If we are doing a HTTP GET , we need to obtain the HTTP method at the consumer side of the queue to invoke the back end with a http GET. So we are setting it here. 

<property name="HTTP_METHOD" expression="get-property('axis2','HTTP_METHOD')" scope="transport" type="STRING"></property>

  • In the endpoint of the send mediator we are setting up following information which you should have 
    • transport.jms.ContentTypeProperty=Content-Type  - We are saying that we are passing the content type in JMS transport
    • ransport.jms.ReplyDestination=SMSReceiveNotificationStore - We are saying that ESB is expecting a response to this queue for this request 

Then in the JMS proxy which we consume the message, it will look like follows.

<proxy xmlns=""
   <target faultSequence="fault">
         <property name="HTTP_METHOD" expression="$trp:HTTP_METHOD" scope="axis2"/>
               <address uri="http://localhost:8080/foo">
   <parameter name="transport.jms.ContentType">
   <parameter name="transport.jms.ConnectionFactory">myQueueConnectionFactory</parameter>
   <parameter name="transport.jms.DestinationType">queue</parameter>
   <parameter name="transport.jms.Destination">SMSStore</parameter>

In the above proxy configuration, you can see following line

 <property name="HTTP_METHOD" expression="$trp:HTTP_METHOD" scope="axis2"/>

In that , what we do is , we read the HTTP_METHOD we already set in previous API before sending the message to JMS Queue and now we are reading it from transport level property.  Then we are setting it to "HTTP_METHOD" property with the "axis2" scope.

With that it will be able to figure out the HTTP method to be used on invoking the actual endpoint.

After getting a response, this Proxy will send the reply to the "SMSReceiveNotificationStore" queue. Then it will consumed from the previous API and send back the response to the client.

This will be working perfectly for HTTP POST requests. If it is a HTTP GET Request , you need to do some additional changes from the client side and the server side.

Client Side Changes

  • We need to pass the content type from the client side as follows. You can set it as a header in SOAP UI
       contentType:  application/x-www-form-urlencoded

Server Side Changes
  • You need to change the builder and formatter for above content type in the axis2.xml file located in WSO2ESB/repository/conf/axis2 directory as follows. 


<messageFormatter contentType="application/x-www-form-urlencoded"


<messageBuilder contentType="application/x-www-form-urlencoded"


If you does not set above , there will be message building and formatting errors.

With this way you ll be able to get this working for GET http methods.

This is tested with WSO2 ESB 4.8.1 with it's latest patches and Apache Activemq 5.10.0

No comments:

Post a Comment