我正在使用 RequestFactory 框架为基于 GWT 的应用程序开发审计服务。我在使用ClosingHandler
. 这是我的代码:
我的审计服务总结:
private static final int MAX_CACHE_SIZE = 15;
private int cacheSize = 0;
private AuditServiceRequestContext context;
@Override
public void audit(String event, String details) {
if (context == null)
context = createContext();
AuditServiceRequestContext cxt = createContext();
context.append(cxt);
AuditProxy proxy = cxt.create(AuditProxy.class);
/* intialize the proxy with event and details */
cxt.persist(proxy);
if (++cacheSize >= MAX_CACHE_SIZE)
flush();
}
public void flush() {
context.fire();
cacheSize = 0;
context = null;
}
我目前如何处理注销事件:
Window.addWindowClosingHandler(new ClosingHandler() {
@Override
public void onWindowClosing(ClosingEvent event) {
audit.audit("logout", "the user has closed the app");
audit.flush();
}
});
数据被保留,但请求失败,因为 HTTP 请求/gwtRequest
未返回任何响应(在 chrome 的开发人员工具上已取消状态)。
有什么想法可以解决这个问题吗?
编辑:
CloseHandler
奇怪的是,使用with没有错误Window#addCloseHandler(CloseHandler)
。不明白为什么,但它有效(如果有人可以向我解释,我真的很喜欢):D