To wrap each AsynCallback<T> that is passed to any RemoteService , you need to override RemoteServiceProxy#doCreateRequestCallback() , because every AsynCallback<T> is passed here before the RPC call.
Here are the steps for doing this:
As pointed out by @ChrisLercher, you need to define your own Proxy Generator for each step when the RemoteService proxy is generated. Start by extending ServiceInterfaceProxyGenerator and overriding #createProxyCreator() .
public class MyServiceInterfaceProxyGenerator extends ServiceInterfaceProxyGenerator { @Override protected ProxyCreator createProxyCreator(JClassType remoteService) { return new MyProxyCreator(remoteService); } }
In your MyModule.gwt.xml use delayed binding to instruct GWT to compile using your Proxy Generator whenever it generates something like RemoteService :
<generate-with class="com.company.ourapp.rebind.rpc.MyServiceInterfaceProxyGenerator"> <when-type-assignable class="com.google.gwt.user.client.rpc.RemoteService"/> </generate-with>
Extend ProxyCreator and override #getProxySupertype() . Use it in MyServiceInterfaceProxyGenerator#createProxyCreator() so that you can define a base class for all generated RemoteServiceProxies .
public class MyProxyCreator extends ProxyCreator { public MyProxyCreator(JClassType serviceIntf) { super(serviceIntf); } @Override protected Class<? extends RemoteServiceProxy> getProxySupertype() { return MyRemoteServiceProxy.class; } }
Make sure that both MyProxyCreator and your MyServiceInterfaceProxyGenerator are located in a package that GWT will not compile in javascript. Otherwise, you will see the following error:
[ERROR] Line XX: No source code is available for type com.google.gwt.user.rebind.rpc.ProxyCreator; did you forget to inherit a required module?
You are now ready to extend RemoteServiceProxy and override #doCreateRequestCallback() ! Here you can do anything you want and apply it to every callback that is sent to your server. Make sure you add this class and any other class that you use here, in my AsyncCallbackProxy case, so that your client package is compiled.
public class MyRemoteServiceProxy extends RemoteServiceProxy { public MyRemoteServiceProxy(String moduleBaseURL, String remoteServiceRelativePath, String serializationPolicyName, Serializer serializer) { super(moduleBaseURL, remoteServiceRelativePath, serializationPolicyName, serializer); } @Override protected <T> RequestCallback doCreateRequestCallback(RequestCallbackAdapter.ResponseReader responseReader, String methodName, RpcStatsContext statsContext, AsyncCallback<T> callback) { return super.doCreateRequestCallback(responseReader, methodName, statsContext, new AsyncCallbackProxy<T>(callback)); } }
Literature: