Web services 使用netbeans测试web服务

Web services 使用netbeans测试web服务,web-services,jakarta-ee,netbeans,jax-rs,jackson,Web Services,Jakarta Ee,Netbeans,Jax Rs,Jackson,我是webservices的新手,我想知道我做错了什么这是我的代码,可以让我所有的listCustomers @Path("/allCustomers") @GET @Produces("application/xml") public List<Customer> listAllCustomers(){ return customerDao.listAllCustomers(); } PS:我不知道是否必须用XmlRootElement注释客户实体,但我做到了…例外是Nu

我是webservices的新手,我想知道我做错了什么这是我的代码,可以让我所有的listCustomers

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

PS:我不知道是否必须用XmlRootElement注释客户实体,但我做到了…

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

经过长时间的搜索后,我找到了一个用netbeans自动创建Web服务的惰性方法。 首先,我创建了一个简单的web服务,用@WebService注释我的类,用@WebMethod注释我的方法。然后,我只需右键单击我的服务并使用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;
}
@GET
@生成(“应用程序/xml”)
@消耗(“文本/普通”)
@路径(“listallcustomers/”)
公共JAXBElement getListAllCustomers(){
试一试{
//调用Web服务操作
如果(端口!=null){
java.util.List result=port.listallcusters();
类ListAllCustomerResponse_1扩展了com.supinfo.supinbank.service_client.ListAllCustomerResponse{
ListAllCustomerResponse_1(java.util.List_返回){
这个.\u return=\u return;
}
}
com.supinfo.supinbank.service_client.listalcustomersresponse=new listalcustomersresponse_1(结果);
返回新的com.supinfo.supinbank.service_client.ObjectFactory().CreateListAllCustomerResponse(响应);
}
}捕获(例外情况除外){
//TODO在此处处理自定义异常
}
返回null;
}

现在它工作得很好…

你能发布CustomerService类的第40-50行吗?第40-50行是以前发布的。我不这么认为,因为如果我从内部类调用我的方法,我会得到一个客户列表。
@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;
}