一些背景时AxisConfiguration传递给Axis的:如何在码头嵌入
我尝试使用SSL相互认证为我们揭露了一些Axis2的服务。问题在于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();
这种做法的问题是,把Axis的初始化(的ServletConfig)方法永远不会调用,所以我得到一个空指针异常,每当我试着拨打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)
据Axis2的源代码,这是因为在配置方面是从来没有在Axis的设置。所以现在最大的问题是:
1)是否可以直接在AxisServlet中设置配置上下文?我没有找到任何办法
2)为什么Jetty不发送初始参数并且不在Servlet上调用init(ServletConfig config)方法?我用调试器确认它永远不会被调用。
我擅长与ConfigurationContext负载,它工作正常。问题是一旦拥有了它,我就无法在AxisServlet中设置它。 –
将AxisServlet config部分添加到答案中。 – jayalalk
有没有办法做到这一点编程?我不使用任何axis2.xml或web.xml。只需嵌入Jetty和引导代码即可。我会尝试将这两个参数传递给Jetty ServletHolder,并让你知道它是如何发生的。 –