一些背景時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,並讓你知道它是如何發生的。 –