atom feed3 messages in org.codehaus.grails.user[grails-user] Bug in GWT-Plugin Servl...
FromSent OnAttachments
Daniel KimmigApr 16, 2008 5:29 am 
Peter LedbrookApr 16, 2008 6:16 am 
Daniel KimmigApr 16, 2008 10:10 am 
Subject:[grails-user] Bug in GWT-Plugin Servlet causes GWT-RPC to use LegacySerializationPolicy (found solution)
From:Daniel Kimmig (dkim@gmail.com)
Date:Apr 16, 2008 5:29:02 am
List:org.codehaus.grails.user

Hi,

I have just finished a few hours of step-debugging my Grails-app that uses the great GWT-Plugin. The problem was that I was completly unable to serialize any custom DTO classes to my client code from my exposed Grails services.

Even the the most simple classes like the following were unable to be serialized:

package gwt.dto.client;

import java.io.Serializable;

public class TreeDTO implements Serializable {

private static final long serialVersionUID = -1060171438121481047L; private String name;

public String getName() { return name; }

public void setName(String name) { this.name = name; }

}

Corresponding service class and interfaces: Remote Interface:

package gwt.aspekt.client.service;

import gwt.dto.client.TreeDTO;

import java.util.Map;

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

public interface GwtTreeService extends RemoteService {

public TreeDTO getTreeDTO();

}

Async Interface:

package gwt.aspekt.client.service;

import gwt.dto.client.TreeDTO;

import java.util.Map;

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

public interface GwtTreeServiceAsync {

void getTreeDTO(AsyncCallback<TreeDTO> callback);

}

Grails Service:

import gwt.dto.client.TreeDTO import org.codehaus.groovy.grails.plugins.gwt.annotation.MapTypeArg

class GwtTreeService{

static expose = [ 'gwt:gwt.aspekt.client.service' ]

public TreeDTO getTreeDTO(){

TreeDTO n = new TreeDTO() n.setName("narf")

return n } }

When executing the following snippet on the client side, an exception on the server side occured.

treeService.getTreeDTO(new AsyncCallback<TreeDTO>() {

public void onFailure(Throwable caught) { RootPanel.get().add(new Label(caught.getMessage()));

}

public void onSuccess(TreeDTO result) { RootPanel.get().add(new Label("" + result.getName()));

} });

The exception had this message:

008-04-16 14:14:59.494:/prowida:WARN: Exception while dispatching incoming RPC call com.google.gwt.user.server.rpc.UnexpectedException: Service method 'public abstract gwt.dto.client.TreeDTO gwt.aspekt.client.service.GwtTreeService.getTreeDTO()' threw an unexpected exception: com.google.gwt.user.client.rpc.SerializationException: Type 'gwt.dto.client.TreeDTO' 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. at com.google.gwt.user.server.rpc.RPC.encodeResponseForFailure(RPC.java:360) at com.google.gwt.user.server.rpc.RPC.encodeResponseForFailure(RPC.java:319)

Caused by:

Caused by: com.google.gwt.user.client.rpc.SerializationException: Type 'gwt.dto.client.TreeDTO' 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. at com.google.gwt.user.server.rpc.impl.LegacySerializationPolicy.validateSerialize(LegacySerializationPolicy.java:140) at com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter.serialize(ServerSerializationStreamWriter.java:524)

As we can clearly see, the LegacySerializationPolicy is used which is a GWT 1.3 compatible RPC serialization policy, that requires e.g. the use of the isSerializable interface.

After step debugging the creation of the SerializationPolicy I found out that you could stop this behavior and make GWT use the "StandardSerializationPolicy" which is the current best solution to use. In order to achieve that I manually changed the "GrailsRemoteServiceServlet" provided by the GWT-plugin. Changes/Solution At line 22:

//before: RPCRequest rpcRequest = RPC.decodeRequest(payload, null) //needs to be... RPCRequest rpcRequest = RPC.decodeRequest(payload, null, this)

and at line 54

//before:return RPC.encodeResponseForSuccess(serviceMethod, retval) //needs to be... RPC.encodeResponseForSuccess(serviceMethod, retval, rpcRequest.getSerializationPolicy())

Doing these changes made it much easier to serialize custom classes to my client code. I am using GWT 1.5 Milestone 2, Grails 1.0.1 and GWT-Plugin 0.24.

-- View this message in context:
http://www.nabble.com/Bug-in-GWT-Plugin-Servlet-causes-GWT-RPC-to-use-LegacySerializationPolicy-%28found-solution%29-tp16721267p16721267.html Sent from the grails - user mailing list archive at Nabble.com.

--------------------------------------------------------------------- To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email