GWT中带过滤器的RemoteServiceServlet
我正在尝试使用带过滤器的RemoteServiceServlet捕获请求,以跟踪在用户的Web应用程序中请求的方法 我不能这样做 有谁能推荐一种跟踪这些方法的最佳方法,比如ServletFilterGWT中带过滤器的RemoteServiceServlet,gwt,servlets,Gwt,Servlets,我正在尝试使用带过滤器的RemoteServiceServlet捕获请求,以跟踪在用户的Web应用程序中请求的方法 我不能这样做 有谁能推荐一种跟踪这些方法的最佳方法,比如ServletFilter 注:我喜欢跟踪用户及其请求 在每个方法的开头使用java.util.logging.Logger,然后写入参数和用户信息。这些信息将写入您的tomcat日志。您可以使用或来完成此操作,此想法背后的步骤是: 编写一个通用servlet并将所有RPC的URL映射到它 通用servlet必须扩展“Remo
注:我喜欢跟踪用户及其请求 在每个方法的开头使用java.util.logging.Logger,然后写入参数和用户信息。这些信息将写入您的tomcat日志。您可以使用或来完成此操作,此想法背后的步骤是:
try {
RPCRequest rpcRequest = RPC.decodeRequest(payload);
RemoteService service = getServiceInstance(rpcRequest.getMethod().getDeclaringClass());
return RPC.invokeAndEncodeResponse(service, rpcRequest.getMethod(),
rpcRequest.getParameters(), rpcRequest.getSerializationPolicy());
} catch (IncompatibleRemoteServiceException ex) {
getServletContext()
.log("An IncompatibleRemoteServiceException was thrown while processing this call.", ex);
return RPC.encodeResponseForFailure(null, ex);
}
}祝您玩得愉快。您可以在RemoteServiceServlet的实现中覆盖
公共布尔预处理(HttpExchange)
,如下所示
public boolean preProcess(HttpExchange exchange) {
String body = null;
RPCRequest req = null;
// Read and parse the request
byte[] bytes = null;
Object bytebuf = getAttribute("RequestBody");
if ((bytebuf != null) && (bytebuf instanceof ByteBuffer)) {
bytes = ((ByteBuffer) bytebuf).array();
}
if (bytes == null) {
setAttribute("ResponseCode", new Integer(500));
setAttribute("ResponseBody", "Missing Request Body.");
return true;
}
body = new String(bytes, "UTF-8");
req = RPC.decodeRequest(body, this.getClass());
String methodName = req.getMethod().toString();
//Here you have name of a method
//You can get parameters
//Object[] parms = req.getParameters();
return true;
}
HttpExchange属于哪个软件包?我无法覆盖它,因为没有这样的方法它是com.sun.net.httpserver.HttpExchange。但是现在RemoteServiceServlet中没有预处理方法。现在AbstractRemoteServiceServlet已反序列化OnAfterRequest(RPCRequest-RPCRequest)