6 Replies Latest reply on Oct 9, 2010 2:37 PM by Mike Brock

    Casting to wrong class during decoding rpc response.

    Marcin Misiewicz Newbie

      Hi

       

      I've got another problem with serialization, Here is the stack trace :

       

      23:29:16.908 [ERROR] [basic] Failure decoding object
      java.lang.RuntimeException: could not demarshall type: pl.scentia.smartoffice.persistence.pojo.assignments.UserAssignment; value={"__EncodedType":"pl.scentia.smartoffice.persistence.pojo.assignments.UserAssignment", "__ObjectID":"1987", "id":1, "active":true, "login":"admin", "password":"ISMvKXpXpadDiUoOSoAfww==", "userRoles":[{"__EncodedType":"pl.scentia.smartoffice.persistence.pojo.assignments.UserRole", "__ObjectID":"2", "id":1, "role":{"__EncodedType":"pl.scentia.smartoffice.persistence.pojo.common.RoleType", "EnumStringValue":"USER"}, "selected":false, "deleted":false, "ownerGroup":null, "createDate":1285110213317, "createUser":null, "lastModifyDate":1285110213317, "lastModifyUser":null},{"__EncodedType":"pl.scentia.smartoffice.persistence.pojo.assignments.UserRole", "__ObjectID":"3", "id":2, "role":{"__EncodedType":"pl.scentia.smartoffice.persistence.pojo.common.RoleType", "EnumStringValue":"ADMIN"}, "selected":false, "deleted":false, "ownerGroup":null, "createDate":1285110213322, "createUser":null, "lastModifyDate":1285110213322, "lastModifyUser":null}], "groups":[{"__EncodedType":"pl.scentia.smartoffice.persistence.pojo.Group", "__ObjectID":"2", "id":1, "name":"Scentia", "description":"Scentia", "groups":null, "parent":null, "users":null, "superGroup":true, "selected":false, "deleted":false, "ownerGroup":null, "createDate":1285110213015, "createUser":{"__EncodedType":"pl.scentia.smartoffice.persistence.pojo.assignments.UserAssignment", "__ObjectID":"$1987"}, "lastModifyDate":1285110213379, "lastModifyUser":{"__EncodedType":"pl.scentia.smartoffice.persistence.pojo.assignments.UserAssignment", "__ObjectID":"$1987"}}], "emails":null, "commonGroups":[], "superGroups":[{"__EncodedType":"pl.scentia.smartoffice.persistence.pojo.Group", "__ObjectID":"$2"}], "sourceUnit":{"__EncodedType":"pl.scentia.smartoffice.persistence.pojo.OrganizationUnit", "__ObjectID":"3", "id":2, "unitType":{"__EncodedType":"pl.scentia.smartoffice.persistence.pojo.common.UnitType", "EnumStringValue":"PERSON"}, "legalForm":null, "newsletter":false, "active":true, "description":null, "name":"Piotr", "fullName":"Nowak", "nip":null, "regon":null, "pesel":null, "birthDate":null, "addresses":null, "phones":null, "emails":null, "domains":null, "number":null, "selected":false, "deleted":false, "ownerGroup":{"__EncodedType":"pl.scentia.smartoffice.persistence.pojo.Group", "__ObjectID":"$2"}, "createDate":1285110213263, "createUser":{"__EncodedType":"pl.scentia.smartoffice.persistence.pojo.assignments.UserAssignment", "__ObjectID":"$1987"}, "lastModifyDate":1285110213393, "lastModifyUser":{"__EncodedType":"pl.scentia.smartoffice.persistence.pojo.assignments.UserAssignment", "__ObjectID":"$1987"}}, "destinationUnit":{"__EncodedType":"pl.scentia.smartoffice.persistence.pojo.OrganizationUnit", "__ObjectID":"2", "id":1, "unitType":{"__EncodedType":"pl.scentia.smartoffice.persistence.pojo.common.UnitType", "EnumStringValue":"ORGANIZATION"}, "legalForm":null, "newsletter":false, "active":true, "description":null, "name":"Scentia", "fullName":"Scentia", "nip":null, "regon":null, "pesel":null, "birthDate":null, "addresses":null, "phones":null, "emails":null, "domains":null, "number":null, "selected":false, "deleted":false, "ownerGroup":{"__EncodedType":"pl.scentia.smartoffice.persistence.pojo.Group", "__ObjectID":"$2"}, "createDate":1285110213253, "createUser":{"__EncodedType":"pl.scentia.smartoffice.persistence.pojo.assignments.UserAssignment", "__ObjectID":"$1987"}, "lastModifyDate":1285110213393, "lastModifyUser":{"__EncodedType":"pl.scentia.smartoffice.persistence.pojo.assignments.UserAssignment", "__ObjectID":"$1987"}}, "number":null, "selected":false, "deleted":false, "ownerGroup":{"__EncodedType":"pl.scentia.smartoffice.persistence.pojo.Group", "__ObjectID":"$2"}, "createDate":1285110213253, "createUser":null, "lastModifyDate":1285110213253, "lastModifyUser":null}
      
      
      23:29:16.908 [ERROR] [basic] Failure decoding object
      java.lang.RuntimeException: could not demarshall type: pl.scentia.smartoffice.persistence.pojo.assignments.UserAssignment; 
      value={"__EncodedType":"pl.scentia.smartoffice.persistence.pojo.assignments.UserAssignment", "__ObjectID":"1987", "id":1, "active":true, "login":"admin", "password":"ISMvKXpXpadDiUoOSoAfww==", "userRoles":[{"__EncodedType":"pl.scentia.smartoffice.persistence.pojo.assignments.UserRole", "__ObjectID":"2", "id":1, "role":{"__EncodedType":"pl.scentia.smartoffice.persistence.pojo.common.RoleType", "EnumStringValue":"USER"}, "selected":false, "deleted":false, "ownerGroup":null, "createDate":1285110213317, "createUser":null, "lastModifyDate":1285110213317, "lastModifyUser":null},{"__EncodedType":"pl.scentia.smartoffice.persistence.pojo.assignments.UserRole", "__ObjectID":"3", "id":2, "role":{"__EncodedType":"pl.scentia.smartoffice.persistence.pojo.common.RoleType", "EnumStringValue":"ADMIN"}, "selected":false, "deleted":false, "ownerGroup":null, "createDate":1285110213322, "createUser":null, "lastModifyDate":1285110213322, "lastModifyUser":null}], "groups":[{"__EncodedType":"pl.scentia.smartoffice.persistence.pojo.Group", "__ObjectID":"2", "id":1, "name":"Scentia", "description":"Scentia", "groups":null, "parent":null, "users":null, "superGroup":true, "selected":false, "deleted":false, "ownerGroup":null, "createDate":1285110213015, "createUser":{"__EncodedType":"pl.scentia.smartoffice.persistence.pojo.assignments.UserAssignment", "__ObjectID":"$1987"}, "lastModifyDate":1285110213379, "lastModifyUser":{"__EncodedType":"pl.scentia.smartoffice.persistence.pojo.assignments.UserAssignment", "__ObjectID":"$1987"}}], "emails":null, "commonGroups":[], "superGroups":[{"__EncodedType":"pl.scentia.smartoffice.persistence.pojo.Group", "__ObjectID":"$2"}], "sourceUnit":{"__EncodedType":"pl.scentia.smartoffice.persistence.pojo.OrganizationUnit", "__ObjectID":"3", "id":2, "unitType":{"__EncodedType":"pl.scentia.smartoffice.persistence.pojo.common.UnitType", "EnumStringValue":"PERSON"}, "legalForm":null, "newsletter":false, "active":true, "description":null, "name":"Piotr", "fullName":"Nowak", "nip":null, "regon":null, "pesel":null, "birthDate":null, "addresses":null, "phones":null, "emails":null, "domains":null, "number":null, "selected":false, "deleted":false, "ownerGroup":{"__EncodedType":"pl.scentia.smartoffice.persistence.pojo.Group", "__ObjectID":"$2"}, "createDate":1285110213263, "createUser":{"__EncodedType":"pl.scentia.smartoffice.persistence.pojo.assignments.UserAssignment", "__ObjectID":"$1987"}, "lastModifyDate":1285110213393, "lastModifyUser":{"__EncodedType":"pl.scentia.smartoffice.persistence.pojo.assignments.UserAssignment", "__ObjectID":"$1987"}}, "destinationUnit":{"__EncodedType":"pl.scentia.smartoffice.persistence.pojo.OrganizationUnit", "__ObjectID":"2", "id":1, "unitType":{"__EncodedType":"pl.scentia.smartoffice.persistence.pojo.common.UnitType", "EnumStringValue":"ORGANIZATION"}, "legalForm":null, "newsletter":false, "active":true, "description":null, "name":"Scentia", "fullName":"Scentia", "nip":null, "regon":null, "pesel":null, "birthDate":null, "addresses":null, "phones":null, "emails":null, "domains":null, "number":null, "selected":false, "deleted":false, "ownerGroup":{"__EncodedType":"pl.scentia.smartoffice.persistence.pojo.Group", "__ObjectID":"$2"}, "createDate":1285110213253, "createUser":{"__EncodedType":"pl.scentia.smartoffice.persistence.pojo.assignments.UserAssignment", "__ObjectID":"$1987"}, "lastModifyDate":1285110213393, "lastModifyUser":{"__EncodedType":"pl.scentia.smartoffice.persistence.pojo.assignments.UserAssignment", "__ObjectID":"$1987"}}, "number":null, "selected":false, "deleted":false, "ownerGroup":{"__EncodedType":"pl.scentia.smartoffice.persistence.pojo.Group", "__ObjectID":"$2"}, "createDate":1285110213253, "createUser":null, "lastModifyDate":1285110213253, "lastModifyUser":null}
          at org.jboss.errai.bus.client.ext.ExtensionsLoaderImpl$45.demarshall(ExtensionsLoaderImpl.java:3186)
          at org.jboss.errai.bus.client.ext.ExtensionsLoaderImpl$45.demarshall(ExtensionsLoaderImpl.java:1)
          at org.jboss.errai.common.client.json.JSONDecoderCli.decodeObject(JSONDecoderCli.java:113)
          at org.jboss.errai.common.client.json.JSONDecoderCli._decode(JSONDecoderCli.java:80)
          at org.jboss.errai.common.client.json.JSONDecoderCli.decodeObject(JSONDecoderCli.java:129)
          at org.jboss.errai.common.client.json.JSONDecoderCli._decode(JSONDecoderCli.java:80)
          at org.jboss.errai.common.client.json.JSONDecoderCli.decode(JSONDecoderCli.java:62)
          at org.jboss.errai.bus.client.json.JSONUtilCli.decodeMap(JSONUtilCli.java:91)
          at org.jboss.errai.bus.client.json.JSONUtilCli.decodeCommandMessage(JSONUtilCli.java:102)
          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:1714)
          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 org.jboss.errai.bus.client.framework.ClientMessageBusImpl._store(ClientMessageBusImpl.java)
          at org.jboss.errai.bus.client.framework.ClientMessageBusImpl.procIncomingPayload(ClientMessageBusImpl.java:1121)
          at org.jboss.errai.bus.client.framework.ClientMessageBusImpl.access$7(ClientMessageBusImpl.java:1118)
          at org.jboss.errai.bus.client.framework.ClientMessageBusImpl$LongPollRequestCallback.onResponseReceived(ClientMessageBusImpl.java:881)
          at com.google.gwt.http.client.Request.fireOnResponseReceived(Request.java:287)
          at com.google.gwt.http.client.RequestBuilder$1.onReadyStateChange(RequestBuilder.java:393)
          at sun.reflect.GeneratedMethodAccessor75.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:1714)
          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.GeneratedMethodAccessor74.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:1669)
          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)
      Caused by: java.lang.ClassCastException: pl.scentia.smartoffice.persistence.pojo.assignments.UserRole cannot be cast to pl.scentia.smartoffice.persistence.pojo.OrganizationUnit
          at org.jboss.errai.bus.client.ext.ExtensionsLoaderImpl$45.demarshall(ExtensionsLoaderImpl.java:3109)
          at org.jboss.errai.bus.client.ext.ExtensionsLoaderImpl$45.demarshall(ExtensionsLoaderImpl.java:1)
          at org.jboss.errai.common.client.json.JSONDecoderCli.decodeObject(JSONDecoderCli.java:113)
          at org.jboss.errai.common.client.json.JSONDecoderCli._decode(JSONDecoderCli.java:80)
          at org.jboss.errai.common.client.json.JSONDecoderCli.decodeObject(JSONDecoderCli.java:129)
          at org.jboss.errai.common.client.json.JSONDecoderCli._decode(JSONDecoderCli.java:80)
          at org.jboss.errai.common.client.json.JSONDecoderCli.decode(JSONDecoderCli.java:62)
          at org.jboss.errai.bus.client.json.JSONUtilCli.decodeMap(JSONUtilCli.java:91)
          at org.jboss.errai.bus.client.json.JSONUtilCli.decodeCommandMessage(JSONUtilCli.java:102)
          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:1714)
          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 org.jboss.errai.bus.client.framework.ClientMessageBusImpl._store(ClientMessageBusImpl.java)
          at org.jboss.errai.bus.client.framework.ClientMessageBusImpl.procIncomingPayload(ClientMessageBusImpl.java:1121)
          at org.jboss.errai.bus.client.framework.ClientMessageBusImpl.access$7(ClientMessageBusImpl.java:1118)
          at org.jboss.errai.bus.client.framework.ClientMessageBusImpl$LongPollRequestCallback.onResponseReceived(ClientMessageBusImpl.java:881)
          at com.google.gwt.http.client.Request.fireOnResponseReceived(Request.java:287)
          at com.google.gwt.http.client.RequestBuilder$1.onReadyStateChange(RequestBuilder.java:393)
          at sun.reflect.GeneratedMethodAccessor75.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:1714)
          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.GeneratedMethodAccessor74.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:1669)
          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)
      

       

      It looks like during demarshalling of the object, being the response of the rpc call, errai tries to cast one of its member objects to the different class.

      I have a testng test case which checks if encoding/decoding works well for my object graph using JSONEncoder and JSONDecoder. And

      using JSONEncoder/Decoder works as expected so it seems like this problem lies on the client side.

       

      If you need my entity classes I can post them.

       

      If this is important, object returned by the rpc call has been cloned by gilead PersistentBeanManager.

      BTW. Is there any way to inject HttpSession object into custom ModelAdapter object. I do need this because of using gilead InMemoryProxyStore is not a good idea.

        • 1. Re: Casting to wrong class during decoding rpc response.
          Marcin Misiewicz Newbie

          It seems that I post the message to early.

           

          That's because when the rpc service returns the same object but created "by hand", not retrieved from persistence storage, it seems like encoding/decoding is working as expected. So I have to take a closer look at gilead cloning/merging process.

           

          Once again sorry for the rush and spamming

          • 2. Re: Casting to wrong class during decoding rpc response.
            Heiko Braun Master

            I was just going to say "Did you try w/o the gilead adapter?". Keep me posted on this one.

            However for the remaining issue (ModelAdapter & HTTPSession) I've created a JIRA:

            https://jira.jboss.org/browse/ERRAI-112

            • 3. Re: Casting to wrong class during decoding rpc response.
              Marcin Misiewicz Newbie

              Well I guess I've found the place where ther problem lies in.

               

              In the DecodingContext class you are storing the decoded objects  in the objects property. The key of this HashMap is the String which comes from ObjectID and actually this is the hashCode value of the object.

              Unfortunately in our application hashCode value can be the same for different kind of objects, but cannot be the same for the same object types

              (which is compliant with the java specification).

               

              That's way when I created object by hand it was working (I didn't setup all the fields, especially the id of the entity which plays the main role in the hashCode generation) but when the object was retrieved from database it couldn't work (the same hashCodes for different kind of objects).

               

              I guess the lookup key in DecodingContext should be encodedType value + "$" + objectid value.

              Of course the gilead has nothing to do with this issue.

               

              BTW. My implementation of the persistence extension uses entitymanagerfactory or hibernate sessionfactory retrieved from jndi, so there is no need to configure factory by hand. The user has to configure jndi and write that jndi name into the erraiservice.properties. I guess it's better approach. We use JPA so I've tested it only with JPA, but it should work with plain hibernate as well. The only thing is missing is how can we get reference to the http session inside model adapter. I can commit that to the git if you like.

              • 4. Re: Casting to wrong class during decoding rpc response.
                Heiko Braun Master

                Marcin Misiewicz wrote:

                 

                BTW. My implementation of the persistence extension uses entitymanagerfactory or hibernate sessionfactory retrieved from jndi, so there is no need to configure factory by hand. The user has to configure jndi and write that jndi name into the erraiservice.properties. I guess it's better approach. We use JPA so I've tested it only with JPA, but it should work with plain hibernate as well. The only thing is missing is how can we get reference to the http session inside model adapter. I can commit that to the git if you like.

                 

                yeah, that would be great. Simply send me a pull request through github.

                • 5. Re: Casting to wrong class during decoding rpc response.
                  Heiko Braun Master

                  As for the DecodingContext lookup: I'll let Mike respond to this. Cause he did work on that one before.

                  • 6. Re: Casting to wrong class during decoding rpc response.
                    Mike Brock Master

                    Sorry for the late reply.  We've been really busy working on some other stuff that dovetails with Errai that we're trying to have done by the end of the year.  If you were willing to submit a patch for the problem -- since you seem to have a good grasp on it -- I'd be more than happy to integrate it! 

                     

                    Otherwise, I can try and get to this next week.