2012-05-20 214 views
0

我新的web服务,我想知道我做错了什么是我的代码,让我所有的listCustomers与NetBeans测试web服务

@Path("/allCustomers") 
@GET 
@Produces("application/xml") 
public List<Customer> listAllCustomers(){ 
    return customerDao.listAllCustomers(); 
} 

为了测试我的服务我使用NetBeans工具(测试RESTful Web服务),我得到这个错误

Avertissement: StandardWrapperValve[ServletAdaptor]: PWC1406: Servlet.service() for servlet ServletAdaptor threw exception 
java.lang.NullPointerException 
at com.supinfo.supinbank.service.CustomerService.listAllCustomers(CustomerService.java:45) 
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
at java.lang.reflect.Method.invoke(Method.java:601) 

PS:我不知道这是否是强制性的注释客户实体XmlRootElement将,但我做到了......

+0

你能不能张贴线40到您的CustomerService类的50? –

+0

40-50行是之前的帖子。 – 113408

回答

0

经过漫长的搜索,我只是找到一个懒惰的方法来自动创建netbeans web服务。 首先,我通过使用@WebService和我的方法使用@WebMethod来注释我的类来创建一个简单的Web服务。然后我就用右键单击我的服务,且与NetBeans RESTful服务的结果是这样的:

@GET 
@Produces("application/xml") 
@Consumes("text/plain") 
@Path("listallcustomers/") 
public JAXBElement<ListAllCustomersResponse> getListAllCustomers() { 
    try { 
     // Call Web Service Operation 
     if (port != null) { 
      java.util.List<com.supinfo.supinbank.service_client.Customer> result = port.listAllCustomers(); 

      class ListAllCustomersResponse_1 extends com.supinfo.supinbank.service_client.ListAllCustomersResponse { 

       ListAllCustomersResponse_1(java.util.List<com.supinfo.supinbank.service_client.Customer> _return) { 
        this._return = _return; 
       } 
      } 
      com.supinfo.supinbank.service_client.ListAllCustomersResponse response = new ListAllCustomersResponse_1(result); 
      return new com.supinfo.supinbank.service_client.ObjectFactory().createListAllCustomersResponse(response); 
     } 
    } catch (Exception ex) { 
     // TODO handle custom exceptions here 
    } 
    return null; 
} 

现在工作的伟大...

0

的excepion是NullPointerExce这意味着你的对象customerDao为空,这就是你的问题的原因。

+0

我不这么认为,因为如果我从内部课程调用我的方法,我会得到一个客户列表。 – 113408