在实例化ServiceClient时获取空指针异常

时间:2013-05-01 09:06:38

标签: java servlets

我创建了一个客户端,我正在创建一个ServiceClient的新对象。我的代码是:

private ServiceClient getClient(String action, String eprType){
String webinfFolder = request.getSession().getServletContext().getRealPath("/WEB-INF");
        try{
            if(wsSecurityEnabled){
                configContext = ConfigurationContextFactory.createConfigurationContextFromFileSystem(webinfFolder, webinfFolder + "/conf/axis2.xml");       
                serviceClient = new ServiceClient(configContext, null);
            }else{
                serviceClient = new ServiceClient();//Here i am getting nullpointerexception
            }
        }catch(IOException ioe){
            ioe.printStackTrace();
        }
        targetEPR = new EndpointReference(eprType);
        serviceClient.setOptions(getOptions(action));       
        serviceClient.addHeader(getUserNameHeaderElement());
        System.out.println("Client Created");
        return serviceClient;
}

由于我的wsSecurityEnabled为false,因此来自此代码serviceClient = new ServiceClient();  在这里我得到nullpointer例外:

java.lang.NullPointerException
    at org.apache.axis2.client.ServiceClient.configureServiceClient(ServiceClient.java:162)
    at org.apache.axis2.client.ServiceClient.<init>(ServiceClient.java:144)
    at org.apache.axis2.client.ServiceClient.<init>(ServiceClient.java:251)
    at cts.remon.cctv.client.Consumer.getClient(Consumer.java:573)
    at cts.remon.cctv.client.Consumer.requestCloseSession(Consumer.java:147)
    at cts.remon.cctv.client.Consumer.doPost(Consumer.java:260)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:225)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1001)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
    at java.lang.Thread.run(Thread.java:722)

如何解决此错误?提前致谢

0 个答案:

没有答案