Hi,

This is still broken. A simple use of ClientResource like this:

ClientResource resource = new 
ClientResource("http://api.bitly.com/v3/shorten?login="; + bitlyUser + 
"&apiKey=" + bitlyKey + "&longUrl=" +              longUrl + "&format=json");
String result = resource.get().getText();

within the context a JaxRsApplication application breaks with two exceptions:

By default, the outbound root of an application can't handle calls without 
being attached to a parent component.
Internal Server Error (500) - The server isn't properly configured to handle 
client calls.
        at org.restlet.resource.ClientResource.doError(ClientResource.java:484)
        at org.restlet.resource.ClientResource.handle(ClientResource.java:917)
        at org.restlet.resource.ClientResource.handle(ClientResource.java:888)
        at org.restlet.resource.ClientResource.handle(ClientResource.java:808)
        at org.restlet.resource.ClientResource.get(ClientResource.java:530)
etc...

and then:

java.lang.IllegalStateException: No CallContext given until now
        at 
org.restlet.ext.jaxrs.internal.core.ThreadLocalizedContext.get(ThreadLocalizedContext.java:123)
        at 
org.restlet.ext.jaxrs.JaxRsRestlet.handleResult(JaxRsRestlet.java:742)
        at org.restlet.ext.jaxrs.JaxRsRestlet.handle(JaxRsRestlet.java:688)
etc...

When I explicitly set an outbound root to the JaxRsApplication like this:

final JaxRsApplication servicesApplication = 
            new JaxRsApplication(server.getContext().createChildContext());
servicesApplication.setOutboundRoot(new 
   Client(server.getContext().createChildContext(),
                                            Arrays.asList(Protocol.HTTP, 
Protocol.HTTPS)));

The first exception disappears and the ClientResource.get call works. However, 
the second exception remains. I have no idea what an "outbound root" is, and 
couldn't find documentation about it, so the setOutboundRoot line above is 
guesswork. And it's a bit frustrating that it forced me to add the "big" apache 
HTTP client&core jars. 

All I want is to hit an HTTP server and get back a response. I'm not sure why 
this has anything to do with the current execution context, the request I'm 
handling, the components I've configured etc. I tried passing a null context to 
the ClientResource constructor, but it ends up getting the thread-bound context 
anyways. 

The second exception is especially weird since it seems a CallContext is being 
set right before it fails to find it. 

This is with 2.1m5.

My workaround is to use write my own HTTP client.

Best Regards,
Boris

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

Reply via email to