users@jersey.java.net

[Jersey] Re: jersey-proxy-client with 1.x and generic collection return types

From: Martin Matula <martin.matula_at_oracle.com>
Date: Mon, 16 Jul 2012 11:11:58 +0200

Hi,
Please see below:

On 7/11/12 7:52 AM, Guy Rouillier wrote:
> I like the concept the Jersey proxy client; it enables much more
> natural usage of web services on the client side. We are using Jersey
> 1.x since 2.0 is still in development. I see the the proxy client
> module has the revision tag for version 1.13 (revision 5739) so I
> checked that out and built it. It somewhat works following the
> supplied example for simple return types (single instance classes, not
> collections.) I say somewhat because I couldn't get it to build
> properly if I just had the annotations on the interface; I had to
> repeat the same annotations on the resource class, or Jersey wouldn't
> create the resource at run time.

This is by design. When using any kind of scanning (package/classpath),
it only finds classes annotated by @Path (i.e. the semantics is not to
find all resources, it is to find all classes annotated by some
annotation). Instead of using scanning, you can create a subclass of
DefaultResourceConfig and add your resources to the collection of
classes manually (like I did in the sample).
>
> However, I've been struggling (unsuccessfully) for two days now trying
> to get methods working that return generic collections. For example,
> with the following web service method:
>
> @GET
> @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
> @Path("listByProspectiveCustomer")
> public List<Contact>
> getProspectiveContactListByCustomer(@QueryParam("id") String customerId);
>
> The invocation gets to the server, and the server returns the result
> to the client. But then the client gets this error:
>
> Jul 10, 2012 11:21:26 PM com.sun.jersey.api.client.ClientResponse
> getEntity
> SEVERE: A message body reader for Java class java.util.List, and Java
> type interface java.util.List, and MIME media type application/xml was
> not found
> Jul 10, 2012 11:21:26 PM com.sun.jersey.api.client.ClientResponse
> getEntity
> SEVERE: The registered message body readers compatible with the MIME
> media type are:
> application/xml ->
> ....
>
> The list is pretty long so I'll leave it off. The example shows:
>
> @GET
> @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
> List<Book> getBooks();
>
> which is pretty much exactly what I have. So does the proxy client
> just not work with 1.x? If it should, how do I fix this?

This is most likely a bug in the proxy client. You actually seem to be
the first one to try it out and give feedback. Thank you very much for
that! Let me look into it - should be easy to fix.
Martin