views:

52

answers:

2

Hi, I have a use case where my GWT application is running on a client browser and I stop my tomcat and update the relevant WAR.
What I'd like to happen is that once I load the tomcat every existing client will be reloaded automatically so they will be using the correct version of the application.

Currently I'm facing two problems:

  1. I don't know how to signal to the currently loaded application that it's obsolete and it should reload. I'm thinking of somehow identifying in my app that the reason for the GWT-RPC failure is 404 and so it should reload, but I'm not sure how this could be identified. I cannot reload on every GWT-RPC of course as the server might just be down for no reason and will be back up in a second or two without a problem.
  2. For some reason, the moduleName.nocache.js file is cached and so even if I manually refresh I can see a 404 request on the server as the app is looking for a non existent resource (the previous version), once I delete the cache of the browser this is resolved. Does anyone have any ideas why this is cached? I have changed nothing, in this regard, to the server settings.

Edit:
1. It seems there is no GWT straightforward way of doing this so what I've decided is that when a module loads it receives a module version, a Double, and if a GWT-RPC fails the module queries the Server for its current module version and if there is a mismatch it reloads the page. The GWT-RPC which is used to query the module version is constant and won't be changed for compatibility reasons. This way, even if all other GWT-RPC methods change the module is guaranteed this method will be valid.
2. It seems, thanks to BalusC's suggestion, that the file is cached for 5-10 minutes only and that's why I've been seeing non-deterministic behavior in this area. I've opened another question on how to set the headers on a single js file as I read somewhere that it's related to the container and not to GWT. Thanks,
Ittai

+1  A: 

HTTP doesn't support pushing of data. You need to use a webserver specific technique. In Tomcat, that's Comet. This is however a lot of work. I would rather recommend to use JavaScript/Ajax to let the client poll for the version change at certain intervals. E.g. every five minutes or so. If the result indicates a change in the version. then you can let JavaScript reload the page by window.location.reload.

As to your caching problem, verify the response headers of the requested file in question. It should match at least the following headers:

Cache-Control: no-cache, no-store, must-revalidate
Pragma: no-cache
Expires: 0
BalusC
Hi BalusC,I know HTTP doesn't support push.And I have the idea of once a GWT-RPC request fails try to initiate another one solely to see what app version the server reports having however I was looking for a more GWT subtle solution if there is such one.That also relates to the headers you mentioned, that is invisble to me as a GWT developer (at least it should be).
Ittai
Also with Firebug and an external HTTP monitor like Fiddler?
BalusC
Sorry, I didn't mean invisble in that sense (although I don't know of a straightforward way of seeing this aside for Fiddler and such) but I rather meant that the usual GWT solution does not require the developer to check these items.
Ittai
@Ittai: You'll have to configure the headers which the (web-) server sends with the files (.html, .js, ...), because it's impossible for GWT to control these. They're just static files. (Theoretically, GWT could put META tags into the HTML files, but using those instead of real headers would be very [unreliable](http://www.mnot.net/cache_docs/#META).)
Chris Lercher
@BalusC: Good answer. Please note however, that `Pragma: no-cache` [shouldn't be used](http://www.mnot.net/cache_docs/#PRAGMA). `Cache-Control: no-cache` does the job, and the Pragma should only be used by client requests. I discovered a lot about caching in [this question](http://stackoverflow.com/questions/2970938/ideal-http-cache-control-headers-for-different-types-of-resources) I asked a while ago. It would be nice to find a standard set of headers that work "best" with GWT apps.
Chris Lercher
@chris: `Pragma` is just there to ensure compatibility with HTTP 1.0 clients, although those are nowadays very rare. It's true that `Cache-Control` is its HTTP 1.1 successor. See also [this answer](http://stackoverflow.com/questions/49547/making-sure-a-web-page-is-not-cached-across-all-browsers/2068407#2068407).
BalusC
@BalusC I was able to see, using Firebug, that the file is cached for 5-10 minutes (depending on whether I ran tomcat from eclipse or standalone). I've opened a new question on how to set the headers on the specific js file here: , so if you'd like to help me with that I'd appreciate it. http://stackoverflow.com/questions/3540786/how-to-set-expires-http-header-on-a-single-js-file-in-apache-tomcat
Ittai
A: 

You can put you app-version in a cookie when the user starts your app, and at every rpc-call check the cookie if the user has the latest version, if not throw an exception.

pathed