Sending a message from SMSC Simulator to WSO2 ESB using SMPP Transport

This post describes how a proxy service deployed in WSO2 ESB can be invoked using a SMS message sent from a SMSC.

Following steps will guide you through this process.

1) Please use the following SMS transport receiver in the <ESB_HOME>/repository/conf/axis2/axis2.xml to enable SMS receiving in the ESB.

<transportReceiver name="sms"
class="org.apache.axis2.transport.sms.SMSMessageReciever">

<parameter name="systemType">cp</parameter>
<parameter name="systemId">test</parameter>
<parameter name="password">test</parameter>
<parameter name="host">localhost</parameter>
<parameter name="port">2775</parameter>
<parameter name="phoneNumber">628176504657</parameter>
</transportReceiver>

2) Download axis2 SMPP transport jar from here and copy it to <ESB_HOME>/repository/components/lib folder.

3) Download JSMPP from [1] unzip it and copy the jsmpp-2.1.0.jar to <ESB_HOME>/repository/components/lib folder. JSMPP is a java implementation of the SMPP protocol which provides and API to communicate with the SMSC.

Now when you start the ESB server it is ready accept messages coming via the SMS trasnport on port 2775. Let’s have a look at how a SMSC simulator can be used to send SMS to the ESB.

4) Checkout open smpp source from [2] and build it with maven.

5) Create a new directory called SMSC and copy <OPENSMPP_SOURCE_HOME>/sim/target/opensmpp-sim-3.0.1-SNAPSHOT.jar and <OPENSMPP_SOURCE_HOME>/core/target/opensmpp-core-3.0.1-SNAPSHOT.jar into it.

6) Create a new directory SMSC/etc and copy the <OPENSMPP_SOURCE_HOME>/sim/users.txt into it.

7) Execute the following command from within the SMSC directory to start the SMSC.

java -cp ./opensmpp-core-3.0.1-SNAPSHOT.jar:opensmpp-sim-3.0.1-SNAPSHOT.jar org.smpp.smscsim.Simulator

8) you will get a command line program interface like the following when you run the simulator.

– 1 start simulation
– 2 stop simulation
– 3 list clients
– 4 send message
– 5 list messages
– 6 reload users file
– 7 log to screen off
– 0 exit
>

9) Start the simulator on port 2775 by selecting option 1.

10) Start the ESB and in the server startup logs you will see “[Axis2] bind and connect to localhost : 2775 on SMPP Transport” log if your ESB was able to successfully connect to the SMSC.

11) Create a passthrough proxy called smsTest and tick the sms transport from the Transports section in the proxy creation page.

<?xml version="1.0" encoding="UTF-8"?>

<proxy xmlns="http://ws.apache.org/ns/synapse"
name="smsTest"
transports="sms"
statistics="disable"
trace="disable"
startOnLoad="true">
<target>
<inSequence>
<log level="full"/>
</inSequence>
<outSequence/>
<endpoint>
<address uri="http://localhost:9000/services/SimpleStockQuoteService"/>
</endpoint>
</target>
</proxy>

 
12) Send message by selecting option 4 from the simulator. The message format is as follows according to [3].

SMS message format: proxy_service_name:action:name1=value1:name2=value2

e.g. smsTest:mediate

13) You can see that the proxy is triggered from the ESB logs.

You can build a message and send to any endpoint that you prefer from within the proxy.

[1] https://jsmpp.googlecode.com/files/jsmpp-2.1.0-bin.zip
[2] https://github.com/OpenSmpp/opensmpp
[3] https://axis.apache.org/axis2/java/transports/sms.html

Avoid conditional GET request issue with cache mediator in WSO2 ESB

I came across something interesting lately while playing with the WSO2 ESB cache mediator. Since this would be a very common scenario I thought of writing about it. Following is a small description about the problem and the solution.

