Wednesday, July 31, 2013

WSO2 ESB - Reading query parametres from a GET request

If you need to read query parameters from a GET request which received by a proxy service / REST API, you can use following xpath expression to read values of those parameters.


example requesst :
GET http://localhost:8280/foo?a=1&b=2

and to log values of a and b

<log level="custom">
    <property name="VAL_a" expression="$url:a"/>
    <property name="VAL_b" expression="$url:b"/>

This xpath expression will be handy when working with REST integrations.

Wednesday, August 1, 2012

How to create simple mock services using WSO2 ESB

When you develop SOA systems, often you need to create mock services to simulate backend systems. Here is a easy way to create mock services using WSO2 ESB.

Create a proxy service in following format. Response of mock service will be content of payload factory mediator's format element.
<proxy xmlns="" name="MyMockProxy" transports="http https"
       startOnLoad="true" trace="disable">
                    <Response xmlns="">
            <header name="To" action="remove"/>
            <property name="RESPONSE" value="true" scope="default" type="STRING"/>
            <property name="NO_ENTITY_BODY" scope="axis2" action="remove"/>

Send a request to http://[your-ip]:8280/services/MyMockProxy and you will get

                    <Response xmlns="">

as the response!

Wednesday, June 20, 2012

java.lang.OutOfMemoryError: unable to create new native thread

You might encounter stack trace like:

