users@jersey.java.net

Re: [Jersey] Custom MessageBodyWriter ignored

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Tue, 04 May 2010 17:32:10 +0200

Hi Marco,

Is there any output in the server log?

I think it is a dependency issue and the MBW/R cannot be instantiated
due to a missing slf4j dependency. Depending on the instantiation
exception when constructing Jersey logs such errors at the level of
CONFIG and not SEVERE. It uses the former when there is a direct
missing dependency, that if missing at compile time would result in a
compilation failure.

But for slf4j the same behavior is induced if slf4f cannot bind to a
logging implementation :-(

Currently Jersey does not differentiate between system and application
components when instantiating, and it should such that deployment will
fail in the latter case.

Note that GF does not ship with slf4j.

See attached for a maven project that works with your code.

Paul.



On May 4, 2010, at 4:01 PM, Marco หงุ่ยตระกูล-
Schulze wrote:

> Hello *,
>
> I'm porting a small evaluation project (which works fine with
> RESTeasy on JBoss) to Jersey on GlassFish v3.
>
> I can access the URL http://localhost:8080/TestRest/resources/room/2
> without any problem when tagging the method
> org.nightlabs.testrest.RoomService#getRoom(String) with
> @Produces("application/xml").
>
> Even though, I have a custom MessageBodyWriter declared via a
> javax.ws.rs.core.Application subclass, when tagging my RoomService
> method with @Produces("application/x-nightlabs-jfire-xstream"),
> Jersey claims that there is no writer:
>
>> SEVERE: A message body writer for Java type, class
>> org.nightlabs.testrest.Room, and MIME media type, application/x-
>> nightlabs-jfire-xstream, was not found
>> SEVERE: Mapped exception to response: 500 (Internal Server Error)
>
> Here's my little project: http://www.nightlabs.de/~marco/jersey/2010-05-04.00/TestRest.tar.gz
>
> My javax.ws.rs.core.Application subclass is instantiated and the
> method getClasses() is called (I debugged through it), but even
> though this method returns XStreamMessageBodyWriter.class (among
> others), my custom writer is ignored.
>
> Can anyone give me a hint? What am I doing wrong? Is this a bug in
> Jersey? Did I miss any configuration setting in my web.xml? Here's
> an excerpt of my web.xml (see the TestRest.tar.gz for all details):
>
>> <servlet>
>> <servlet-name>TestRestJerseyServlet</servlet-name>
>> <servlet-
>> class>com.sun.jersey.server.impl.container.servlet.ServletAdaptor</
>> servlet-class>
>> <init-param>
>> <param-name>com.sun.jersey.config.feature.Redirect</param-
>> name>
>> <param-value>true</param-value>
>> </init-param>
>> <init-param>
>> <param-name>javax.ws.rs.Application</param-name>
>> <param-value>org.nightlabs.testrest.TestRestApplication</
>> param-value>
>> </init-param>
>> <load-on-startup>1</load-on-startup>
>> </servlet>
>> <servlet-mapping>
>> <servlet-name>TestRestJerseyServlet</servlet-name>
>> <url-pattern>/resources/*</url-pattern>
>> </servlet-mapping>
>
> Best regards, Marco :-)
>
> --------------------------------------------------------------------- To
> unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net For
> additional commands, e-mail: users-help_at_jersey.dev.java.net