ClientResource.wrap with Result<> callback

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

ClientResource.wrap with Result<> callback

Bill Claypool
I'm using 2.1-RC1

I have a resource interface with a get method which returns an enum: DrState.  I have included a callback signature in the interface:
  @Get("json")
  DrState getDrState();

  @Get("json")
  void getDrState( Result<DrState> callback );

When I use the synchronous version, everything works. If I use the callback version, I see an exception logged and onSuccess() is called with null.

Running in the debugger and looking at the code, I see in org.restlet.engine.resource.ClientInvocationHandler<T>:

  result = getClientResource().toObject(
                 response.getEntity(),
                 actualType.getClass());

At this point, actualType is correctly the class of my enum.  However, actualType.getClass() is Class.class.

Based on my (limited) reading of the code, I think this should be passing actualType instead of actualType.getClass().


The logged stack trace:
Unable to parse the object with Jackson.

org.codehaus.jackson.map.JsonMappingException: Can not construct instance of java.lang.Class, problem: NEUTRAL
 at [Source: org.restlet.engine.io.NbChannelInputStream@627b5c; line: 1, column: 1]
        at org.codehaus.jackson.map.JsonMappingException.from(JsonMappingException.java:169)
        at org.codehaus.jackson.map.deser.StdDeserializationContext.instantiationException(StdDeserializationContext.java:204)
        at org.codehaus.jackson.map.deser.StdDeserializer$ClassDeserializer.deserialize(StdDeserializer.java:714)
        at org.codehaus.jackson.map.deser.StdDeserializer$ClassDeserializer.deserialize(StdDeserializer.java:685)
        at org.codehaus.jackson.map.ObjectMapper._readMapAndClose(ObjectMapper.java:2395)
        at org.codehaus.jackson.map.ObjectMapper.readValue(ObjectMapper.java:1641)
        at org.restlet.ext.jackson.JacksonRepresentation.getObject(JacksonRepresentation.java:136)
        at org.restlet.ext.jackson.JacksonConverter.toObject(JacksonConverter.java:163)
        at org.restlet.service.ConverterService.toObject(ConverterService.java:164)
        at org.restlet.resource.Resource.toObject(Resource.java:715)
        at org.restlet.engine.resource.ClientInvocationHandler$1.handle(ClientInvocationHandler.java:163)
        at org.restlet.engine.connector.ClientConnectionHelper.doHandleInbound(ClientConnectionHelper.java:217)
        at org.restlet.engine.connector.BaseHelper$2.run(BaseHelper.java:585)
        at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
        at java.lang.Thread.run(Thread.java:662)
Caused by: java.lang.ClassNotFoundException: NEUTRAL
        at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:169)
        at org.codehaus.jackson.map.deser.StdDeserializer$ClassDeserializer.deserialize(StdDeserializer.java:712)
        ... 13 more

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2880706
Reply | Threaded
Open this post in threaded view
|

RE: ClientResource.wrap with Result<> callback

Bill Claypool
I also see the same failure in 2.0.10 except that the stack trace is a bit different because of a fair bit of refactoring between 2.0 and 2.1 (e.g. in 2.0, ClientInvocationHandler in an anonymous inner class in ClientResource.

So, the question is: Is this a bug? Does my assessment of the problem seem correct?  Would it be fixed by passing "actualType" instead of "actualType.getClass()"?

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2883326
Reply | Threaded
Open this post in threaded view
|

RE: ClientResource.wrap with Result<> callback

jlouvel
Administrator
Hi Bill,

This indeed looks like a bug. I've fixed it based on your suggestion in both
SVN trunk and 2.0 branch.
Could you confirm it works with the next 2.1 snapshot?

Best regards,
Jerome
--
http://www.restlet.org
http://twitter.com/#!/jlouvel




-----Message d'origine-----
De : Bill Claypool [mailto:[hidden email]]
Envoyé : lundi 21 novembre 2011 17:50
À : [hidden email]
Objet : RE: ClientResource.wrap with Result<> callback

I also see the same failure in 2.0.10 except that the stack trace is a bit
different because of a fair bit of refactoring between 2.0 and 2.1 (e.g. in
2.0, ClientInvocationHandler in an anonymous inner class in ClientResource.

So, the question is: Is this a bug? Does my assessment of the problem seem
correct?  Would it be fixed by passing "actualType" instead of
"actualType.getClass()"?

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=28833
26

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2885134
Reply | Threaded
Open this post in threaded view
|

RE: ClientResource.wrap with Result<> callback

Bill Claypool
Jerome,

Thanks for the quick turnaround. I'll check it out in the next snapshot

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2885166