users@jersey.java.net

Re: [Jersey] Jersey Client question...

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Fri, 22 Aug 2008 09:23:05 +0200

Hi Kevin,

Is the MyJaxBGeneraredClass an JAXB element or JAXB type? are you
wrapping that around JAXBElement on the server side?

Can you send me the code of MyJaxBGeneraredClass. As i think you may
be hitting a limitation/bug in the client API. Notice that you can
only send the class you want an instance of in return, it is not
possible to do this:

   JAXBElement< MyJaxBGeneraredClass>.class

Grrr it is really hard to deal with generic types in Java.

Note that you do not have to set the Content-Type header, this is
because a GET is not sending anything so you can do:

     a = r..accept("application/xml").get(MyJaxBGeneratedClass.class);

And if you did need to send something you can use the "type" method
to set the content-type and you do not need to refer to the header
explicitly.

Paul.

On Aug 22, 2008, at 8:45 AM, Kevin Duffey wrote:

> Back again...
>
> So I am deploying a webapp that makes use of the Jersey Client to
> call another webapp (deployed in a different glassfish domain) that
> has the JAXB/Rest stuff that works. I am using the same "common"
> jaxb generated classes on both the server side and the "client"
> side webapp.
>
> My use of jersey client is as follows:
>
> Client client = Client.create();
> WebResource r = client.resource("http://localhost:8081/
> myapp/myresource");
>
> MyJaxBGeneratedClass a = null;
>
> try {
> a = r.header("Content-Type", "application/xml").accept
> ("application/xml").get(MyJaxBGeneratedClass.class);
> } catch (UniformInterfaceException uie) {
> uie.printStackTrace(System.out);
> }
>
>
> When I hit the page that calls that bit of code, it does make it
> across to the other domain REST server app. The response from that
> call does return XML as I tested it with the RestClient swing app,
> and it works fine. The error I am getting is:
>
> com.sun.jersey.api.client.ClientHandlerException: A message body
> reader for Java type, class com.company.MyJaxBGeneratedClass, and
> MIME media type, application/xml, was not found
>
> So, being that these are JAXB generated classes, and I thought I
> had read that the Jersey Client works much like the Jersey JAXB
> stuff I got working on the server side piece, what am I missing? Do
> I need to do some JAXB code to get the response back into the
> MyJaxBGeneratedClass so that I can use the object? I figured it
> would be as easy/nice as the server side, where I don't need to do
> any JAXB code at all, it's done via the Jersey engine.
>
> Can't seem to find any good info on how to do this with regards to
> Jersey client, JAXB generated classes that are "shared" between the
> client and the server jersey app the client makes use of.
>
> Thanks for any help.
>
>
>
>