0

Some background:

I'm trying to use SSL mutual authentication for some Axis2 services we're exposing. The problem is that Axis2 built-in server doesn't support that. So I want to use embedded Jetty to achieve that and deploy the AxisServlet in it.

Problem:

There seems to be no way of passing the AxisConfiguration (containing the definition of all the available services) to the servlet directly.

How I'm trying to do it:

ConfigurationContext context = ConfigurationContextFactory.createDefaultConfigurationContext();

File serviceArchiveFile = new File("<path to my aar file which is loaded properly>");
AxisServiceGroup serviceGroup = DeploymentEngine.loadServiceGroup(serviceArchiveFile, context);

AxisConfiguration axiConfiguration = context.getAxisConfiguration();
axiConfiguration.addServiceGroup(serviceGroup);

AxisServlet axisServlet = new AxisServlet();

Server server = new Server(8080);
org.mortbay.jetty.servlet.Context root = new org.mortbay.jetty.servlet.Context(server,"/",org.mortbay.jetty.servlet.Context.SESSIONS);
ServletHolder holder=new ServletHolder(axisServlet);

// Trying to pass the Config context via the parameters map
Map parameters = new HashMap();
parameters.put(AxisServlet.CONFIGURATION_CONTEXT, context);
holder.setInitParameters(parameters);

root.addServlet(holder,"/services/*");

server.start();

The problem with that approach is that the init(ServletConfig) method of the AxisServlet is never call so I get a nullPointer exception whenever I try to call the service on 8080:

java.lang.NullPointerException
  at org.apache.axis2.transport.http.AxisServlet.initContextRoot(AxisServlet.java:586)
  at org.apache.axis2.transport.http.AxisServlet.preprocessRequest(AxisServlet.java:605)
  at org.apache.axis2.transport.http.AxisServlet.doGet(AxisServlet.java:241)
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
  at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:442)
  at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:356)
  at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:226)
  at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:615)
  at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:141)
  at org.mortbay.jetty.Server.handle(Server.java:265)
  at org.mortbay.jetty.HttpConnection.handlerRequest(HttpConnection.java:420)
  at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:666)
  at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:487)
  at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:197)
  at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:336)
  at org.mortbay.jetty.bio.SocketConnector$Connection.run(SocketConnector.java:183)
  at org.mortbay.thread.BoundedThreadPool$PoolThread.run(BoundedThreadPool.java:475)

According to Axis2 source code, this happens because the config context is never set in the AxisServlet. So now the big questions are:

1) Is that possible to set the config context directly in AxisServlet? I didn't find any way of doing so

2) Why is Jetty not sending the init paremeters and not calling the init(ServletConfig config) method on the servlet? I confirmed with debugger that it is never called.

2 Answers2

1

If you want to load Configuration context, You can try loading Configuration Context directly from file system as below.

ConfigurationContext myConfigContext = ConfigurationContextFactory.createConfigurationContextFromFileSystem("", "absolute path to the axis2.xml");

More detail : http://wso2.com/library/585/

I believe I have answered part of your question.

Also to load axis2 config to the AxisServlet, Add below config to your web.xml

<servlet>
<servlet-name>AxisServlet</servlet-name>
<display-name>Apache-Axis Servlet</display-name>
<servlet-class>org.apache.axis2.transport.http.AxisServlet</
servlet-class>
<init-param>
<param-name>axis2.xml.url</param-name>
<param-value>path to you axis2.xml</param-value>
<param-name>axis2.repository.url</param-name>
<param-value>path to your repo</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
jayalalk
  • 2,382
  • 3
  • 17
  • 14
  • I'm good with the ConfigurationContext loading, it works fine. The problem is that once I have it, I have no way of setting it in the AxisServlet. – Kévin Isabelle Jan 16 '14 at 17:19
  • 1
    Added AxisServlet config part to the answer. – jayalalk Jan 16 '14 at 17:32
  • Is there a way to do this programmatically? I don't use any axis2.xml nor web.xml. Just embedded Jetty and bootstrap code. I'll try to pass those 2 parameters to the Jetty ServletHolder and let you know how it goes. – Kévin Isabelle Jan 16 '14 at 19:36
0

Instead of using a simple jetty Context you should use a WebAppContext. This allows you to add the axis2 ConfigurationContext the jetty context.

Like this:

Server server = new Server(1111);
WebAppContext root = new WebAppContext();
root.setAttribute(AxisServlet.CONFIGURATION_CONTEXT, context);
AxisServlet s = new AxisServlet();
ServletHolder holder = new ServletHolder(s);
root.addServlet(holder, "/axis2/*");
pyropunk51
  • 404
  • 6
  • 8