从客户端调用 ParentService 的处理方法时,客户端出现空指针异常。但是在服务器日志中也不例外。我正在使用服务器端处理程序。该请求正在发送到处理程序,并且在完成 ParentHandler 的 handleMessage 方法后,它会返回给带有 NPE 的客户端。
客户端堆栈跟踪:
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)
服务器代码
服务等级:
@WebService
@SOAPBinding(style = SOAPBinding.Style.DOCUMENT, use = SOAPBinding.Use.LITERAL, parameterStyle = SOAPBinding.ParameterStyle.WRAPPED)
@HandlerChain(file = "ParentServiceHandler.xml")
public interface ParentService {
@WebMethod
public Parent process(Parent parent);
}
实现类:
@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;
}
}
处理程序类:
public class ParentHandler implements SOAPHandler<SOAPMessageContext> {
@Override
public boolean handleMessage(SOAPMessageContext mc) {
try{
Boolean flag = (Boolean)mc.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
if(!flag){
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;
}
}
父服务处理程序.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>
太阳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.ParentChildImp"
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>
客户端代码:
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);
}
}
但是当我发送空白子对象时,它工作正常。 objService.process(new ChildA());
请帮帮我。