I have just tried a simple JAXB based resource
and it works fine for me (Jersey taken from trunk).
JAXB bean:
@XmlRootElement
public class MyBean {
public String name;
public Long value;
}
resource methods:
@GET @ProduceMime("application/xml")
@Path("bean")
public MyBean getBean() {
if (bean == null) {
MyBean newBean = new MyBean();
newBean.name = "Jan";
newBean.value = 12l;
bean = newBean;
}
return bean;
}
@POST @ConsumeMime("application/xml")
public void postBean(MyBean b) {
this.bean = b;
}
I am using curl to make the POST request:
curl -HContent-type:application/xml -X POST --data '<?xml version="1.0" encoding="UTF-8" standalone="yes"?><myBean><name>Jan</name><value>12</value></myBean>'
http://localhost:8080/...
and it works! the xml i got via curl -HAccept:application/xml
http://localhost:8080/.../bean
i am now curious, if you try to get *your* xml via curl,
and then pass it back via curl like described above, will it work?
if yes, what are you using on the client side (to make the POST request) ?
if no, could you please provide a small reproducible test case?
Thanks,
~Jakub
On Mon, Jun 02, 2008 at 09:37:24AM -0400, Marc Hadley wrote:
> 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.
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>