users@jersey.java.net

Custom MessageBodyWriter ignored

From: Marco หงุ่ยตระกูล-Schulze <Marco_at_NightLabs.de>
Date: Tue, 04 May 2010 16:01:37 +0200
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 :-)