一些背景:

我正在尝试对我们公开的某些Axis2服务使用SSL相互身份验证。问题是Axis2内置服务器不支持该功能。因此,我想使用嵌入式Jetty来实现这一点并在其中部署AxisServlet。

问题:

似乎没有办法将AxisConfiguration(包含所有可用服务的定义)直接传递给servlet。

我如何尝试做到这一点:

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


这种方法的问题在于,从不调用AxisServlet的init(ServletConfig)方法,因此,每当尝试在8080上调用服务时,我都会得到nullPointer异常:

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)


根据Axis2源代码,发生这种情况是因为从未在AxisServlet中设置配置上下文。因此,现在的主要问题是:

1)是否可以直接在AxisServlet中设置配置上下文?我没有找到任何办法

2)为什么Jetty没有发送初始化参数,并且没有在servlet上调用init(ServletConfig config)方法?我与调试器确认,它永远不会被调用。

最佳答案

如果要加载配置上下文,可以尝试直接从文件系统加载如下所示的配置上下文。

ConfigurationContext myConfigContext =
            ConfigurationContextFactory.createConfigurationContextFromFileSystem(“”,“ axis2.xml的绝对路径”);

更多详情 :
http://wso2.com/library/585/

我相信我已经回答了您的部分问题。

还要将axis2配置加载到AxisServlet,将以下配置添加到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>

09-28 13:11