users@jersey.java.net

Re: [Jersey] Jersey client in Servlet

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Tue, 29 Dec 2009 11:57:22 +0100

Hi Andreas,

It seems there may be some restriction in the loading of classes,
although i am surprised that such behavior would occur from within a
basic Servlet.

Can you verify that the Servlet fails with a similar error if you
replace the get(new GenericType) with get(String.class) ?

If it does try the following:

   if (client == null) {
     ClassLoader cl = Thread.currentThread().getContextClassLoader();
     try {
        
Thread
.currentThread
().setContextClassLoader(this.getClass().getClassLoader());
        client = Client.create();
     } finally {
       Thread.currentThread().setContextClassLoader(cl);
     }
   }

Paul.

On Dec 29, 2009, at 10:08 AM, xworker wrote:

> Hi I created a servlet that should function as a jersey client. But
> there seems to be problems with readers when using the Servlet. The
> same client call works in my JSF bean, but when I put it in a
> separate servlet it doesnt work. This is the client call: if (client
> == null) { client = Client.create(); } MultivaluedMap queryParams =
> new MultivaluedMapImpl(); queryParams.add("lang", lang); wr =
> client.resource(PermitUtil.getPermitBackendUrl("") + "/
> allPermitsViews"); permitList = wr.queryParams(queryParams).get(new
> GenericType>() { }); and the error message is:
> com.sun.jersey.api.client.ClientHandlerException: A message body
> reader for Java type, interface java.util.List, and MIME media type,
> application/xml, was not found at
> com
> .sun.jersey.api.client.ClientResponse.getEntity(ClientResponse.java:
> 255) at
> com
> .sun.jersey.api.client.ClientResponse.getEntity(ClientResponse.java:
> 237) at
> com.sun.jersey.api.client.WebResource.handle(WebResource.java:572)
> at com.sun.jersey.api.client.WebResource.get(WebResource.java:183)
> Thanks /Andreas
> View this message in context: Jersey client in Servlet
> Sent from the Jersey mailing list archive at Nabble.com.