users@jersey.java.net

POST with content type "application/xml"

From: Ralf Edmund Stranzenbach <ralf_at_reswi.de>
Date: Sat, 31 May 2008 14:34:59 +0200

Hi,

i spent some time the past days experimenting with the Jersey
implementation of JSR-311. To get some figures for a comparism of
technologies and frameworks i tried to adopt a sample application
already prepared for Restlet.

This application consists of an (classical example) UsersResource
which also acts as a factory for new User instances. My example, now
based on Jersey release 0.7-ea, has two problems i failed to solve:


1) Content negotiation

As far as i can see, the content negotiation based on url extensions
(such as .de.xml) does not work.
Is there anything - like Restlets TunnelFilter - that needs to be
enabled to activate this feature ?


2) POST request method is *not* accepted by infrastructure

The following fragment is part of my UsersResource class.

@Path("/users")
public class UsersResource {
        ...
        @POST
        @ConsumeMime("application/xml")
        @ProduceMime("application/xml")
        public Response createUser(User user) {
                Session session = HibernateUtil.getSessionFactory().openSession();
                Transaction tx = session.beginTransaction();

                user.setId(null);
                session.save(user);
                tx.commit();
                session.close();
                return Response.ok(user).build();
        }
        ...

Enclosed you may find the exception message raised by the container:

31.05.2008 14:21:53 com.sun.jersey.api.core.ClasspathResourceConfig init
INFO: Root resource classes found:
   class de.reswi.jersey.resources.UsersResource
   class de.reswi.jersey.resources.HelloWorldResource
31.05.2008 14:21:53 com.sun.jersey.api.core.ClasspathResourceConfig init
INFO: Provider classes found:
31.05.2008 14:21:54
com.sun.jersey.impl.application.ResourceMethodDispatcherFactory
getDispatcher
SCHWERWIEGEND: Error processing method, public
javax.ws.rs.core.Response
de
.reswi
.jersey
.resources.UsersResource.createUser(de.reswi.jersey.domain.User), for
WebResourceInvoker,
com
.sun
.jersey
.impl
.model
.method.dispatch.FormDispatchProvider.java.lang.NullPointerException
        at
com
.sun
.jersey
.impl
.model
.method
.dispatch
.FormDispatchProvider.processParameters(FormDispatchProvider.java:178)
        at
com
.sun
.jersey
.impl
.model
.method.dispatch.FormDispatchProvider.create(FormDispatchProvider.java:
152)
        at
com
.sun
.jersey
.impl
.application
.ResourceMethodDispatcherFactory
.getDispatcher(ResourceMethodDispatcherFactory.java:60)
        at
com
.sun
.jersey
.impl.model.method.ResourceHttpMethod.<init>(ResourceHttpMethod.java:48)
        at
com
.sun
.jersey
.impl.model.method.ResourceHttpMethod.<init>(ResourceHttpMethod.java:41)
        at
com
.sun.jersey.impl.model.ResourceClass.processMethods(ResourceClass.java:
231)
        at com.sun.jersey.impl.model.ResourceClass.<init>(ResourceClass.java:
95)
        at
com
.sun
.jersey
.impl
.application
.WebApplicationImpl.newResourceClass(WebApplicationImpl.java:272)
        at
com
.sun
.jersey
.impl
.application
.WebApplicationImpl.getResourceClass(WebApplicationImpl.java:243)
        at
com
.sun
.jersey
.impl
.application
.WebApplicationImpl.processRootResources(WebApplicationImpl.java:675)
        at
com
.sun
.jersey
.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:
562)
        at
com
.sun
.jersey
.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:
433)
        at
com
.sun
.jersey
.spi.container.servlet.ServletContainer.initiate(ServletContainer.java:
385)
        at
com
.sun
.jersey
.spi.container.servlet.ServletContainer.load(ServletContainer.java:313)
        at
com
.sun
.jersey
.spi.container.servlet.ServletContainer.init(ServletContainer.java:121)

This exception was raised during the discovery phase of the resource
classes.
Based on my very limited understanding of JAX-RS im confident, this
resources basic configuration should be correct.

Is there anything i've missed ?



Regards
Ralf E. Stranzenbach