简体   繁体   English

使用netbeans测试Web服务

[英]test web-services with netbeans

I'm new to webservices and i want to know what i'm doing wrong here's my code to get all my listCustomers 我是Web服务的新手,我想知道自己在做错什么,这是获取我所有列表的代码

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

To test my services i use netbeans tool (TEST RESTFUL web services) and i'm getting this error 为了测试我的服务,我使用了netbeans工具(TEST 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: I don't know if it's mandatory to annotate Customer Entity with XmlRootElement but i did it ... PS:我不知道是否必须使用XmlRootElement注释客户实体,但是我做到了...

例外是NullPointerException,这意味着您的对象customerDao为null,这就是问题的原因。

After a long search i just find a lazy method to auto create webservices with netbeans. 经过长时间的搜索,我只是找到了一种使用netbeans自动创建Web服务的惰性方法。 First, i create a simple web services by annotate my class with @WebService and my method with @WebMethod . 首先,我通过使用@WebService注释类和使用@WebMethod的方法来创建简单的Web服务。 Then i just right click in my services and generate restful service with netbeans the result looks like this : 然后我只需右键单击我的服务并使用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;
}

Now it work great... 现在效果很好...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM