我正在编写一个 GWT 客户端,它使用 REST/Json 与 IIS 上运行的 .NET 服务进行通信。
我有使用 GWT 与 Java servlet 和普通 RPC 的经验,并且我知道可以通过指定将 Logger.log 输出发送到远程 java 服务器
<set-property name="gwt.logging.simpleRemoteHandler" value="ENABLED" />
在.gwt.xml 模块文件中。并通过在 web.xml 文件中配置 servlet。
我知道这个SimpleRemoteHandler使用GWT/RPC进行通信。 现在我的问题是,我可以编写自己的 RemoteHandler 来在服务器上存储消息,它不使用 GWT/RPC,而只是使用 RequestBuilder 的 REST/JSON 吗?
有关如何使用普通 Java Servlet 或 PHP 页面执行此操作的入门指南,对于了解我必须采用哪种方式在 .NET 中进行开发也应该有很大帮助。
最佳答案
技巧如下:
只需创建一个扩展 RemoteLogHandlerBase 的类,并在必须重写的发布方法中执行您想要执行的操作。
package be.gps.gwt.client.log;
import java.util.logging.LogRecord;
import com.google.gwt.logging.client.RemoteLogHandlerBase;
import com.google.gwt.user.client.Window;
public class JsonRemoteLogHandler extends RemoteLogHandlerBase
{
// =============================================================================================
/**
* Constructor.
*/
public JsonRemoteLogHandler()
{
}
// =============================================================================================
@Override
public void publish(LogRecord logRecord)
{
Window.alert("publish " + logRecord.getMessage());
//TODO send to server
}
}
然后您必须在模块 .gwt.xml 中配置此日志处理程序,如下所示:
<replace-with class="be.gps.gwt.client.log.JsonRemoteLogHandler">
<when-type-is class="com.google.gwt.logging.client.SimpleRemoteLogHandler" />
<any>
<when-property-is name="gwt.logging.enabled" value="TRUE" />
<when-property-is name="gwt.logging.simpleRemoteHandler" value="ENABLED" />
</any>
</replace-with>
关于java - 使用自定义处理程序的 GWT 远程日志记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32881322/