I am using GWT and RPC in my app. after session expires when I do a RPC call, because of my login-filter the request redirect to login.jsp, but my problem is client doen\'t
@Vielinko's update was useful with MyProxyCreator's @Piotr's solution.
For variety, this is an alternative solution to the one provided by @Piotr but it's also quite similar. I found this also worked after implementing with @Piotr's solution to begin with:
Note: update the package name as required.
package com.google.gwt.sample.stockwatcher.server;
import com.google.gwt.core.ext.typeinfo.JClassType;
import com.google.gwt.sample.stockwatcher.client.MyRemoteServiceProxy;
import com.google.gwt.user.client.rpc.impl.RemoteServiceProxy;
import com.google.gwt.user.rebind.rpc.ProxyCreator;
public class MyProxyCreator extends ProxyCreator {
public MyProxyCreator(JClassType serviceIntf) {
super(serviceIntf);
}
/**
* This proxy creator extends the default GWT {@link ProxyCreator} and replaces {@link RemoteServiceProxy} as base class
* of proxies with {@link MyRemoteServiceProxy}.
*/
@Override
protected Class extends RemoteServiceProxy> getProxySupertype() {
return MyRemoteServiceProxy.class;
}
}
Create a MyRemoteServiceProxy.java class in your client package:
package com.google.gwt.sample.stockwatcher.client;
import com.google.gwt.user.client.rpc.impl.Serializer;
import com.google.gwt.http.client.RequestCallback;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.rpc.impl.RemoteServiceProxy;
import com.google.gwt.user.client.rpc.impl.RequestCallbackAdapter;
import com.google.gwt.user.client.rpc.impl.RpcStatsContext;
/**
* The remote service proxy extends default GWT {@link RemoteServiceProxy} and
* proxies the {@link AsyncCallback} with the {@link AsyncCallbackProxy}.
*/
public class MyRemoteServiceProxy extends RemoteServiceProxy {
public MyRemoteServiceProxy(String moduleBaseURL, String remoteServiceRelativePath, String serializationPolicyName,
Serializer serializer) {
super(moduleBaseURL, remoteServiceRelativePath, serializationPolicyName, serializer);
}
@Override
protected RequestCallback doCreateRequestCallback(RequestCallbackAdapter.ResponseReader responseReader,
String methodName, RpcStatsContext statsContext, AsyncCallback callback) {
return super.doCreateRequestCallback(responseReader, methodName, statsContext,
new MyAsyncCallback(callback));
}
}
This is an alternate solution to having the MyProxyCreator and MyRpcRemoteProxyGenerator in @Piotr's solution. I've tested that it works. RPC calls reroute to this function first before they are called. Keep the MyAsyncCallback for handling the session time out. :)