我尝试将 AutoBeans 添加到我们的 GWT 应用程序中,以将我们的对象序列化为 cookie,然后将它们读回。
但是,在此之后我无法使用反序列化对象调用 GWT RPC 方法调用。谁能提供有关 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;
}
}
然后运行:
@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 方法失败了,并且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());
}
});
此外,我在服务器日志中看不到任何请求。
任何人都可以帮忙吗?非常感谢