Wednesday, September 8, 2010

Re: GWT RPC offline caching

Unfortunately, RPC serialization is assymetric : On client side,
you'll be able to deserialize data serialized on the server, and
vice-versa.

But you will not be able to serialize/deserialize data on the client.

If you cache data received from the server, you can deserialize it
using the following code :

Assume that you called a RPC service implementing IMyService, and that
the method returns a MyObject :

String payload = theResponseString;
SerializationStreamFactory ssf = GWT.create(IMyService.class); // magic
MyObject myObject = (MyObject) ssf.createStreamReader(payload).readObject();

The problem is that you will need to get the response String, and I
don't know if it is possible.


2010/9/8 Alex G. <alexej.gubin@googlemail.com>:
> Hello,
>
> i m working on generalized AsyncCallback class which allows to get a
> serialized string from a succesful GWT RPC response, so i can save it
> to htlm5 localStorage and use it as cached result in case RPC request
> fails.
>
> public abstract class OfflineAsyncCallback<T> implements
> AsyncCallback<T> {
>
>    private T offlineResult;
>
>    public void onFailure(Throwable caught) {
>
>         //load from localStorage
>         offlineResult = deserialize(serializedString);
>    }
>
>    public void onSuccess(T result) {
>
>        String serializedString = serialize(result);
>        //save to localStorage
>    }
>
>    private String serialize(T object) {TODO};
>    private T deserialize(String s) {TODO};
>
> }
>
> Is it possible to implement this two functions serialize() and
> deserialize() by using GWT internal class? Are there any other
> alternatives to cache GWT response?
>
> Thanks for help,
> Alex
>
> --
> You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
> To post to this group, send email to google-web-toolkit@googlegroups.com.
> To unsubscribe from this group, send email to google-web-toolkit+unsubscribe@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
>
>

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to google-web-toolkit+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

No comments:

Post a Comment