在JBoss 5中调用Web服务方法时客户端的空指针异常

时间:2013-07-26 06:51:22

标签: java web-services soap jax-ws jboss5.x

从客户端调用ParentService的进程方法时,我在客户端获取空指针异常。但在服务器日志中没有例外。 我正在使用服务器端处理程序。请求将转到处理程序,在完成ParentHandler的handleMessage方法之后,它将返回到NPE的客户端。

客户端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)

服务器代码

服务类:

@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;
  }
}

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>

太阳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());

请帮帮我

0 个答案:

没有答案