Thursday, February 27, 2014

WSO2 ESB 4.8.1 - Remote debugging with IntelliJ IDEA

Apache Synapse is a light-weight ESB written in Java. It is commercially supported by WSO2 ESB which is based on Apache Synapse. In this post I'll describe how to configure IntelliJ IDEA to debug the Apache Synapse code base within WSO2 ESB.

First you need to checkout the code base from svn location by running the following command on terminal:

svn checkout 

After completing the checkout operation it is required to build this code base and configure it to the IDE (IntelliJ IDEA). Before building the project make sure following things.
  1. You got a live internet connection throughout the process to download the dependencies.
  2. You got Apache Maven and JDK installed in the system.
  3. Set the environment variable as follows to avoid Maven OutOfMemory error.      MAVEN_OPTS="-Xms768m -Xmx3072m -XX:MaxPermSize=1200m
To build the repository, first navigate in to the 2.1.2-wso2v4 directory through command line and run the following :

mvn clean install

This will also run all the unit tests. Then run:

mvn idea:idea 

to set up the repository as an IntelliJ IDEA project.

Now you can open the IDE (IntelliJ IDEA) and select 'File -> open' and navigate to the directory location. Now the directory will display as an IDEA project. Go ahead and open it.

Now select 'Run -> Edit Configurations...' in IDEA. In the pop up window select 'Add New Configuration' (the plus sign at the top left corner) and select 'Remote' from the drop down menu. Now give a meaningful name and save with the default configurations.

Now download the latest WSO2 ESB release (WSO2 ESB 4.8.1) from WSO2 website:

Extract it to a preferred location. Navigate to {Extracted Location}/wso2esb-4.8.1/bin through command line and run the following command:

sh -sn 150 --debug 5005

The ESB will start to listen to port 5005. Now go to IntelliJ IDEA and add a debug point to an appropriate location (I prefer to add the debug point to line 50 in the class as it is the method relevant to catching the SOAP packet that will be sent by the service). Then select " Run -> Debug 'SynapseESBServeDebug' " (The name will differ according to the name you have given to the remote debug configuration).

And now follow the WSO2 ESB documentation to run " ESB Sample 150: Introduction to Proxy Services " to run a sample proxy service. 

After your invoking the Axis2Client you will be able to see that the process has been paused at the break point that you have added earlier. Now your can use IntelliJIdea in the usual way to debug the code.