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 WebAppContextOne 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 ServletHolderOnly 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();