java.lang.OutOfMemoryError: unable to create new native thread
        at java.lang.Thread.start0(Native Method)
        at java.lang.Thread.start(

 when your java code tries to spawn a new thread. It says OOM but probably it's not.

In Linux OS, there is a max allowed processes per user called "nproc" and if it's set to too low, JVM will fail to spawn a new thread and throw a OOM exception. 

You can check nproc by running following command

ulimit -u

and to change it

sudo vim /etc/security/limits.conf

and add following line with appropriate values.

{user_name} hard nproc {value}

Monday, March 5, 2012

Tracing message exchange in WSO2 ESB / Synapse

There might be situations where you need to trace the message on wire when working with WSO2 ESB/Synapse. You can use TCPMon to do is as I explained early[1], but it might be too complex and you might not able to trace messages if ESBs runs on remote servers (ESB is in your office, you are in home and connect to office via VPN).

Here is a simple solution:

Open lib/ of WSO2 ESB / Synapse instance and add
and you will be able to see wire level messages in log file.


Monday, February 20, 2012

Disable suspension of WSO2 ESB / Synapse Endpoint

The default behavior upon faulting a request of Synapse endpoint is, endpoint will suspend for 30000ms. During suspended time, synapse will not try to send further messages to suspended endpoint. However some deployment might need to turn off this behavior.

Here is a sample endpoint configuration which will never suspend for any error.

   <endpoint name="NoSuspendEndpoint">
       <address uri="http://localhost:9000/services/SimpleStockQuoteService">

Tuesday, September 27, 2011

Date Time addition using XSLT

I was searching in many places for a easy way to add dates using XSLT. Here is a sample that worked for me.
 <xsl:stylesheet xmlns:xsl=""  
   <xsl:output method="xml" omit-xml-declaration="yes" indent="yes"/>  
   <xsl:template match="/">  
     <expiryDate xmlns="">  
       <xsl:value-of select="fn:current-date()+xs:dayTimeDuration('P1D')"/>  

Sunday, November 21, 2010

How to monitor WSO2 ESB traffic using TCPMon

Here I will explain how to use TCPmon with WSO2 ESB to monitor incoming and outgoing traffic between Client,WSO2 ESB Proxy Service and WSO2 ESB Proxy Service,Backend service.

TCPmon is bundled with WSO2 ESB installation. So you do not need to download it. You can find TCPmon executable in <WSO2_ESB_Installation>/bin/ for Linux and <WSO2_ESB_Installation>/bin/tcpmon.bin for Windows.

You can find detailed TCPmon tutorial at [1].

I assume that you didn't changed default HTTP and HTTPS ports of WSO2 ESB which is 8280 for HTTP and 8243 for HTTPS.

To monitor HTTP traffic between client and WSO2 ESB.
  • Start TCPMon on machine runs WSO2 ESB
  • Goto Admin tab
  • Set Listen Port # as 8281 ( Assume that port 8281 is free on your system )
  • Leave Target Hostname as
  • Set Target Port # as 8280
  • Click Add
  • Goto Port 8281 tab

Now TCPmon is ready to capture traffic between client and WSO2 ESB.

When sending request to WSO2 ESB using client, use 8281 as the server port ( NOT 8280 ). So client will send request to 8281 which TCPmon runs and TCPmon will pass that request to WSO2 ESB which runs on 8280. You will able to monitor request/response transmitted between client and WSO2 ESB in TCPmon window.

To monitor HTTP traffic between WSO2 ESB and back-end service
  • Start TCPMon on machine runs WSO2 ESB
  • Goto Admin tab
  • Set Listen Port # as 8282 ( Assume that port 8282 is free on your system )
  • Set Target Hostname as hostname of machine that runs back-end service
  • Set Target Port # as port number that back-end service runs
  • Click Add
  • Goto Port 8282 tab

Then you have to edit WSO2 ESB Proxy service configuration to send messages to TCPmon port 8282 runs on localhost.

To do that replace the hostname and port of endpoint url with localhost and 8282.
Eg: If back-end service url is http://myhost:8000/services/myservice , set endpoint url as http://localhost:8282/services/myservice

When WSO2 ESB sends a message to back-end service, WSO2 ESB will send message to TCPmon runs on localhost:8282 and TCPmon sends that message to actual back-end service (http://myhost:8000/services/myservice). You can monitor request/response transmitted between WSO2 ESB and back-end service in TCPmon window.

By following mentioned steps you can obtain wire level messages transmitted between Client,WSO2 ESB and WSO2 ESB,back-end service.


Sunday, October 3, 2010

WSO2 Rocks @ NBQSA 2010

NBQSA (National Best Quality Software Award) is a annual event that evaluate and award software developed in Sri Lanka.

In NBQSA 2010 WSO2 won four awards.

Tuesday, September 8, 2009

Extending Audio of Xen Virtual Machines

Extending audio of Xen Virtual Machines, is a research project done by me as a part of my university degree programme. With my system, it is possible to access audio device of remote Xen virtual machines. This is the abstract of that project published in UCSC research symposium book.
 Extending audio of Xen Virtual Machines
Desktop virtualization introduces a novel approach in managing user environments. Going beyond the traditional thin-client based computing environment, this approach provides superior management with higher security level, higher resource utilization, and power saving to user Desktop PCs, while providing users with new capabilities. Desktop virtualization isolates users from each other, giving each user a location, independent of their own customizable operating system instance, while allowing granular resource allocation and protection of users from application crashes and operating system faults caused by user activities.
User experience of virtualized desktop session is largely affected by capabilities of virtualization environment that hides virtualization context from the end user. With a good virtualization solution, end user will never feel any difference between virtual machine environment and normal physical machine environment. Providing this rich user experience is quite a tedious task for virtualization system and it is harder when virtual machine is deployed in a remote server. Xen virtualization platform is designed towards the enterprise level and large scale virtualization. Xen does not hence, provide rich user experience for desktop users especially for multimedia support. Further, if Xen virtual machine is deployed in a remote server, we can access Xen Virtual machine's video system by vnc viewer, without the possibility of being able to hear audio of Xen virtual machine.
        Design of the System
“Extending Audio of Xen Virtual Machines” is a research project that attempts to develop an audio system which allows remote users to access audio of remote Xen virtual machines. This system uses network transparent device model to create a solution. Therefore, we created a special audio device that was installed in Xen virtual machines that act as audio device of the virtual machine letting the audio data to be passed on to the remote client through the virtual audio device via network.
The main component of the system is the Virtual Audio Device (VAD) installed in Xen virtual machine (domU). It is a simple character device that supports open, read, write, ioctl and close system calls. This device driver replaces /dev/dsp node in Linux device directory. Since audio applications use /dev/dsp node to pass audio to sound device, our device driver is able to capture audio data written to audio hardware by applications. Data captured by VAD is in a raw audio format which is a device-independent format in representing audio data. Thus, we can directly play these captured audio files in a different computer, even with a different type of hardware configuration.
The audio data captured by VAD is sent to remote user host through a client-server network application. Server side (Network Audio Server) is deployed in Xen virtual machine and Client side (Network Audio Client) runs in remote user host. When remote user connects to Xen virtual machine through VNC or any other remote desktop protocol, client application running on the user host acquires the IP address of Xen VM and connects to server application running on the Xen VM. When an application running in Xen VM plays an audio, output is captured by the VAD and network audio server would consequently send the audio to the network audio client. Data received by Network Audio Client passes to /dev/dsp node in user host. Since the data is hardware independent, the same audio output would be reproduced similar to the audio output produced in Xen VM.
Current prototype only allows extending audio system of Xen VM. Yet, with some simple modifications to the design, it is possible to create many types of network transparent device systems. 

XML Parsing with Java

I'll explain about parsing XML with Java using a simple scenario.

Java has several XML parsers: DOM ( Document Object Model), SAX ( Simple API for XML ). The most important thing about the SAX parser is, it's an event based parser and it looks complex for a novice programmer ;-) . So I'll start with DOM parser.

For parsing I'll use a simple xml file ( Address_Book.xml ) that holds information about persons.
<?xml version="1.0" encoding="UTF-8"?>
 This xml file will parse by following Java code and print the content.

import javax.xml.parsers.*;
import org.w3c.dom.*;
import org.xml.sax.SAXException;

public class DomParse {

    public static void main(String args[]){
        File f = new File("Address_Book.xml");
        try {
            DocumentBuilder build = DocumentBuilderFactory.newInstance().newDocumentBuilder();
            Document doc = build.parse(f);

            NodeList nodes = doc.getElementsByTagName("entry");

            for (int i = 0; i < nodes.getLength(); i++) {
                Element element = (Element) nodes.item(i);

                String fname = getValue("firstName", element);
                String lname = getValue("lastName", element);
                String email = getValue("email", element);

                System.out.println("FirstName: " + fname);
                System.out.println("LastName: " + lname);
                System.out.println("email: " + email);                         }
        } catch (ParserConfigurationException ex) {
        } catch (IOException ex) {
        } catch (SAXException ex) {


    public static String getCharacterDataFromElement(Element e) {
        Node child = e.getFirstChild();
        if (child instanceof CharacterData) {
            CharacterData cd = (CharacterData) child;
            return cd.getData();
        return "?";

    public static String getValue(String val, Element rootElement) {
        NodeList node = rootElement.getElementsByTagName(val);
        Element ele = (Element) node.item(0);
        String txt = getCharacterDataFromElement(ele);
        return txt;

Tuesday, January 22, 2008

Sinhala Enabling in Ubuntu

Now you can Convert Ubuntu 7.10 Gutsy to Complete Sinhala enable system.

Steps to install sinhala in Ubuntu.

  • Install Sinhala fonts from ( Instructions will be there)
  • Download si.tar.gz from UCSC Sinhala unicode Group
  • Extract downloaded file to /usr/share/locale-langpack
  • Open /etc/environment with root privileges and change LANG="en_US.UTF-8" to LANG="si_LK.UTF-8" then save.
  • Restart the System and you'll in Sinhala.
  • To Change back to English, roll back the changes applied to /etc/environment and restart.