GWT-RPC を使用して GWT クライアント サーバー Web アプリケーションを開発しています。ほとんどは正常に動作しているように見えますが、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 メソッドをトリガーします。
サーバー側のエラーがないため、理由を理解するのに少し途方に暮れています。
問題はサーバー側のシリアル化の 1 つですが、それがどこから来ているのかわかりません。物事を調べるために OnAfterResponseSerialized をオーバーライドしましたが、呼び出されません (同じサービス実装クラスの他のメソッドによって呼び出されるため、プローブは機能しています)。javadocs から、processCall() は SerializationException をスローする必要があります。私はそれを捕まえて、何が起こっているのかを見る必要があります。