Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/gwt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/redis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
GWT中带过滤器的RemoteServiceServlet_Gwt_Servlets - Fatal编程技术网

GWT中带过滤器的RemoteServiceServlet

GWT中带过滤器的RemoteServiceServlet,gwt,servlets,Gwt,Servlets,我正在尝试使用带过滤器的RemoteServiceServlet捕获请求,以跟踪在用户的Web应用程序中请求的方法 我不能这样做 有谁能推荐一种跟踪这些方法的最佳方法,比如ServletFilter 注:我喜欢跟踪用户及其请求 在每个方法的开头使用java.util.logging.Logger,然后写入参数和用户信息。这些信息将写入您的tomcat日志。您可以使用或来完成此操作,此想法背后的步骤是: 编写一个通用servlet并将所有RPC的URL映射到它 通用servlet必须扩展“Remo

我正在尝试使用带过滤器的RemoteServiceServlet捕获请求,以跟踪在用户的Web应用程序中请求的方法

我不能这样做

有谁能推荐一种跟踪这些方法的最佳方法,比如ServletFilter


注:我喜欢跟踪用户及其请求

在每个方法的开头使用java.util.logging.Logger,然后写入参数和用户信息。这些信息将写入您的tomcat日志。

您可以使用或来完成此操作,此想法背后的步骤是:

  • 编写一个通用servlet并将所有RPC的URL映射到它
  • 通用servlet必须扩展“RemoteServiceServlet”类
  • 重写processCall方法,以便找出客户端要调用哪个类的哪个方法

    @凌驾 公共字符串processCall(字符串负载)引发序列化异常{

    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);
    }
    
    }

  • 你可以看到使用谷歌guice


    祝您玩得愉快。

    您可以在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)