When a browser sends a request for a certain resource the server replies with the resource with a HTTP ETag value (e.g. ETag: d9537e6b) header. This allows the browser to make conditional requests. The next time the browser sends a HTTP GET request to the same resource it will send a new HTTP header called If-None-Match (e.g. If-None-Match:d9537e6b). The server will only reply with the resource if only the resource has been changed in the server since the last request. This means that the server will only reply with the resource if the ETag value of the requested resource is different from the value sent in the  If-None-Match header. Otherwise the server will reply with a HTTP 304 Not Modified response.

So let’s analyze what happens when we use the cache mediator of the WSO2 ESB. The first time the browser sends a request to the back end service the service will respond and the response will be cached in the ESB. All the subsequent requests sent requesting the same resource will result in the response to be served to the browser from the cache. What happens when the ESB cache is expired? From the second request onwards the browser will add a new “If-None-Match” request to the HTTP request. This will result the server responding with “HTTP 304 Not Modified” if the resource has not been modified since the last request. This causes the ESB to cache an empty response since the “HTTP 304 Not Modified” does not have a response body.

Let’s consider the following REST API as a sample configuration in the ESB.

<api xmlns="http://ws.apache.org/ns/synapse" name="ArcGIS" context="/GeoCoding">
<resource methods="GET" uri-template="/GeoCode*">
<inSequence>
<property name="POST_TO_URI" value="true" scope="axis2" type="STRING"></property>
<property name="uri.var.format" expression="$ctx:query.param.format" scope="default" type="STRING"></property>
<property name="uri.var.address" expression="$ctx:query.param.address" scope="default" type="STRING"></property>
<log>
<property name="format" expression="get-property('uri.var.format')"></property>
<property name="address" expression="get-property('uri.var.address')"></property>
</log>
<cache id="arcGisSingleCache" scope="per-host" collector="false" hashGenerator="org.wso2.caching.digest.DOMHASHGenerator" timeout="100" maxMessageSize="1000000">
<implementation type="memory" maxSize="1000000"></implementation>
</cache>
<send>
<endpoint>
<http method="get" uri-template="http://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/find?text={uri.var.address}&f={uri.var.format}"></http>
</endpoint>
</send>
</inSequence>
<outSequence>
<cache id="arcGisSingleCache" scope="per-host" collector="true"></cache>
<log level="full"></log>
<send/>
</outSequence>
</resource>
</api>

We can invoke the above using the SOAP UI or the Advanced REST Client in the Google Chrome. Enable wire logs in the ESB to look at the wire level information.

Invoke the API by sending the following request.

http://localhost:8280/GeoCoding/GeoCode?address=seoul&format=json

If you look at the wire logs it will be something similar to the following.

