1

我正在使用 GWT-RPC 开发一个 GWT 客户端-服务器 webapp;大多数情况下它似乎工作正常,但我在检索 IsSerializable 类型的 ArrayList 时遇到错误。

这是服务器端方法的代码:

    public GWTInvoiceList listInvoices(String enterpriseID, int selection) {
    try{
        logger.log("ISI getting a listy of invoices "+selection);
        PlataccsUser pxuser =  (PlataccsUser) getSession().getAttribute(PlataccsConstants.USER);
        Enterprise enterprise= pxuser.getEnterprise(enterpriseID);
        Clerk clerk= pxuser.getClerk(enterprise);
         int i=0;
         List<Invoice> invoices =Invoice.getInvoices(enterprise, clerk, selection);
         GWTInvoiceList gwinvoices = new GWTInvoiceList();
         Iterator<Invoice> it = invoices.iterator();
         while (it.hasNext()){
             Invoice invoice = it.next();
             logger.log("ISI-listInvoices converting invoice "+invoice.getSystemInvoiceNumber());
             gwinvoices.add(convert(invoice, clerk));
         }
         logger.log("ISI-lI, the invoice list is now ready and it lists "+gwinvoices.size()+" invoices");
        return gwinvoices;
    }catch(Exception px){
        logger.log("ISI propblem getting invoice list", px);
        return null;
    }
}

此代码执行时不会引发任何异常。GWTInvoiceList 返回类型是 ArrayList 的简单包装器,并且已知 GWTInvoice 类型可以在其他调用中成功序列化。客户端代码为:

    public InvoiceList(PlataxTabPanel parent, GWTEnterprise gwtEnterprise, int list_selection_type) {
    super(parent, gwtEnterprise.getName());
     topLabel.setText("List of Invoices");
     subHeader.setText("blah blah");
     invoiceService.listInvoices(gwtEnterprise.getEnterpriseID(), list_selection_type, invoiceListCallBack);

     //table headers:
     table.setWidget(0, 0, new ColumnHeaderLabel(LabelText.LIST_INVOICE_NUMBER_HEADER));
     table.setWidget(0, 1, new ColumnHeaderLabel(LabelText.LIST_INVOICE_CUSTOMER_HEADER));
     table.setWidget(0, 2, new ColumnHeaderLabel(LabelText.LIST_INVOICE_VALUE_DATE_HEADER));
     table.setWidget(0, 3, new ColumnHeaderLabel(LabelText.LIST_INVOICE_DUE_DATE_HEADER));
     table.setWidget(0, 4, new ColumnHeaderLabel(LabelText.LIST_INVOICE_STATUS_HEADER));
     table.setWidget(0, 5, new MoneyColumnHeaderLabel(LabelText.LIST_INVOICE_NET_HEADER));
     table.setWidget(0, 6, new MoneyColumnHeaderLabel(LabelText.LIST_INVOICE_TAX_HEADER));
     table.setWidget(0, 7, new MoneyColumnHeaderLabel(LabelText.LIST_INVOICE_TOTAL_HEADER));

}


final AsyncCallback<GWTInvoiceList> invoiceListCallBack= new AsyncCallback<GWTInvoiceList>(){
    @Override
    public void onSuccess(GWTInvoiceList invoices){
    Iterator<GWTInvoice> gwit = invoices.iterator();
     int row = 1;
     while(gwit.hasNext()){
         GWTInvoice gwinvoice = gwit.next();
         table.setWidget(row, 0, new Label(gwinvoice.getUserno()));
         table.setWidget(row, 1, new Label(gwinvoice.getCustomer().getName()));
         table.setWidget(row, 2, new Label(DateTimeFormat.getFormat(DateFormats.SHORT_DATE_FORMAT).format(gwinvoice.getValueDate())));
         table.setWidget(row, 3, new Label(DateTimeFormat.getFormat(DateFormats.SHORT_DATE_FORMAT).format(gwinvoice.getDueDate())));
         table.setWidget(row, 4, new Label(gwinvoice.getStatus()));
         table.setWidget(row, 5, new MoneyLabel(gwinvoice.getNet()));
         table.setWidget(row, 6, new MoneyLabel(gwinvoice.getTax()));
         table.setWidget(row, 7, new MoneyLabel(gwinvoice.getGross()));
         row++;
     }
    }

    @Override
    public void onFailure(Throwable cause) {
         //Debugging code

        StackTraceElement[] st = cause.getStackTrace();
       String error = "get invoice list failed\n";

       error = error+cause.getClass().getName()+"\n";
       if (cause instanceof StatusCodeException){
            StatusCodeException sce=(StatusCodeException) cause;
            int sc = sce.getStatusCode();
            error=error+"Status Code:"+ sc+"\n";
        }
       for (int i=0; i<st.length; i++){
           error = error + st[i].toString()+ "\n";
       }
        Window.alert(error);
    }
};

调用总是以 500 状态码失败,因此会触发 AsyncCallback 内部类的 OnFailure 方法。

我有点不知所措,因为没有服务器端错误。

问题是服务器端的序列化之一,但我看不到它来自哪里。我已经重写了 OnAfterResponseSerialized 来探测事物并且它没有被调用 - (它被同一服务实现类中的其他方法调用,因此探测正在工作)。从 javadocs 中,processCall() 应该抛出一个 SerializationException。我需要抓住它,看看发生了什么。

4

2 回答 2

0

GWTInviceList 代码是什么样的?

我猜你没有 GWTInvoiceList 类的无参数构造函数。

于 2013-06-24T17:41:36.647 回答
0

这段代码:

 /**
 * catches the SerializationException for forensic examination.
 */
@Override
public String processCall(String payload) throws SerializationException{
    try{
        return super.processCall(payload);
    }catch(SerializationException se){
        logger.log("Xservlet serialisation excption", se);
        throw se;
    }
}

添加到服务实现类会捕获 SerializationException,因此我可以跟踪异常对象。

于 2013-06-25T09:15:27.310 回答