我想用FilterService來跟蹤RemoteServiceServlet以跟蹤請求在我的webapplicaiton用戶中請求的方法。RemoteServiceServlet GWT中的篩選器
我無法做到這一點...
任何人都可以提出來跟蹤稱爲像ServletFilter中的方法的最佳途徑。
注意我喜歡跟蹤他請求的用戶和他的請求。
我想用FilterService來跟蹤RemoteServiceServlet以跟蹤請求在我的webapplicaiton用戶中請求的方法。RemoteServiceServlet GWT中的篩選器
我無法做到這一點...
任何人都可以提出來跟蹤稱爲像ServletFilter中的方法的最佳途徑。
注意我喜歡跟蹤他請求的用戶和他的請求。
您可以在您的RemoteServiceServlet實現中覆蓋public boolean preProcess(HttpExchange exchange)
,如下所示。
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;
}
在每個方法的開始處使用java.util.logging.Logger,然後寫入參數和用戶信息。這些信息將寫入您的Tomcat日誌。
可以使用"Spring MVC"或"Google Guice"做到這一點,這背後的想法的步驟是:
重寫processCall方法,以便您可以找出客戶端要調用哪個類的哪個方法。
@覆蓋 公共字符串processCall(字符串有效載荷)拋出SerializationException {
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);
}
}
你可以看到this sample使用谷歌吉斯。
祝您有美好的時光。
HttpExchange屬於哪個包?我不能重寫它,因爲沒有這樣的方法 – Alex
這是com.sun.net.httpserver.HttpExchange。但是現在RemoteServiceServlet中沒有preProcess方法。現在AbstractRemoteServiceServlet具有onAfterRequestDeserialized(RPCRequest rpcRequest) – Ilya