Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GWT - how can client detect that it's javascript is out-of-sync if server is updated

I have a GWT application where users keep the browser based side of the application open indefinitely. Every so often we upgrade the application - if the users hit reload in their browsers after this is done then everything goes fine. However what usually happens is that they carry on using the already open version of the application, i.e. a version served before the upgrade, and then experience obscure RPC related errors as the client side Javascript is no longer in sync with what is on the server.

Does GWT have any mechanism, that you can enable or incorporate in your code, for coping with this. I don't need any clever handling of the situation, e.g. trying to reload the application and reestablish the user's current state, a simple dialog explaining that client and server are no longer in sync and that the web application needs to be reloaded would be enough.

like image 874
George Hawkins Avatar asked Sep 15 '11 12:09

George Hawkins


2 Answers

The documentation of the interface com.google.gwt.user.client.rpc.AsyncCallback<T> gives a hint on how to do this.

   public void onFailure(Throwable caught) {
     // Convenient way to find out which exception was thrown.
     try {
       throw caught;
     } catch (IncompatibleRemoteServiceException e) {
       // this client is not compatible with the server; cleanup and refresh the 
       // browser
     } catch (InvocationException e) {
       // the call didn't complete cleanly
     } catch (ShapeException e) {
       // one of the 'throws' from the original method
     } catch (DbException e) {
       // one of the 'throws' from the original method
     } catch (Throwable e) {
       // last resort -- a very unexpected exception
     }
   }

You most likely want to handle (pop-up the user dialog) the IncompatibleRemoteServiceException.

like image 167
Julian Lettner Avatar answered Nov 16 '22 17:11

Julian Lettner


It is called IncompatibleRemoteServiceException, and how to handle exceptions including this one is mentioned in the Google's Communicating with a Server Documentation.

like image 1
pistolPanties Avatar answered Nov 16 '22 18:11

pistolPanties