• Post Reply Bookmark Topic Watch Topic
  • New Topic

Null pointer exception in client side when calling a web service method in JBoss 5  RSS feed

 
Meastro Torres
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am getting null pointer exception in client when calling ParentService' process method from client. But in server log no exception is there. I am using server side handler. The request is comming to handler and after completing the ParentHandler's handleMessage method it's coming back to client with NPE.

Client Stacktrace:

Exception in thread "main" javax.xml.ws.soap.SOAPFaultException: java.lang.NullPointerException
at com.sun.xml.internal.ws.fault.SOAP11Fault.getProtocolException(Unknown Source)
at com.sun.xml.internal.ws.fault.SOAPFaultBuilder.createException(Unknown Source)
at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(Unknown Source)
at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(Unknown Source)
at com.sun.xml.internal.ws.client.sei.SEIStub.invoke(Unknown Source)
at $Proxy30.service(Unknown Source)

Server Codes

Service Class:

@WebService
@SOAPBinding(style = SOAPBinding.Style.DOCUMENT, use = SOAPBinding.Use.LITERAL, parameterStyle = SOAPBinding.ParameterStyle.WRAPPED)
@HandlerChain(file = "ParentServiceHandler.xml")
public interface ParentService {
@WebMethod
Parent process(Parent parent);
}

Implementation class:

@WebService(endpointInterface = "com.practise.ws.ParentService")
public class ParentServiceImp implements ParentService {
@Resource
private WebServiceContext context;
@Override
public Parent process(Parent parent) {
System.out.println("Process calling---------------");
return parent;
}
}

Handler class:

public class ParentHandler implements SOAPHandler<SOAPMessageContext> {
@Override
public boolean handleMessage(SOAPMessageContext mc) {
try{
Boolean flag = (Boolean)mc.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
if(!flag.booleanValue()){
SOAPMessage soapMsg = mc.getMessage();
System.out.println("MESSAGE: " + soapMsg);
soapMsg.writeTo(System.out);
}
return true;
}catch (Exception e) {
e.printStackTrace();
return false;
}
}

@Override
public Set<QName> getHeaders() {
return Collections.emptySet();
}

@Override
public void close(MessageContext mc) {}

@Override
public boolean handleFault(SOAPMessageContext mc) {
return true;
}
}

ParentServiceHandler.xml

<?xml version="1.0" encoding="UTF-8"?>
<handler-chains xmlns="http://java.sun.com/xml/ns/javaee">
<handler-chain>
<handler>
<handler-name>ServiceSOAPHandler</handler-name>
<handler-class>com.practise.handler.ParentHandler</handler-class>
</handler>
</handler-chain>
</handler-chains>

sun-jaxws.xml

<?xml version="1.0" encoding="UTF-8"?>
<endpoints xmlns="http://java.sun.com/xml/ns/jax-ws/ri/runtime" version="2.0">
<endpoint name="ParentChild" implementation="com.practise.ws.ParentServiceImp" url-pattern="/parentWs" />
</endpoints>

web.xml

<listener>
<listener-class>
com.sun.xml.ws.transport.http.servlet.WSServletContextListener
</listener-class>
</listener>
<servlet>
<servlet-name>ParentChild</servlet-name>
<servlet-class>com.sun.xml.ws.transport.http.servlet.WSServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>ParentChild</servlet-name>
<url-pattern>/parentWs</url-pattern>
</servlet-mapping>
Client code:

public class WebServiceClient {
public static void main(String[] args) {
ParentServiceImpService service = new ParentServiceImpService();
ParentService objService = (ParentService) service.getParentChildImpPort();
ChildA child =new ChildA();
child.setStrParent("Parent");
child.setStrChildA("Child");
objService.process(child);
}
}

But when I am sending blank child object then it's working properly. objService.process(new ChildA());

Please help me.
 
Kesava Krishna
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please try for null checks in your ParentHandler class at each step and this will clearly tell you where you are missing.

Thanks,
Kesava.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!