我正在使用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。我需要抓住它,看看发生了什么。
答案 0 :(得分:0)
GWTInviceList代码是什么样的?
我猜你没有GWTInvoiceList类的无参数构造函数。
答案 1 :(得分: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,以便我可以跟踪异常对象。