0
我已經嘗試將AutoBeans添加到我們的GWT應用程序中,以便將我們的對象序列化爲cookie,然後再讀取它們。使用AutoBeans作爲參數的GWT RPC調用
但是,在這之後,我無法用反序列化的對象調用GWT RPC方法調用。任何人都可以提供任何有關爲什麼RPC調用失敗的見解?
示範:
@Test
public void testMyObject() {
MyObject obj = new MyObject();
obj.setTitle("titely");
WorkerFactory factory = AutoBeanFactorySource.create(WorkerFactory.class);
AutoBean<Worker> bean = factory.create(Worker.class, obj);
String json = AutoBeanCodex.encode(bean).getPayload();
System.out.println("Json is: " + json);
bean = AutoBeanCodex.decode(factory, Worker.class, json);
Worker newObject = bean.as();
System.out.println("Object title is: " + newObject.getTitle());
}
...這似乎按預期方式工作:
Json is: {"title":"titely"}
Object title is: titely
但現在我的RPC方法
public interface Worker {
public String getTitle();
public void setTitle(String title);
}
public interface WorkerFactory extends AutoBeanFactory {
AutoBean<Worker> createWorker();
}
public class MyObject implements Worker {
private String title;
public MyObject() {
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
}
然後運行失敗了,和caught.getMessage()
是null
。
服務定義:
@RemoteServiceRelativePath("workerService")
interface WorkerService {
public void doWork(Worker worker);
}
public interface WorkerServiceAsync {
void doWork(Worker worker, AsyncCallback<Void> callback);
}
public class WorkerServiceImpl extends RemoteServiceServlet implements WorkerService {
@Override
public void doWork(Worker worker) {
// Do stuff that never gets called
}
}
通過調用:
WorkerServiceAsync WORKER_SERVICE = GWT.create(WorkerService.class);
WORKER_SERVICE.doWork(newObject, new AsyncCallback<Void>() {
public void onSuccess(Void result) {
Window.alert("Never get here!");
}
public void onFailure(Throwable caught) {
Window.alert("Get here, but message is blank: " + caught.getMessage());
}
});
此外,我看不出在服務器日誌中的任何請求。
任何人都可以幫忙嗎?非常感謝