Sunday, September 12, 2010

How to debug a portlet in GateIn !!

Lately I have  seen few questions on how to use an IDE to develop and debug a portlet in GateIn user forum. The simplest answer is: it's similar to how you develop and debug a regular (jsp, servlet, jsf etc) web application. But I am going to walk you through one example of doing the same using plain Eclipse (or JBoss Tools ) and GateIn Portal using remote debugging of the upcoming Jasper portlet that is still a work in progress.

1. Import or create a project in eclipse

Nothing much to add here..it's like any standard java project. You can see further details for creating a new project at http://docs.jboss.org/tools/whatsnew/portlet/portlet-news-1.0.0.Alpha1.html In this example, I am going to import the mavenized jasper project from http://anonsvn.jboss.org/repos/qa/people/vrockai/jasper-sample-portlet/

2. Deploy the portlet into GateIn

Since this is a maven project, doing a maven install will create a .war file which we will deploy or copy to $GATEIN_HOME/server/default/deploy.

3. Preapre GateIn for debugging
Uncomment JPDA section for remote socket debugging in $GATEIN_HOME/bin/run.conf

JAVA_OPTS="$JAVA_OPTS -Xrunjdwp:transport=dt_socket, address=8787, server=y,suspend=n"


Please note the port number here. You can change it if you have any conflict on that port.

4. Start GateIn
You simply do "bash run.sh" on Linux/Unix or run.bat on Windows.

5. Hook up Eclipse with GateIn server
 In eclipse, select Run->Debug Configurations->Remote Java application and click on "New Launch Configuration Icon" which should show the following screen. Please change the port number from Step 3.
Click Debug. You should not get an error if eclipse is able to connect to the socket on port 8787.

6. Add portlet to a page
As of GateIn 3.1.0, there is no "simple" way of adding a portlet to a page using XML similar to how it was in JBoss Portal so we are going to use GateIn's user interface to do that. You can see how to do that at http://docs.jboss.com/gatein/portal/3.1.0-FINAL/user-guide/en-US/html_single/index.html#chap-User_Guide-Portal_Administration Please ask in user forum if you need help with this. In my case, I added this to home page. I can see the portlet when I visit the home page. However since we did not put any break point, eclispe does not care at this point

7.  Add a break point

I am going to add a break point on the first line of code in doView method of JasperPortlet class knowing that this method is always going to be called for normal viewing of this portlet.

8. See it in action

Let's refresh the page which should call doView method again and eclipse should prompt me to go to Debug perspective. Here is screenshot.

Happy debugging.
------------------
Please help me in my effort of computer literacy in Nepal at http://www.eejot.org

No comments: