PDA

View Full Version : Problem with enum and rpcproxy



Aphrel
19 Jan 2010, 3:39 AM
Hi,
i have a problem with rpcproxy, using GWT 2.0.0 and EXTGWT 2.1.0

My grid class contains this definition of rpcproxy:


proxy = new RpcProxy<PagingLoadResult<HRSuiteBaseDTO>>() {
@Override
public void load(Object loadConfig, AsyncCallback<PagingLoadResult<HRSuiteBaseDTO>> callback) {
// stores grid type into config object
((PagingLoadConfig) loadConfig).set("gridType", GRID_TYPE);

// stores parameters map into config object
((PagingLoadConfig) loadConfig).set("parameters", parametersMap);

// loads data
service.load((PagingLoadConfig) loadConfig, callback);
}
};
parametersMap is declared as Map<String, Object>, but at runtime it is an HashMap<String, HRSuiteFormatTypes>, where HRSuiteFormatTypes is this enumeration:


public enum HRSuiteFormatTypes {
NONE,
DATE, MONTH_NUMBER, PERIOD_MM_YYYY,
IMPORT, EXCHANGE, DISTANCE,
IMPORT_WITH_CURRENCY,
EXP_ACC_STATE, MONTH_STATE,
YES_NO, BOOLEAN
}
Using GWT 1.7 and EXTGWT 2.0.1 this works fine and the grid was loaded without any problem.
Using GWT 2.0.0 and ETXGWT 2.1.0, instead, the grid loading failed with this message (on development mode's console):


12:18:02.483 [ERROR] [HRSuite] Uncaught exception escaped
java.lang.AssertionError: Not enough methods, expecting 3 saw 2
at com.google.gwt.user.client.rpc.impl.SerializerBase.check(SerializerBase.java:165)
at com.google.gwt.user.client.rpc.impl.SerializerBase.serialize(SerializerBase.java:145)
at com.google.gwt.user.client.rpc.impl.ClientSerializationStreamWriter.serialize(ClientSerializationStreamWriter.java:199)
at com.google.gwt.user.client.rpc.impl.AbstractSerializationStreamWriter.writeObject(AbstractSerializationStreamWriter.java:129)
at com.google.gwt.user.client.rpc.core.java.util.Map_CustomFieldSerializerBase.serialize(Map_CustomFieldSerializerBase.java:50)
at com.google.gwt.user.client.rpc.core.java.util.HashMap_CustomFieldSerializer.serialize(HashMap_CustomFieldSerializer.java:36)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:157)
at com.google.gwt.dev.shell.BrowserChannel.reactToMessagesWhileWaitingForReturn(BrowserChannel.java:1713)
at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:165)
at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:120)
at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:507)
at com.google.gwt.dev.shell.ModuleSpace.invokeNativeVoid(ModuleSpace.java:284)
at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeVoid(JavaScriptHost.java:107)
at com.google.gwt.user.client.rpc.impl.SerializerBase$MethodMap$.serialize$(SerializerBase.java)
at com.google.gwt.user.client.rpc.impl.SerializerBase.serialize(SerializerBase.java:147)
at com.google.gwt.user.client.rpc.impl.ClientSerializationStreamWriter.serialize(ClientSerializationStreamWriter.java:199)
at com.google.gwt.user.client.rpc.impl.AbstractSerializationStreamWriter.writeObject(AbstractSerializationStreamWriter.java:129)
at com.google.gwt.user.client.rpc.core.java.util.Map_CustomFieldSerializerBase.serialize(Map_CustomFieldSerializerBase.java:50)
at com.google.gwt.user.client.rpc.core.java.util.HashMap_CustomFieldSerializer.serialize(HashMap_CustomFieldSerializer.java:36)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:157)
at com.google.gwt.dev.shell.BrowserChannel.reactToMessagesWhileWaitingForReturn(BrowserChannel.java:1713)
at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:165)
at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:120)
at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:507)
at com.google.gwt.dev.shell.ModuleSpace.invokeNativeVoid(ModuleSpace.java:284)
at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeVoid(JavaScriptHost.java:107)
at com.google.gwt.user.client.rpc.impl.SerializerBase$MethodMap$.serialize$(SerializerBase.java)
at com.google.gwt.user.client.rpc.impl.SerializerBase.serialize(SerializerBase.java:147)
at com.google.gwt.user.client.rpc.impl.ClientSerializationStreamWriter.serialize(ClientSerializationStreamWriter.java:199)
at com.google.gwt.user.client.rpc.impl.AbstractSerializationStreamWriter.writeObject(AbstractSerializationStreamWriter.java:129)
at com.extjs.gxt.ui.client.data.RpcMap_CustomFieldSerializer.serialize(RpcMap_CustomFieldSerializer.java:37)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:157)
at com.google.gwt.dev.shell.BrowserChannel.reactToMessagesWhileWaitingForReturn(BrowserChannel.java:1713)
at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:165)
at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:120)
at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:507)
at com.google.gwt.dev.shell.ModuleSpace.invokeNativeVoid(ModuleSpace.java:284)
at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeVoid(JavaScriptHost.java:107)
at com.google.gwt.user.client.rpc.impl.SerializerBase$MethodMap$.serialize$(SerializerBase.java)
at com.google.gwt.user.client.rpc.impl.SerializerBase.serialize(SerializerBase.java:147)
at com.google.gwt.user.client.rpc.impl.ClientSerializationStreamWriter.serialize(ClientSerializationStreamWriter.java:199)
at com.google.gwt.user.client.rpc.impl.AbstractSerializationStreamWriter.writeObject(AbstractSerializationStreamWriter.java:129)
at com.extjs.gxt.ui.client.data.BaseModelData_FieldSerializer.serialize(BaseModelData_FieldSerializer.java:17)
at com.extjs.gxt.ui.client.data.BaseListLoadConfig_FieldSerializer.serialize(BaseListLoadConfig_FieldSerializer.java:26)
at com.extjs.gxt.ui.client.data.BasePagingLoadConfig_FieldSerializer.serialize(BasePagingLoadConfig_FieldSerializer.java:16)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:157)
at com.google.gwt.dev.shell.BrowserChannel.reactToMessagesWhileWaitingForReturn(BrowserChannel.java:1713)
at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:165)
at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:120)
at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:507)
at com.google.gwt.dev.shell.ModuleSpace.invokeNativeVoid(ModuleSpace.java:284)
at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeVoid(JavaScriptHost.java:107)
at com.google.gwt.user.client.rpc.impl.SerializerBase$MethodMap$.serialize$(SerializerBase.java)
at com.google.gwt.user.client.rpc.impl.SerializerBase.serialize(SerializerBase.java:147)
at com.google.gwt.user.client.rpc.impl.ClientSerializationStreamWriter.serialize(ClientSerializationStreamWriter.java:199)
at com.google.gwt.user.client.rpc.impl.AbstractSerializationStreamWriter.writeObject(AbstractSerializationStreamWriter.java:129)
at it.visiant.hrsuite.client.service.LoadGridService_Proxy.load(LoadGridService_Proxy.java:71)
at it.visiant.hrsuite.client.customwidget.grid.HRSuiteBaseBeanGrid$1.load(HRSuiteBaseBeanGrid.java:264)
at com.extjs.gxt.ui.client.data.RpcProxy.load(RpcProxy.java:21)
at it.visiant.hrsuite.client.customwidget.grid.HRSuiteBaseBeanGrid$1.load(HRSuiteBaseBeanGrid.java:241)
at com.extjs.gxt.ui.client.data.BaseLoader.loadData(BaseLoader.java:134)
at com.extjs.gxt.ui.client.data.BaseLoader.load(BaseLoader.java:98)
at com.extjs.gxt.ui.client.data.BaseLoader.load(BaseLoader.java:92)
at com.extjs.gxt.ui.client.data.BasePagingLoader.load(BasePagingLoader.java:59)
at com.extjs.gxt.ui.client.widget.toolbar.PagingToolBar.doLoadRequest(PagingToolBar.java:680)
at com.extjs.gxt.ui.client.widget.toolbar.PagingToolBar.refresh(PagingToolBar.java:611)
at com.extjs.gxt.ui.client.widget.toolbar.PagingToolBar$6.componentSelected(PagingToolBar.java:430)
at com.extjs.gxt.ui.client.widget.toolbar.PagingToolBar$6.componentSelected(PagingToolBar.java:1)
at com.extjs.gxt.ui.client.event.SelectionListener.handleEvent(SelectionListener.java:20)
at com.extjs.gxt.ui.client.event.SelectionListener.handleEvent(SelectionListener.java:1)
at com.extjs.gxt.ui.client.event.BaseObservable.callListener(BaseObservable.java:178)
at com.extjs.gxt.ui.client.event.BaseObservable.fireEvent(BaseObservable.java:86)
at com.extjs.gxt.ui.client.widget.Component.fireEvent(Component.java:448)
at com.extjs.gxt.ui.client.widget.button.Button.onClick(Button.java:577)
at com.extjs.gxt.ui.client.widget.button.Button.onComponentEvent(Button.java:285)
at com.extjs.gxt.ui.client.widget.Component.onBrowserEvent(Component.java:820)
at com.google.gwt.user.client.DOM.dispatchEventImpl(DOM.java:1307)
at com.google.gwt.user.client.DOM.dispatchEvent(DOM.java:1263)
at sun.reflect.GeneratedMethodAccessor33.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:157)
at com.google.gwt.dev.shell.BrowserChannel.reactToMessagesWhileWaitingForReturn(BrowserChannel.java:1713)
at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:165)
at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:120)
at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:507)
at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:264)
at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:91)
at com.google.gwt.core.client.impl.Impl.apply(Impl.java)
at com.google.gwt.core.client.impl.Impl.entry0(Impl.java:188)
at sun.reflect.GeneratedMethodAccessor25.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:157)
at com.google.gwt.dev.shell.BrowserChannel.reactToMessages(BrowserChannel.java:1668)
at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:401)
at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:222)
at java.lang.Thread.run(Thread.java:619)
This error is raised by an assertion in com.google.gwt.user.client.rpc.impl.SerializerBase (line 164).

I tryied to replace the replace parametersMap with a simple


((PagingLoadConfig) loadConfig).set("parameters",HRSuiteFormatTypes.EXCHANGE);
but nothing changes ...
Instead if i declare parametersMap has Map<String, String> all works fine.

Another test that i have done is to use the same enumeration in a simple GWTservice: serialization and deserialization are done without any problem.

I've checked .gwt.rpc file too: the enumeration is listed, so GWT must know that it must be serialized/deserialized.

At this point, i think that is a problem with rpcproxy, but i don't have any idea about a possibile solution..

Someone have any idea can be usefull?

Thanks a lot

jc-perez
22 Jan 2010, 1:16 PM
Hi,

I'm expecting the same issue on my application. In my case, I have a list of object as a bean inside the main bean class. For example,

public class LoginWindowModel extends BaseModelData{

.....

public int getClientID() {
return get("clientID");
}

public List<LookupValue> getClientsList() {
return get("clientList");
}

.....

}

Where LookupValue class is:

public class LookupValue extends BaseModel{

.............

public String getKey() {
return get("key");
}

public String getValue() {
return get("value");
}

public void setKey(String key) {
set("key",key);
}

public void setValue(String value) {
set("value",value);
}

}

Have you found any way to fix this issue?

Thank you

Aphrel
23 Jan 2010, 11:00 AM
Seems that there is a bug (don't know if in GWT or in EXTGWT): some types are not serialized if they are located inside a complex structure, like a map, a list, a bean inside anohter bean, and so on ...

I've found a workaround for this issue.

Just create a new class, in a package under GWT client package, that contains one attribute for every types that must be serialized becouse are involved in a rpc call.
For simplicity i suggest to include all your custom types and standard java types too (like String, Boolean, Double, ...).

Now you have to modify the signature of GWT services that have complex parameter (like map, list, bean with other bean as attributes, ...) adding a new parameter having the bean descripted above as type.

You can pass null as value of this paramater when you call the service.

In this way all types needed by the service are present as "simple" types: the compiler can now serialize all types even if they are located inside a map, list or another complex structure.

I know that isn't a really good solution, but is the one i've found quickly.

becevka
24 Jan 2010, 10:02 PM
http://code.google.com/p/google-web-toolkit/issues/detail?id=4460&q=milestone%3D2_0_1&sort=milestone
Maybe this is somehow connected with.

jc-perez
26 Jan 2010, 9:44 AM
I downloaded the GWT Trunk and built the new distribution ( probably GWT-2.0.1 ), and I'm still getting the same error. I don't know what the problem could be :S

cgokey2
2 Mar 2010, 6:24 AM
I just ran into this issue too... I've got a object that also extends BaseModelData and contains a complex type and experiencing this:

java.lang.AssertionError: Not enough methods, expecting 3 saw 2 at com.google.gwt.user.client.rpc.impl.SerializerBase.check(SerializerBase.java:165) at com.google.gwt.user.client.rpc.impl.SerializerBase.serialize(SerializerBase.java:145) at com.google.gwt.user.client.rpc.impl.ClientSerializationStreamWriter.serialize(ClientSerializationStreamWriter.java:199) at com.google.gwt.user.client.rpc.impl.AbstractSerializationStreamWriter.writeObject(AbstractSerializationStreamW

Any fixed yet? Has anyone submitted this as a bug yet to the GXT group (if it is a GXT bug... suppose it could be a GWT bug)

Thanks,
Chris

cgokey2
2 Mar 2010, 6:41 AM
I did a workaround similar to the above post:

I had a BaseModelData object that had this method:

public ArrayList<RoleDTO> getRoles() {
return get(ROLES);
}

public void setRoles(ArrayList<RoleDTO> roles) {
set(ROLES, roles);
}

I just added an instance variable to this class and do nothing with it:

List<RoleDTO> r;

And simply adding the instance variable did the trick.
Chris

devcybiko
9 Jun 2010, 1:45 PM
It seems that if an object is not directly or indirectly delivered to the server via a service.myServiceName(foo, callback) method, a serializer is not created for the object. To remedy this, I put a member for every object I send in my main object: MidwarePropertyGroupDTO (source clipping below). This is enough to get GWT_Compile to generate a serializer for the objects.



@SuppressWarnings("unused")
public class MidwarePropertyGroupDTO extends BaseModelData implements Serializable {
private static final long serialVersionUID = -3159026563230034370L;
private MidwarePropertyDTO midwareProperties;
private List<MidwarePropertyGroupDTO> midwarePropertyGroups;
private String typeKey;
private String key;
private Map<String, RelationalPropertyDTO> relationalProperties; // hashmap of rp's. rp type key is used for key
private boolean RPG;
private String entityKey;
private boolean isNew = false;
private boolean isSubType = false;
private String subTypeKey;
private String subTypeName;
private String rpTypeKey;

/* TODO
* these dummy items force a serialzation method to be created.
* this is a workaround for GWT 2.0.3
* *
* if you get the error "java.lang.AssertionError: Not enough methods, expecting 3 saw 2"
* or "Exception (TypeError): d[c][2] is not a function"
* be sure that all the DTO objects are represented here...
*
*/
private AssociationDTO associationDTO;
private FileUploadDTO fileUploadDTO;
private MidwareCategorizedChoicesDTO midwareCategorizedChoicesDTO;
private MidwareChoiceDTO midwareChoiceDTO;
private MidwarePropertyDTO midwarePropertyDTO;
private MidwarePropertyGroupDTO midwarePropertyGroupDTO;
private MidwarePropertyGroupTypeDTO midwarePropertyGroupTypeDTO;
private MidwarePropertyTypeDTO midwarePropertyTypeDTO;
private MidwarePropertyTypeFormatDTO midwarePropertyTypeFormatDTO;
private MidwareRelationalPropertyDTO midwareRelationalPropertyDTO;
private RelationalPropertyDTO relationalPropertyDTO;
private RelationalPropertyGroupReferenceDTO relationalPropertyGroupReferenceDTO;
private RelationalPropertyTypeDTO relationalPropertyTypeDTO;
private SimpleMidwarePropertyGroupTypeDTO simpleMidwarePropertyGroupTypeDTO;
private StatusDTO statusDTO;
private SymbolTreeDTO symbolTreeDTO;
private TimeZoneDTO timeZoneDTO;
private UserDTO userDTO;

dave.shepherd
14 Jun 2010, 4:08 AM
I've had a similar issue after upgrading to GWT 2.0.3. When setting a custom type as a property on a ListLoadConfig RPC parameter used to populate a ComboBox. The same code worked fine using GWT 1.7.

This change was introduced in GWT for version 2; before this, if a type was to be sent to the server both the serialise and deserialise code was created on the client side, even if the deserialise code was not needed (i.e. the type is only used as an input parameter, not an output parameter to the RPC servlet).

It worked previously for me because my custom type also happened to be an attribute of the output parameter. With the upgrade to GWT 2.0.3 the serialisation code was no longer being created so it wasn't there to execute when it was being passed as an input parameter.

The solutions suggested above should work fine. Either explicitally define the type causing the issue as an attribute of the parent class or pass it in explicitly as an input paramter to the RPC method.

I have been assured that this is not a bug with GWT. However, it is certainly not clear what the problem is when you're presented with the error:

"java.lang.AssertionError: Not enough methods, expecting 3 saw 2"

I would be interested to hear other views on this.

Colin Alworth
15 Jun 2010, 9:20 AM
The error "java.lang.AssertionError: Not enough methods, expecting 3 saw 2" is a GWT error, as it is only finding the deserialize method and instantiate method, not the require serialize method in the serialization class. GWT was able to infer that you will be downloading the type, but couldn't be certain that you would upload it, so it didn't bother to write that method.

This is common with the map based objects that need to be created to use GXT's grid and template code - some RPC interface makes it clear that the client might get a type back from the server, but never is clear that the client can send it to the server. If we had reflection, or some other way that templates and the like could be generated, we could allow the developer instead to send POJOs over the wire, which could never have this bug, as they are not backed by a Map<String, Object>. With the great power of psuedo-reflection comes the pain-in-the-ass responsibility of being crystal clear about what types an object might contain.