Search code examples
javaweb-servicesapache-axis

Axis2 Client getting NullPointerException within ServiceStub Class


I have a client trying to invoke a web service -

public static void main(String[] args) throws RemoteException {
    SimpleServiceStub service = new SimpleServiceStub(
            "http://localhost:8080/axis2/services/SimpleService");
            ConcatRequest request = new ConcatRequest();
            request.setS1("abc");
            request.setS2("123");
            ConcatResponse response = service.concat(request);
            System.out.println(response.getConcatResponse());
}

The exception stacktrace is from within eclipse is -

Exception in thread "main" org.apache.axis2.AxisFault
at org.apache.axis2.AxisFault.makeFault(AxisFault.java:430)
at com.ttdev.ss.SimpleServiceStub.fromOM(SimpleServiceStub.java:1419)
at com.ttdev.ss.SimpleServiceStub.concat(SimpleServiceStub.java:190)
at com.ttdev.ss.SimpleClient.main(SimpleClient.java:15)
Caused by: java.lang.NullPointerException
at com.ttdev.ss.SimpleServiceStub.fromOM(SimpleServiceStub.java:1413)
... 2 more

*EDIT* This is the stacktrace from axis

Exception in thread "HttpConnection-8080-1" java.lang.IllegalStateException: Response already committed
    at org.apache.axis2.transport.http.server.AxisHttpResponseImpl.assertNotCommitted(AxisHttpResponseImpl.java:75)
    at org.apache.axis2.transport.http.server.AxisHttpResponseImpl.sendError(AxisHttpResponseImpl.java:110)
    at org.apache.axis2.transport.http.server.AxisHttpService.doService(AxisHttpService.java:315)
    at org.apache.axis2.transport.http.server.AxisHttpService.handleRequest(AxisHttpService.java:187)
    at org.apache.axis2.transport.http.server.HttpServiceProcessor.run(HttpServiceProcessor.java:82)
    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)

When I debug the code, I see a null parameter (first parameter) being passed within the generated stub class -

private  java.lang.Object fromOM(
    org.apache.axiom.om.OMElement param,
    java.lang.Class type,
    java.util.Map extraNamespaces) throws org.apache.axis2.AxisFault{

    try {

            if (com.ttdev.ss.SimpleServiceStub.ConcatRequest.class.equals(type)){

                       return com.ttdev.ss.SimpleServiceStub.ConcatRequest.Factory.parse(param.getXMLStreamReaderWithoutCaching());


            }

            if (com.ttdev.ss.SimpleServiceStub.ConcatResponse.class.equals(type)){

                       return com.ttdev.ss.SimpleServiceStub.ConcatResponse.Factory.parse(param.getXMLStreamReaderWithoutCaching());


            }

    } catch (java.lang.Exception e) {
    throw org.apache.axis2.AxisFault.makeFault(e);
    }
       return null;
    }

I tried with axis2 version 1.5.1 and 1.6.2 The server is local server and is version 1.6.2.

I can't post the wsdl code here. It just does not show up! But here's the code used to generate the stub class -

WSDL2Code.main(new String[] {       
    "-S", "src/main/java",
    "-R", "src/main/resources/META-INF",
    "-ns2p", "http://ttdev.com/ss=com.ttdev.ss",
    "-uri", "src/main/resources/SimpleService.wsdl" });

Any help is appreciated. Btw, when I tried with CXF, it works. So either this is a bug or I did something wrong in generating the java code from the valid WSDL.


Solution

  • It is a bug with version 1.6.2! I downgraded the server version to 1.5.1 and it works! I hope this helps other people struggling to find answers with axis2 (like I did).