0

私はWebサービスを初めて使用し、何が間違っているのか知りたいのですが、これがすべてのlistCustomersを取得するためのコードです。

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

サービスをテストするには、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:XmlRootElementで顧客エンティティに注釈を付けることが必須かどうかはわかりませんが、私はそれを行いました...

4

2 に答える 2

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

今ではうまくいきます...

于 2012-05-20T16:57:38.010 に答える
0

例外はNullPointerExceptionです。これは、オブジェクトcustomerDaoがnullであることを意味し、これが問題の原因です。

于 2012-05-20T02:18:33.183 に答える