1

Hi guys here are a lot of posts about gwt offline possibilities. But none of them answer my questions completely.

Here just a few excerpts:

Excerpts of GWT, GAE and Android technologies i use:

  • RequestFactories
  • RPC Requests
  • JDO
  • Cordova/Phonegap
  • localstorage
  • html5 appcache

So whats my problem now?

  • When i startup my app without internet connection, it doesn't load anything. I get error 500 because theres no internet connection.
  • It doesn't load the HTML, CSS and JavaScript from offline cache.

I now it's because my webapp tries to connect to www.mypage.com, and doesn't get any response.

Is it possible that i startup my page from local resources on my android device and get the response from my server if i'm online, and get the response from my local storage if I don't have any connection?

I tried to implement it with local resources (Compiled HTML, CSS and JavaScripts), but in this case it don't connect to the date from google app engine at any time. The obvious result: No Data.

Community
  • 1
  • 1
Sam
  • 2,707
  • 1
  • 23
  • 32

1 Answers1

0

Yes you can get the response from local storage if you don't have a connection. Absolutely.

In your linker that extends com.google.gwt.core.ext.linker.AbstractLinker, iterate through the artifacts and check if it is rpc code (1). If it is, you add it to the network section of your manifest (2).

Then in your rpc callback (which is going to fail since there is no network), set up your @Override public void onFailure(Throwable caught) { ...} method to get the data from local storage and continue from there.

(1) example --

private boolean isRPRCall(EmittedArtifact artifact) {
        return (artifact.getPartialPath().substring(artifact.getPartialPath().length() - 3)).equals("rpc");
    }

(2) mine looks like :

CACHE MANIFEST
file.jsp
/myapp/myapp.nocache.js
[etc. etc...]

NETWORK:
/myapp/34C9362A2B2ED625B4FE3FF8E80A4A60.gwt.rpc
/myapp/586D3102158048D2D56BA386A134648D.gwt.rpc
/myapp/CCA65B31464BDB27545C23C142FEEEF8.gwt.rpc
FALLBACK:
user1258245
  • 3,639
  • 2
  • 18
  • 23
  • @Sam I think it should. I would think you just handle it in the onFail method like you do with rpc. I also suspect that you don't need to specify anything in your network manifest. In the worst case, I expect you'd just have to figure out what you need under the NETWORK. Try it and see. I was getting an error for rpc about the code not being available so I added it to the manifest and presto it worked. Just try getting your local data in the onFail method of your request factory. – user1258245 Feb 08 '13 at 08:38
  • This works most times. I created a linker, which creates the correct manifest file. But the answer is no enough. What do you do with dynamic images? you can't list it in the offline cache file. I got my app running offline, but without files. Do you have an idea for this? espacially gae/blobservice? – Sam Feb 12 '13 at 07:45
  • Why can't you list it in the offline cache? If it can't be listed there then an html5 offline app isn't going to work for you. Is it that you need to make a servlet so to serve those when the manifest requests them? I used to use the blobstore to serve my gwt javascript (to get around previous 1 gb app limit) so I had a servlet to handle that request. I think that is all you would need and that you have to put all the resources you will use offline into the linker. [remember you can use a FALLBACK entry to handle the url for the servlet if it's different than how you ask in your code] – user1258245 Feb 12 '13 at 08:26
  • If i list all images in the manifest - all images get downloaded at first place. isn't it? I server the app with different images for different customers, so i can't list it there. Or do you think i can create different manifest files for different customers? The images aren't ready on compile time. So can i change the manifest during runtime? Can i use a servlet to serve the manifest file? – Sam Feb 12 '13 at 09:14
  • Yes you can serve the manifest with a servlet [sorry actually I am using javax.servlet.Filter]. I currently serve a different manifest depending on the language header. You can most likely include whatever images you need by rewriting/finishing the manifest in the filter. Make sure you serve it with response.setContentType("text/cache-manifest"); That might be a topic for a thread of it's own, but I do it via context.getRequestDispatcher(fileName).include(request, response); – user1258245 Feb 12 '13 at 09:30
  • Ok, if i would do that. Does my browser download every image on first startup which are included in the manifest? – Sam Feb 12 '13 at 09:32
  • Yeah it has to or they won't be there when you need it. Practically though, it loads your page first then gets the stuff for the manifest so your user doesn't sit there waiting. If it's too much and your cache can't handle it (there are limits right?!?), maybe you might use FALLBACK and have img.jpg img2.jpg and img3.jpg etc. etc. all resolve to img4.jpg (which just says offline or something). – user1258245 Feb 12 '13 at 10:07
  • Yes there is a limitation, i know. For that reason i'm thinking about implement it on my app by my self to overtake this limitation. – Sam Feb 12 '13 at 10:26