users@jersey.java.net

Re: [Jersey] Jersey client accessing Jesery REST server message writer issue

From: Paul Sandoz <Paul.Sandoz_at_oracle.com>
Date: Tue, 10 Aug 2010 11:40:30 +0200

Hi Kevin,

It looks like there might be a class loading issue. It indicates that
the Client instance cannot see the JAXB libs and therefore the JAXB
message body writers for the client are not being utilized. Can you
access JAXB directly from the application code in server 1 e.g. new
JAXBContext(Transaction.class);

When you say simple calls did you try a simple GET request such as:

   String s = webResource....get(String.class);

if that works it certainly indicates an issue with JAXB rather than a
fundamental issue with META-INF/services.

Anything else in the logs on initialization? If you set JDK logging to
CONFIG or above you may got some more clues.

Since Jersey is distributed with GF you might want to be careful if
you are also distributing a different version of Jersey in the WEB-INF/
lib, also GF ships with JAXB so you may not require it to be in the
WEB-INF/lib unless you need a specific version.

Paul.

On Aug 10, 2010, at 3:41 AM, Kevin Duffey wrote:

> Hey all,
>
> I am working on a project that uses two servers to communicate back
> and forth. The one server makes a REST call to the 2nd server. Both
> are my own code, both use Jersey and so forth. They both use the
> same .xsd and compiled JAXB classes. From server 1 I can reach
> server 2 no problem on simple calls. It's when I use the Jersey
> client code to pass a JAXB object to server 2 that I get the problem.
>
> Client client = Client.create();
> WebResource webResource =
> client.resource(getServerURL()).path("resources/transaction");
> Transaction response = webResource.header("Authorization",
> auth).accept("application/vnd.mycompany..transactions
> +xml").type("application/vnd.mycompany.transactions
> +xml").post(Transaction.class, t);
>
> Maybe I am doing this wrong? But when I execute this code I get the
>
> com.sun.jersey.api.client.ClientHandlerException: A message body
> writer for Java type...
>
> exception. I did some searching and see where Paul has replied to
> make sure all the JAXB libraries are in the class path. I definitely
> have all these in the WEB-INF/lib folder of my .war app that I
> deploy on both servers.
>
> So I am stumped as of now why this is telling me to have a message
> body writer. The Transaction class is a class generated from
> the .xsd.. and in fact on the server 1, I can make a REST call to it
> with xml in the format of the Transaction JAXB class, and it works.
> So I am not sure why it is telling me I need a separate writer.. it
> should have been part of the JAXB generated shouldn't it?
>
> I am using Jersey client 1.1.5 and GlassFish v3.
>
> Thanks in advance.
>
>