views:

553

answers:

3

Hello,

In my GWT app I have the following model class:

import com.google.gwt.user.client.rpc.IsSerializable;

public class TestEntity implements IsSerializable {
    public String testString;
}

This class implements the GWT custom IsSerializable marker interface - which I really don't like, because I use my model classes not only for GWT. So I prefer java.io.Serializable.

But if I modify the class to implement Serializable instead of IsSerializable, the GWT RPC mechanism doesn't work anymore. I don't get an error on the server side, but on the client AsyncCallback.onFailure is invoked.

I am using...

  • GWT 1.7.0.
  • Spring 2.5.6.SEC01
  • Spring and GWT are configured as described here.
A: 

What exactly is the error you receive? We are using Serializable for our DTO's without any problems so you should be able to as well.

Mark
Throwable.getMessage() on the client only says:The call failed on the server; see server log for detailsThe stacktrace is empty.On the server log there are only my debug messages. And they tell me, that everything was fine.I forgot to say, that I also use Spring. GWT and Spring are configured as described here: http://technophiliac.wordpress.com/2008/08/24/giving-gwt-a-spring-in-its-step/
Ethan Leroy
A: 

Ok, I went through the comments of the Gwt-Spring-Article (the link i posted) and found the solution. I had to change two lines in the process call method:

RPCRequest rpcRequest = RPC.decodeRequest(payload, this.remoteServiceClass, this);
return RPC.invokeAndEncodeResponse(this.remoteService, rpcRequest.getMethod(), rpcRequest.getParameters(), rpcRequest.getSerializationPolicy());
Ethan Leroy
A: 

It turns out that this Spring-MVC and GWT hybrid technique is being used in the code base at my new job - no wonder the error I was getting was similar! Thanks for this posting - it helped me identify the issue and fix it. The code we had was based on the old code from the article you posted - or whatever that code was based on! Plagiarism abound!

To summarize, that article proposes a way to integrate GWT with Spring-MVC. The crux of the solution is to provide a Servlet servlet class that combines a Spring MVC Controller with a GWT RemoteServiceServlet. Serializable DTO objects were not supported since (I presume) the code was based on pre-GWT-1.4 code, which couldn't cope with DTOs that didn't implement GWT's isSerializable marker interface. The update to the controller class is very simple once you know what's going on...

The two fixed lines I see simply pass through the SerializationPolicyProvider (which is the 'this' in the last parameter to RPC.decodeRequest() method. The calling class extends GWT's RemoveServiceServlet, which is a SerializationPolicyProvider). This simple fix I presume causes the updated (post 1.4) GWT code to be invoked, which can handle Serializable as well as isSerializable classes. The SerializationPolicyProvider looks at the serializationPolicy.

The second fix passes the serializationPolicy through to the RPC.invokeAndEncodeResponse() method. I presume this is the *.gwt.rpc whitelist of DTO objects that were verified when the GWT module was compiled.

Alex Worden