TID: [0] [ESB] [2014-04-29 14:28:51,741] DEBUG {org.apache.synapse.transport.http.wire} - >> "GET /GeoCoding/GeoCode?address=seoul HTTP/1.1[\r][\n]" {org.apache.synapse.transport.http.wire}
TID: [0] [ESB] [2014-04-29 14:28:51,741] DEBUG {org.apache.synapse.transport.http.wire} - >> "Host: 162.44.168.228:8280[\r][\n]" {org.apache.synapse.transport.http.wire}
TID: [0] [ESB] [2014-04-29 14:28:51,741] DEBUG {org.apache.synapse.transport.http.wire} - >> "Connection: keep-alive[\r][\n]" {org.apache.synapse.transport.http.wire}
TID: [0] [ESB] [2014-04-29 14:28:51,742] DEBUG {org.apache.synapse.transport.http.wire} - >> "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8[\r][\n]" {org.apache.synapse.transport.http.wire}
TID: [0] [ESB] [2014-04-29 14:28:51,742] DEBUG {org.apache.synapse.transport.http.wire} - >> "User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.116 Safari/537.36[\r][\n]" {org.apache.synapse.transport.http.wire}
TID: [0] [ESB] [2014-04-29 14:28:51,742] DEBUG {org.apache.synapse.transport.http.wire} - >> "Accept-Encoding: gzip,deflate,sdch[\r][\n]" {org.apache.synapse.transport.http.wire}
TID: [0] [ESB] [2014-04-29 14:28:51,742] DEBUG {org.apache.synapse.transport.http.wire} - >> "Accept-Language: en-US,en;q=0.8[\r][\n]" {org.apache.synapse.transport.http.wire}
TID: [0] [ESB] [2014-04-29 14:28:51,742] DEBUG {org.apache.synapse.transport.http.wire} - >> "[\r][\n]" {org.apache.synapse.transport.http.wire}
TID: [0] [ESB] [2014-04-29 14:28:51,749] INFO {org.apache.synapse.mediators.builtin.LogMediator} - format = json, address = seoul {org.apache.synapse.mediators.builtin.LogMediator}
TID: [0] [ESB] [2014-04-29 14:28:51,754] INFO {org.apache.synapse.mediators.builtin.LogMediator} - To: /GeoCoding/GeoCode?address=seoul, MessageID: urn:uuid:773bf9f5-ff71-434e-9d65-807d3cb29b65, Direction: request, Envelope: <?xml version="1.0" encoding="utf-8"?><soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope"><soapenv:Body></soapenv:Body></soapenv:Envelope> {org.apache.synapse.mediators.builtin.LogMediator}
TID: [0] [ESB] [2014-04-29 14:28:51,764] DEBUG {org.apache.synapse.transport.http.wire} - << "GET http://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/find?text=seoul&f=json HTTP/1.1[\r][\n]" {org.apache.synapse.transport.http.wire}
TID: [0] [ESB] [2014-04-29 14:28:51,765] DEBUG {org.apache.synapse.transport.http.wire} - << "Accept-Language: en-US,en;q=0.8[\r][\n]" {org.apache.synapse.transport.http.wire}
TID: [0] [ESB] [2014-04-29 14:28:51,765] DEBUG {org.apache.synapse.transport.http.wire} - << "Accept-Encoding: gzip,deflate,sdch[\r][\n]" {org.apache.synapse.transport.http.wire}
TID: [0] [ESB] [2014-04-29 14:28:51,765] DEBUG {org.apache.synapse.transport.http.wire} - << "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8[\r][\n]" {org.apache.synapse.transport.http.wire}
TID: [0] [ESB] [2014-04-29 14:28:51,766] DEBUG {org.apache.synapse.transport.http.wire} - << "Host: geocode.arcgis.com:80[\r][\n]" {org.apache.synapse.transport.http.wire}
TID: [0] [ESB] [2014-04-29 14:28:51,766] DEBUG {org.apache.synapse.transport.http.wire} - << "Connection: Keep-Alive[\r][\n]" {org.apache.synapse.transport.http.wire}
TID: [0] [ESB] [2014-04-29 14:28:51,766] DEBUG {org.apache.synapse.transport.http.wire} - << "User-Agent: Synapse-PT-HttpComponents-NIO[\r][\n]" {org.apache.synapse.transport.http.wire}
TID: [0] [ESB] [2014-04-29 14:28:51,767] DEBUG {org.apache.synapse.transport.http.wire} - << "[\r][\n]" {org.apache.synapse.transport.http.wire}
TID: [0] [ESB] [2014-04-29 14:28:52,164] DEBUG {org.apache.synapse.transport.http.wire} - >> "HTTP/1.1 200 OK[\r][\n]" {org.apache.synapse.transport.http.wire}
TID: [0] [ESB] [2014-04-29 14:28:52,164] DEBUG {org.apache.synapse.transport.http.wire} - >> "Via: 1.1 CDTSTMG02[\r][\n]" {org.apache.synapse.transport.http.wire}
TID: [0] [ESB] [2014-04-29 14:28:52,164] DEBUG {org.apache.synapse.transport.http.wire} - >> "Connection: Keep-Alive[\r][\n]" {org.apache.synapse.transport.http.wire}
TID: [0] [ESB] [2014-04-29 14:28:52,165] DEBUG {org.apache.synapse.transport.http.wire} - >> "Proxy-Connection: Keep-Alive[\r][\n]" {org.apache.synapse.transport.http.wire}
TID: [0] [ESB] [2014-04-29 14:28:52,165] DEBUG {org.apache.synapse.transport.http.wire} - >> "Transfer-Encoding: chunked[\r][\n]" {org.apache.synapse.transport.http.wire}
TID: [0] [ESB] [2014-04-29 14:28:52,165] DEBUG {org.apache.synapse.transport.http.wire} - >> "Date: Tue, 29 Apr 2014 18:28:52 GMT[\r][\n]" {org.apache.synapse.transport.http.wire}
TID: [0] [ESB] [2014-04-29 14:28:52,165] DEBUG {org.apache.synapse.transport.http.wire} - >> "Content-Type: text/plain;charset=utf-8[\r][\n]" {org.apache.synapse.transport.http.wire}
TID: [0] [ESB] [2014-04-29 14:28:52,165] DEBUG {org.apache.synapse.transport.http.wire} - >> "ETag: d9537e6b[\r][\n]" {org.apache.synapse.transport.http.wire}
TID: [0] [ESB] [2014-04-29 14:28:52,166] DEBUG {org.apache.synapse.transport.http.wire} - >> "Server: [\r][\n]" {org.apache.synapse.transport.http.wire}
TID: [0] [ESB] [2014-04-29 14:28:52,166] DEBUG {org.apache.synapse.transport.http.wire} - >> "Cache-Control: max-age=0,must-revalidate[\r][\n]" {org.apache.synapse.transport.http.wire}
TID: [0] [ESB] [2014-04-29 14:28:52,166] DEBUG {org.apache.synapse.transport.http.wire} - >> "Set-Cookie: AGS_ROLES="419jqfa+uOZgYod4xPOQ8Q=="; Version=1; Max-Age=60; Expires=Tue, 29-Apr-2014 18:30:02 GMT; Path=/arcgis/rest; HttpOnly[\r][\n]" {org.apache.synapse.transport.http.wire}
TID: [0] [ESB] [2014-04-29 14:28:52,166] DEBUG {org.apache.synapse.transport.http.wire} - >> "[\r][\n]" {org.apache.synapse.transport.http.wire}
TID: [0] [ESB] [2014-04-29 14:28:52,168] DEBUG {org.apache.synapse.transport.http.wire} - >> "143[\r][\n]" {org.apache.synapse.transport.http.wire}
TID: [0] [ESB] [2014-04-29 14:28:52,168] DEBUG {org.apache.synapse.transport.http.wire} - >> "{"spatialReference":{"wkid":4326,"latestWkid":4326},"locations":[{"name":"Seoul, Seoul, South Korea","extent":{"xmin":126.85532000000001,"ymin":37.456209999999999,"xmax":127.1934,"ymax":37.705689999999997},"feature":{"geometry":{"x":126.97782765600061,"y":37.56825582300047},"attributes":{"Score":100,"Addr_Type":"POI"}}}]}[\r][\n]" {org.apache.synapse.transport.http.wire}
TID: [0] [ESB] [2014-04-29 14:28:52,168] DEBUG {org.apache.synapse.transport.http.wire} - >> "0[\r][\n]" {org.apache.synapse.transport.http.wire}
TID: [0] [ESB] [2014-04-29 14:28:52,168] DEBUG {org.apache.synapse.transport.http.wire} - >> "[\r][\n]" {org.apache.synapse.transport.http.wire}
TID: [0] [ESB] [2014-04-29 14:28:52,207] INFO {org.apache.synapse.mediators.builtin.LogMediator} - GEO API = RESPONSE {org.apache.synapse.mediators.builtin.LogMediator}
TID: [0] [ESB] [2014-04-29 14:28:52,209] INFO {org.apache.synapse.mediators.builtin.LogMediator} - To: http://www.w3.org/2005/08/addressing/anonymous, WSAction: , SOAPAction: , MessageID: urn:uuid:4a2d34ea-cf46-4e4e-8bec-aee1a3936c3b, Direction: response, MESSAGE = INCOMING, Envelope: <?xml version="1.0" encoding="utf-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><text xmlns="http://ws.apache.org/commons/ns/payload">{"spatialReference":{"wkid":4326,"latestWkid":4326},"locations":[{"name":"Seoul, Seoul, South Korea","extent":{"xmin":126.85532000000001,"ymin":37.456209999999999,"xmax":127.1934,"ymax":37.705689999999997},"feature":{"geometry":{"x":126.97782765600061,"y":37.56825582300047},"attributes":{"Score":100,"Addr_Type":"POI"}}}]}</text></soapenv:Body></soapenv:Envelope> {org.apache.synapse.mediators.builtin.LogMediator}

 

Notice the “ETag: d9537e6b” header sent with the response. After some time when the cache cache expires if we send another request to the ESB the logs would look like the following. (Since we are using the SOAP UI or the Advanced REST Client please add a new “If-None-Match:d9537e6b” HTTP header to simulate the browser behavior).

TID: [0] [ESB] [2014-04-29 14:29:10,610] DEBUG {org.apache.synapse.transport.http.wire} - >> "GET /GeoCoding/GeoCode?address=seoul HTTP/1.1[\r][\n]" {org.apache.synapse.transport.http.wire}
TID: [0] [ESB] [2014-04-29 14:29:10,610] DEBUG {org.apache.synapse.transport.http.wire} - >> "Host: 162.44.168.228:8280[\r][\n]" {org.apache.synapse.transport.http.wire}
TID: [0] [ESB] [2014-04-29 14:29:10,610] DEBUG {org.apache.synapse.transport.http.wire} - >> "Connection: keep-alive[\r][\n]" {org.apache.synapse.transport.http.wire}
TID: [0] [ESB] [2014-04-29 14:29:10,611] DEBUG {org.apache.synapse.transport.http.wire} - >> "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8[\r][\n]" {org.apache.synapse.transport.http.wire}
TID: [0] [ESB] [2014-04-29 14:29:10,611] DEBUG {org.apache.synapse.transport.http.wire} - >> "User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.116 Safari/537.36[\r][\n]" {org.apache.synapse.transport.http.wire}
TID: [0] [ESB] [2014-04-29 14:29:10,611] DEBUG {org.apache.synapse.transport.http.wire} - >> "Accept-Encoding: gzip,deflate,sdch[\r][\n]" {org.apache.synapse.transport.http.wire}
TID: [0] [ESB] [2014-04-29 14:29:10,611] DEBUG {org.apache.synapse.transport.http.wire} - >> "Accept-Language: en-US,en;q=0.8[\r][\n]" {org.apache.synapse.transport.http.wire}
TID: [0] [ESB] [2014-04-29 14:29:10,611] DEBUG {org.apache.synapse.transport.http.wire} - >> "If-None-Match: d9537e6b[\r][\n]" {org.apache.synapse.transport.http.wire}
TID: [0] [ESB] [2014-04-29 14:29:10,612] DEBUG {org.apache.synapse.transport.http.wire} - >> "[\r][\n]" {org.apache.synapse.transport.http.wire}
TID: [0] [ESB] [2014-04-29 14:29:10,625] INFO {org.apache.synapse.mediators.builtin.LogMediator} - format = json, address = colombo {org.apache.synapse.mediators.builtin.LogMediator}
TID: [0] [ESB] [2014-04-29 14:29:10,629] INFO {org.apache.synapse.mediators.builtin.LogMediator} - To: /GeoCoding/GeoCode?address=colombo, MessageID: urn:uuid:a784dda4-faa5-4a82-8758-111f4b8cd330, Direction: request, Envelope: <?xml version="1.0" encoding="utf-8"?><soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope"><soapenv:Body></soapenv:Body></soapenv:Envelope> {org.apache.synapse.mediators.builtin.LogMediator}
TID: [0] [ESB] [2014-04-29 14:29:10,636] DEBUG {org.apache.synapse.transport.http.wire} - << "GET http://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/find?text=colombo&f=json HTTP/1.1[\r][\n]" {org.apache.synapse.transport.http.wire}
TID: [0] [ESB] [2014-04-29 14:29:10,637] DEBUG {org.apache.synapse.transport.http.wire} - << "Accept-Language: en-US,en;q=0.8[\r][\n]" {org.apache.synapse.transport.http.wire}
TID: [0] [ESB] [2014-04-29 14:29:10,637] DEBUG {org.apache.synapse.transport.http.wire} - << "Accept-Encoding: gzip,deflate,sdch[\r][\n]" {org.apache.synapse.transport.http.wire}
TID: [0] [ESB] [2014-04-29 14:29:10,637] DEBUG {org.apache.synapse.transport.http.wire} - << "If-None-Match: d9537e6b[\r][\n]" {org.apache.synapse.transport.http.wire}
TID: [0] [ESB] [2014-04-29 14:29:10,637] DEBUG {org.apache.synapse.transport.http.wire} - << "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8[\r][\n]" {org.apache.synapse.transport.http.wire}
TID: [0] [ESB] [2014-04-29 14:29:10,637] DEBUG {org.apache.synapse.transport.http.wire} - << "Host: geocode.arcgis.com:80[\r][\n]" {org.apache.synapse.transport.http.wire}
TID: [0] [ESB] [2014-04-29 14:29:10,637] DEBUG {org.apache.synapse.transport.http.wire} - << "Connection: Keep-Alive[\r][\n]" {org.apache.synapse.transport.http.wire}
TID: [0] [ESB] [2014-04-29 14:29:10,637] DEBUG {org.apache.synapse.transport.http.wire} - << "User-Agent: Synapse-PT-HttpComponents-NIO[\r][\n]" {org.apache.synapse.transport.http.wire}
TID: [0] [ESB] [2014-04-29 14:29:10,638] DEBUG {org.apache.synapse.transport.http.wire} - << "[\r][\n]" {org.apache.synapse.transport.http.wire}
TID: [0] [ESB] [2014-04-29 14:29:10,973] DEBUG {org.apache.synapse.transport.http.wire} - >> "HTTP/1.1 304 Not Modified[\r][\n]" {org.apache.synapse.transport.http.wire}
TID: [0] [ESB] [2014-04-29 14:29:10,974] DEBUG {org.apache.synapse.transport.http.wire} - >> "Via: 1.1 CDTSTMG02[\r][\n]" {org.apache.synapse.transport.http.wire}
TID: [0] [ESB] [2014-04-29 14:29:10,974] DEBUG {org.apache.synapse.transport.http.wire} - >> "Connection: Keep-Alive[\r][\n]" {org.apache.synapse.transport.http.wire}
TID: [0] [ESB] [2014-04-29 14:29:10,974] DEBUG {org.apache.synapse.transport.http.wire} - >> "Proxy-Connection: Keep-Alive[\r][\n]" {org.apache.synapse.transport.http.wire}
TID: [0] [ESB] [2014-04-29 14:29:10,975] DEBUG {org.apache.synapse.transport.http.wire} - >> "Date: Tue, 29 Apr 2014 18:29:10 GMT[\r][\n]" {org.apache.synapse.transport.http.wire}
TID: [0] [ESB] [2014-04-29 14:29:10,975] DEBUG {org.apache.synapse.transport.http.wire} - >> "Age: 0[\r][\n]" {org.apache.synapse.transport.http.wire}
TID: [0] [ESB] [2014-04-29 14:29:10,975] DEBUG {org.apache.synapse.transport.http.wire} - >> "[\r][\n]" {org.apache.synapse.transport.http.wire}
TID: [0] [ESB] [2014-04-29 14:29:10,983] INFO {org.apache.synapse.mediators.builtin.LogMediator} - GEO API = RESPONSE {org.apache.synapse.mediators.builtin.LogMediator}
TID: [0] [ESB] [2014-04-29 14:29:10,984] INFO {org.apache.synapse.mediators.builtin.LogMediator} - To: http://www.w3.org/2005/08/addressing/anonymous, WSAction: , SOAPAction: , MessageID: urn:uuid:d79666e6-b6e1-4ccd-972c-a8cac419e1ef, Direction: response, MESSAGE = INCOMING, Envelope: <?xml version="1.0" encoding="utf-8"?><soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope"><soapenv:Body></soapenv:Body></soapenv:Envelope> {org.apache.synapse.mediators.builtin.LogMediator}
TID: [0] [ESB] [2014-04-29 14:29:10,989] DEBUG {org.apache.synapse.transport.http.wire} - << "HTTP/1.1 304 Not Modified[\r][\n]" {org.apache.synapse.transport.http.wire}
TID: [0] [ESB] [2014-04-29 14:29:10,989] DEBUG {org.apache.synapse.transport.http.wire} - << "Age: 0[\r][\n]" {org.apache.synapse.transport.http.wire}
TID: [0] [ESB] [2014-04-29 14:29:10,989] DEBUG {org.apache.synapse.transport.http.wire} - << "Via: 1.1 CDTSTMG02[\r][\n]" {org.apache.synapse.transport.http.wire}
TID: [0] [ESB] [2014-04-29 14:29:10,989] DEBUG {org.apache.synapse.transport.http.wire} - << "Content-Type: application/xml[\r][\n]" {org.apache.synapse.transport.http.wire}
TID: [0] [ESB] [2014-04-29 14:29:10,990] DEBUG {org.apache.synapse.transport.http.wire} - << "Proxy-Connection: Keep-Alive[\r][\n]" {org.apache.synapse.transport.http.wire}
TID: [0] [ESB] [2014-04-29 14:29:10,990] DEBUG {org.apache.synapse.transport.http.wire} - << "Date: Tue, 29 Apr 2014 18:29:10 GMT[\r][\n]" {org.apache.synapse.transport.http.wire}
TID: [0] [ESB] [2014-04-29 14:29:10,990] DEBUG {org.apache.synapse.transport.http.wire} - << "Server: WSO2-PassThrough-HTTP[\r][\n]" {org.apache.synapse.transport.http.wire}
TID: [0] [ESB] [2014-04-29 14:29:10,990] DEBUG {org.apache.synapse.transport.http.wire} - << "Transfer-Encoding: chunked[\r][\n]" {org.apache.synapse.transport.http.wire}
TID: [0] [ESB] [2014-04-29 14:29:10,990] DEBUG {org.apache.synapse.transport.http.wire} - << "Connection: keep-alive[\r][\n]" {org.apache.synapse.transport.http.wire}
TID: [0] [ESB] [2014-04-29 14:29:10,990] DEBUG {org.apache.synapse.transport.http.wire} - << "[\r][\n]" {org.apache.synapse.transport.http.wire}
TID: [0] [ESB] [2014-04-29 14:29:10,991] DEBUG {org.apache.synapse.transport.http.wire} - << "0[\r][\n]" {org.apache.synapse.transport.http.wire}
TID: [0] [ESB] [2014-04-29 14:29:10,991] DEBUG {org.apache.synapse.transport.http.wire} - << "[\r][\n]" {org.apache.synapse.transport.http.wire}

You can see that the ESB is sending the request to the back end service with the “If-None-Match” header and the server has replied with a  “HTTP/1.1 304 Not Modified” with an empty response body. This now gets cached in the ESB. All the similar subsequent requests will result in an empty ressponse retrieved from the cache.

So how to avoid this from happening?

The answer is very simple. We may drop a “If-None-Match” header if there is any when we send it to the back end server. We can use the header mediator to achieve this before the cache mediator.

<header name="If-None-Match" scope="transport" action="remove"/>

<cache id=”arcGisSingleCache”
scope=”per-host”
collector=”false”
hashGenerator=”org.wso2.caching.digest.DOMHASHGenerator”
timeout=”60″
maxMessageSize=”1000000″>
<implementation type=”memory” maxSize=”1000000″/>

This will cause the back end server to treat the incoming request as a new request which does not know anything about the requested resource. Hence the server will always reply with the correct response having a body and it will be cached in the ESB so that all the requests will be served with the correct resource.

Hope this will be helpful.