users@jersey.java.net

Re: [Jersey] POST with content type "application/xml"

From: Marc Hadley <Marc.Hadley_at_Sun.COM>
Date: Mon, 02 Jun 2008 09:37:24 -0400

This area of the code has changed a lot recently and the stack trace
you sent doesn't really match up to the current code so its hard to
see what is going wrong without knowing the exact revision you are
using. If its not too much trouble would you be able to update Jersey
to the latest nightly build:

https://jersey.dev.java.net/servlets/ProjectDocumentList?folderID=7653&expandFolder=7653&folderID=0

and then retest your application. Assuming the error still occurs,
please resend the stack trace to the list.

Thanks,
Marc.

On Jun 1, 2008, at 4:26 PM, Ralf Edmund Stranzenbach wrote:

>
> Am 01.06.2008 um 03:26 schrieb Marc Hadley:
>
>> On May 31, 2008, at 8:34 AM, Ralf Edmund Stranzenbach wrote:
>>>
>>> 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 ?
>>>
>> Did you define the extension to media-type mappings in your
>> ApplicationConfig instance ?
>>
>>>
>>> 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();
>>> }
>>> ...
>>>
>> Hmm, it looks OK at first glance. What does the
>> de.reswi.jersey.domain.User class look like - is it a JAXB class ?
>
> Yes, is is a nonspectacular JAXB and Hibernate annotated class
> consisting of a Long identification property and some sample String
> type properties. This class works pretty well with all those GET
> type methods. That part of server and client application works like
> a charm.
>
>>> 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 ?
>>>
>> ---
>> Marc Hadley <marc.hadley at sun.com>
>> CTO Office, Sun Microsystems.
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
>> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>

---
Marc Hadley <marc.hadley at sun.com>
CTO Office, Sun Microsystems.