Thursday, July 20, 2017

Re: SerializationException when application is modified

Hi.

Thanks a lot for you all your replies.  We have just noticed that the behavior of the RPC calls is different depending on whether the beans travelling through the wire implement Serializable or IsSerializable.

When they implement IsSerializable the onFailure(Throwable) method of the AsyncCallback contains a IncompatibleRemoteServiceException.  According to its Javadoc "The correct response to receiving an instance of this exception in the AsyncCallback.onFailure(Throwable) method is to get the application into a state where a browser refresh can be done."

On the other side, when they implement the generic Serializable method, the exception is the more generic StatusCodeException with a message "500 The call failed on the server; see server log for details".  This is too generic, it could be caused by any problems on the server, not just code changes requiring a reload.

So it looks like its better to implement IsSerializable rather than Serializable.

What do you think?  Am I missing something?


On Wed, Jul 19, 2017 at 12:22 PM, Thomas Broyer <t.broyer@gmail.com> wrote:


On Tuesday, July 18, 2017 at 6:15:23 PM UTC+2, Óscar Frías Barranco wrote:
Hi.

When we modify the code of our GWT application, in particular the classes that travel through GWT calls, these exceptions are generated for many users for a few hours:

com.google.gwt.user.client.rpc.SerializationException: Type '.....' was not assignable to 'com.google.gwt.user.client.rpc.IsSerializable' and did not have a custom field serializer.For security purposes, this type will not be serialized.: instance = .....

We think that this is due to browsers caching the previous (old) code which is no longer aligned with the server code.  We have reviewed all HTTP headers related to caching and all of the are, we think, correctly configured.

So our plan is to force a reload of the browser page with a location.reload(true) when we detect that the SerializationException is being thrown at the server.

From a UX point of view, it's probably better to show an error (possibly with a button to reload the app) than forcibly reload, as that could possibly lead to losing data the user has entered.
This is what Google Groups is doing, and it allows users to copy their message before reloading, pasting and re-sending it.
 
Any ideas about how to implement this easily?  Our code if full of AsyncCallback calls and we would like to avoid editing each one of them.  Is there a place where we could insert a client code that would be executed for every RPC call and that will call location.reload(true) if a SerializationException is thrown ?

If your GWT.create() for the services are relatively centralized, you could implement wrappers that wrap the AsyncCallback before delegating to the real service.

I.e. from 

FooServiceAsync fooService = GWT.create(FooService.class);

to

FooServiceAsync fooService = new FooServiceAsyncWrapper();

with

class FooServiceAsyncWrapper implements FooServiceAsync {
  private final FooServiceAsync delegate = GWT.create(FooService.class);

  @Override
  public void doFoo(int param1, String param2, AsyncCallback<Bar> callback) {
    delegate.doFoo(param1, param2, new AsyncCallbackWrapper<Bar>(callback));
  }
}

class AsyncCallbackWrapper<T> implements AsyncCallback<T> {
  private final AsyncCallback<T> delegate;

  public AsyncCallbackWrapper(AsyncCallback<T> delegate) {
    this.delegate = delegate;
  }

  @Override
  public void onSuccess(T result) {
    delegate.onSuccess(result);
  }

  @Override
  public void onFailure(Throwable caught) {
    if (caught instanceof Xxx) {
      // handle failure
    } else {
      delegate.onFailure(caught);
    }
  }
}
--
You received this message because you are subscribed to a topic in the Google Groups "GWT Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-web-toolkit/Kt9DygTyQ-U/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at https://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "GWT Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at https://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment