[英]How to send an Exception object from GWT's client to server?
I'm trying to log client's exceptions on the server side. 我正在尝试在服务器端记录客户端的异常。 So I need to send them from client to server. 所以我需要将它们从客户端发送到服务器。
I have created service for this purpose: 我为此创建了服务:
public interface LoggerService extends RemoteService {
void logerror(Throwable e);
}
On the client's side I use GWT.setUncaughtExceptionHandler(uncaughtExceptionHandler): 在客户端,我使用GWT.setUncaughtExceptionHandler(uncaughtExceptionHandler):
GWT.UncaughtExceptionHandler uncaughtExceptionHandler = new
GWT.UncaughtExceptionHandler() {
public void onUncaughtException(Throwable e) {
LoggerServiceAsync loggerService = GWT.create(LoggerService.class);
loggerService.logerror(e, new AsyncCallback<Void>() {
@Override
public void onSuccess(Void arg0) {
SC.say("Client's error logged");
}
@Override
public void onFailure(Throwable arg0) {
SC.say("Unable to log client's error");
}
});
}
};
When I'm using hosted mode it works fine. 当我使用托管模式时,它可以正常工作。 But when I'm trying to work with web mode My LoggerService doesn't work. 但是,当我尝试使用网络模式时,我的LoggerService无法正常工作。 I know that in hosted mode exception "translates" from js to java. 我知道在托管模式下,异常会从js“转换”为java。 But I can't understand, why my logerror(Throwable e) method doesn't invoke at all in web mode. 但是我不明白,为什么我的logerror(Throwable e)方法根本不在Web模式下调用。 Server responce is 200. 服务器响应为200。
GWT offers infrastructure that facilitates client side logging with support for sending your log messages to the server. GWT提供了便利于客户端日志记录的基础架构,并支持将日志消息发送到服务器。 It'll slightly complicate your implementation at first but might establish a way to do logging across your app. 刚开始时,它会使您的实现稍微复杂一些,但可能会建立一种跨应用程序进行日志记录的方法。
最后,我添加了gwt-log用于在服务器上记录客户端的异常。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.