Friday, October 30, 2009

Apache Asia Roadshow 2009 - Call For Presentations

The Apache Software Foundation together with Sri Lankan FOSS community invites you to submit a proposal for a presentation at APACHE ASIA ROADSHOW 2009. If you are a community member of any Apache projects or If you have worked with Apache projects or have a revolutionary idea on the use of an Apache project, then we would like to hear from you!

Please use the following link for submissions http://www.foss.lk/events/apacheasia09/cfp and the due date for submission is November 8th. APACHE ASIA ROADSHOW 2009 (Colombo) will be held in Colombo, Sri Lanka from December 3rd to 5th, 2009. For more details please visit FOSS.lk

Tuesday, October 27, 2009

Axis2 on embedded Jetty

In this week I tried to finalize the Axis2m Spring extension module by writing some integration test cases. For above purpose I used embedded Jetty server with Axis2 , this gave enough flexibility within test cases. There can be many possible approaches to use Axis2 with embedded Jetty server , here I have mentioned some of the approaches.

Using Jetty WebAppContext

One possible option is to use Jetty WebAppContext with Axis2 WAR based deployment approach.
        Server server = new Server(8080);
WebAppContext root = new WebAppContext();
root.setContextPath("/");
root.setResourceBase("/work/workspace/Jetty_Axis2/webapp1" );
server.setHandler(root);
server.start();

In here , webapp1/WEB-INF directory contains the repository for Axis2 and also have to define the AxisServlet in the web.xml file. The web.xml file should come under the webapp1/WEB-INF directory.


<servlet>
<servlet-name>AxisServlet</servlet-name>
<servlet-class>org.apache.axis2.transport.http.AxisServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>AxisServlet</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>

Another possible approach is define AxisServlet in the code level instead of web.xml file as shown below.
        Server server = new Server(8080);
WebAppContext root = new WebAppContext();
root.setContextPath("/");
root.addServlet( "org.apache.axis2.transport.http.AxisServlet","/services/*");
root.setResourceBase("/work/workspace/Jetty_Axis2/webapp2" );
server.setHandler(root);
server.start();

Here in the directory structure only noticeable change is you don't need to have web.xml file.

Using Jetty ServletHolder
Only required step for this approach is provide a Axis2 repository as an InitParameter for AxisServlet.
        Server server = new Server(8080);
Context root = new Context(server,"/",Context.SESSIONS);
ServletHolder holder=new ServletHolder(new AxisServlet());
root.addServlet(holder,"/services/*");
holder.setInitParameter("axis2.repository.path", "/work/workspace/Jetty_Axis2/webapp3");
server.start();

Further it is possible to set Axis2.xml also as an input parameter.

holder.setInitParameter("axis2.xml.path", "/work/workspace/Jetty_Axis2/webapp3/axis2.xml");

Since my test cases dependent of Spring ,It was a requirement to add ContextLoaderListener as a ServletListener. It's again required only few lines of codes for this enhancement.
        Server server = new Server(8080);
Context root = new Context(server,"/",Context.SESSIONS);
ServletHolder holder=new ServletHolder(new AxisServlet());
root.addServlet(holder,"/services/*");
holder.setInitParameter("axis2.repository.path", "/work/workspace/Jetty_Axis2/webapp3");
root.getInitParams().put("contextConfigLocation","Module-app-test.xml");
root.setResourceBase("/work/workspace/Jetty_Axis2/webapp3");
root.addEventListener(new ContextLoaderListener());
server.start();