开发者_JAVA百科In GWT, requests are sent to XXXX.rpc which maps to a "GWT Controller" (RemoteService). The method name that will be invoked is buried in the post of this request.
Is there a way to send the method name as an additional HTTP header or as part of the URL? This way we can log the method name in our access logs.
I know there is a RpcRequestBuilder
class, but I dont know how I would extend it to add the method name to the header or URL.
I think you should solve this problem different, if possible. Here is another thought.
The method name is actually already sent, but buried as you said. But on the server side you can catch this name. In the RemoteServiceServlet
there is a protected method onAfterRequestDeserialized
which gives you a decoded version of the data and is specific for these kind of things. It contains the method name. Simply extend this method and log the method name there. This way you don't have to add tricks to your client side code.
I think this link could help you.. http://stuffthathappens.com/blog/2009/12/22/custom-http-headers-with-gwt-rpc/
EDIT : you should set methodName before invoking remote service method..
public class MyRpcRequestBuilder extends RpcRequestBuilder() {
String methodName;
public void setMethodName(String name) {
methodName = name;
}
@Override
protected RequestBuilder doFinish(RequestBuilder rb) {
RequestBuilder rb = super.doFinish(rb);
rb.setHeader("method", methodName);
return rb;
}
};
精彩评论