You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Josh Holtzman <jh...@berkeley.edu> on 2010/10/06 10:10:34 UTC
JAX-RS and Collections of JAXB objects (was: Help required with
apache cxf multiparts)
When I do this:
@GET
@Path("/jobs.xml")
@Produces(MediaType.APPLICATION_XML)
public Response getJobs() {
return Response.ok(getJobsImpls()).build();
}
@XmlType(name = "job", namespace = "http://remote.opencastproject.org/")
@XmlRootElement(name = "job", namespace = "
http://remote.opencastproject.org/")
public class JobImpl implements Job {
...
}
I get a 500 response with this in the body "No message body writer has been
found for response class Vector." I thought maybe the problem was that this
Vector is the one being returned by eclipselink, and there was some kind of
proxy voodoo interfering. If I copy all of the JobImpls into a new
ArrayList, I get the same kind of message, "No message body writer has been
found for response class ArrayList."
I'm building the JAX-RS endpoint manually using cxf-bundle-jaxrs-2.2.9.jar
and a CXFNonSpringServlet with some custom providers. Perhaps I'm missing
one of the providers needed to handle Collections?
And I'm curious, what would the xml look like for this collection? Where
does the root element name come from? And the namespace... is it copied
from the objects in the collection?
Thanks,
Josh
On Tue, Oct 5, 2010 at 11:20 PM, Sergey Beryozkin <sb...@gmail.com>wrote:
> Hi Josh
>
> thanks for this tip, but my question is to do with you referring to
> collections of JAXB beans not being supported.
> I'd appreciate if you could send me an example of such a collection.
> Explicit collection have been supported for a while and I recall users
> confirming that it worked for them, so if there's some issue there lurking
> then I'd like to get it fixed :-)
>
> thanks, Sergey
>
> On Tue, Oct 5, 2010 at 7:24 PM, Josh Holtzman <jholtzman@berkeley.edu
> >wrote:
>
> > This part of the stack trace:
> >
> > Caused by: javax.ws.rs.WebApplicationException at
> >
> >
> org.apache.cxf.jaxrs.client.AbstractClient.reportNoMessageHandler(AbstractClient.java:487)
> >
> > looks like there's no message body writer. I've run into this kind of
> > problem when trying to return Collections, even collections of JAXB
> > elements, from JAX-RS endpoints. I usually solve it by wrapping the list
> > in
> > a root class, and passing the wrapper rather than the Collection, like
> > this:
> >
> > @XmlRootElement(name="deviceList")
> > public class DeviceList {
> > @XmlElement
> > protected List<Device> devices;
> > }
> >
> > Perhaps this might help in your case too, switching from
> > addDevice(List<Device> device) to addDevice(DeviceList deviceList).
> >
> > Josh
> >
> > On Tue, Oct 5, 2010 at 8:00 PM, oceanz <oc...@yahoo.com> wrote:
> >
> > >
> > > I changed it to:
> > > @Path("user/site/plant/device/addDevice1")
> > > @POST
> > > @Produces("text/xml")
> > > @Consumes("multipart/form-data;type=text/xml")
> > > Device addDevice(List<Device> device);
> > >
> > > But it still doesn't work.
> > > Same exception:Caused by: javax.ws.rs.WebApplicationException
> > > at
> > >
> > >
> >
> org.apache.cxf.jaxrs.client.AbstractClient.reportNoMessageHandler(AbstractClient.java:487)
> > > at
> > >
> > >
> >
> org.apache.cxf.jaxrs.client.AbstractClient.writeBody(AbstractClient.java:401)
> > > at
> > >
> > >
> >
> org.apache.cxf.jaxrs.client.ClientProxyImpl$BodyWriter.handleMessage(ClientProxyImpl.java:514)
> > > ... 5 more
> > >
> > > Device is a JAXB Bean.:
> > > @Entity(name="device")
> > > @XmlRootElement(name="device")
> > > @XmlAccessorType(XmlAccessType.FIELD)
> > > public class Device extends DomainEntity {
> > >
> > > /**
> > > *
> > > */
> > > private static final long serialVersionUID = 1L;
> > >
> > > public Device() {}
> > >
> > >
> > > @XmlAttribute(name="deviceName")
> > > private String deviceName;
> > >
> > > @XmlAttribute(name="deviceType")
> > > private String deviceType;
> > >
> > > @XmlAttribute(name="modelNumber")
> > > private String modelNumber;
> > >
> > > @XmlAttribute(name="serialNumber")
> > > private String serialNumber;
> > > ..........
> > > }
> > >
> > > Who do I need to do next? Desparate to get this working.
> > > Thanks for all your help.
> > > --
> > > View this message in context:
> > >
> >
> http://cxf.547215.n5.nabble.com/Help-required-with-apache-cxf-multiparts-tp3199975p3200103.html
> > > Sent from the cxf-user mailing list archive at Nabble.com.
> > >
> >
>
Re: JAX-RS and Collections of JAXB objects (was: Help required with
apache cxf multiparts)
Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi Josh, this is nice - I honestly was not sure if it will work or not :-)
By the way, 500 is correct for a missing writer, according to [1]
cheers, Sergey
[1]
https://jsr311.dev.java.net/nonav/releases/1.1/spec/spec3.html#x3-440004.2.2
On Wed, Oct 6, 2010 at 10:21 AM, Josh Holtzman <jh...@berkeley.edu>wrote:
> Thank you for the hint! Returning a GenericEntity wrapped collection also
> works, as you suggested.
>
> @GET
> @Path("/jobs.xml")
> @Produces(MediaType.APPLICATION_XML)
> public Response getJobs() {
> GenericEntity<List<JobImpl>> entity = new
> GenericEntity<List<JobImpl>>(getJobs()) {};
> return Response.ok(entity).build();
> }
>
> Thanks,
> Josh
>
> On Wed, Oct 6, 2010 at 10:48 AM, Sergey Beryozkin <sberyozkin@gmail.com
> >wrote:
>
> > Cool, thanks for the confirmation...
> >
> > cheers, Sergey
> >
> >
> > On 10/6/10, Josh Holtzman <jh...@berkeley.edu> wrote:
> > >
> > > It looks like the problem is in returning a Response with the
> Collection
> > > set
> > > as the entity, as described below. Changing the return type to
> > > List<JobImpl> works as expected.
> > >
> > > Thanks,
> > > Josh
> > >
> > > On Wed, Oct 6, 2010 at 10:10 AM, Josh Holtzman <jholtzman@berkeley.edu
> > > >wrote:
> > >
> > > > When I do this:
> > > >
> > > > @GET
> > > > @Path("/jobs.xml")
> > > > @Produces(MediaType.APPLICATION_XML)
> > > > public Response getJobs() {
> > > > return Response.ok(getJobsImpls()).build();
> > > > }
> > > >
> > > > @XmlType(name = "job", namespace = "
> http://remote.opencastproject.org/
> > ")
> > > > @XmlRootElement(name = "job", namespace = "
> > > > http://remote.opencastproject.org/")
> > > > public class JobImpl implements Job {
> > > > ...
> > > > }
> > > >
> > > >
> > > > I get a 500 response with this in the body "No message body writer
> has
> > > been
> > > > found for response class Vector." I thought maybe the problem was
> that
> > > this
> > > > Vector is the one being returned by eclipselink, and there was some
> > kind
> > > of
> > > > proxy voodoo interfering. If I copy all of the JobImpls into a new
> > > > ArrayList, I get the same kind of message, "No message body writer
> has
> > > been
> > > > found for response class ArrayList."
> > > >
> > > > I'm building the JAX-RS endpoint manually using
> > > cxf-bundle-jaxrs-2.2.9.jar
> > > > and a CXFNonSpringServlet with some custom providers. Perhaps I'm
> > > missing
> > > > one of the providers needed to handle Collections?
> > > >
> > > > And I'm curious, what would the xml look like for this collection?
> > Where
> > > > does the root element name come from? And the namespace... is it
> > copied
> > > > from the objects in the collection?
> > > >
> > > > Thanks,
> > > > Josh
> > > >
> > > > On Tue, Oct 5, 2010 at 11:20 PM, Sergey Beryozkin <
> > sberyozkin@gmail.com
> > > >wrote:
> > > >
> > > >> Hi Josh
> > > >>
> > > >> thanks for this tip, but my question is to do with you referring to
> > > >> collections of JAXB beans not being supported.
> > > >> I'd appreciate if you could send me an example of such a collection.
> > > >> Explicit collection have been supported for a while and I recall
> users
> > > >> confirming that it worked for them, so if there's some issue there
> > > lurking
> > > >> then I'd like to get it fixed :-)
> > > >>
> > > >> thanks, Sergey
> > > >>
> > > >> On Tue, Oct 5, 2010 at 7:24 PM, Josh Holtzman <
> jholtzman@berkeley.edu
> > > >> >wrote:
> > > >>
> > > >> > This part of the stack trace:
> > > >> >
> > > >> > Caused by: javax.ws.rs.WebApplicationException at
> > > >> >
> > > >> >
> > > >>
> > >
> >
> org.apache.cxf.jaxrs.client.AbstractClient.reportNoMessageHandler(AbstractClient.java:487)
> > > >> >
> > > >> > looks like there's no message body writer. I've run into this
> kind
> > of
> > > >> > problem when trying to return Collections, even collections of
> JAXB
> > > >> > elements, from JAX-RS endpoints. I usually solve it by wrapping
> the
> > > >> list
> > > >> > in
> > > >> > a root class, and passing the wrapper rather than the Collection,
> > like
> > > >> > this:
> > > >> >
> > > >> > @XmlRootElement(name="deviceList")
> > > >> > public class DeviceList {
> > > >> > @XmlElement
> > > >> > protected List<Device> devices;
> > > >> > }
> > > >> >
> > > >> > Perhaps this might help in your case too, switching from
> > > >> > addDevice(List<Device> device) to addDevice(DeviceList
> deviceList).
> > > >> >
> > > >> > Josh
> > > >> >
> > > >> > On Tue, Oct 5, 2010 at 8:00 PM, oceanz <oc...@yahoo.com>
> > > wrote:
> > > >> >
> > > >> > >
> > > >> > > I changed it to:
> > > >> > > @Path("user/site/plant/device/addDevice1")
> > > >> > > @POST
> > > >> > > @Produces("text/xml")
> > > >> > > @Consumes("multipart/form-data;type=text/xml")
> > > >> > > Device addDevice(List<Device> device);
> > > >> > >
> > > >> > > But it still doesn't work.
> > > >> > > Same exception:Caused by: javax.ws.rs.WebApplicationException
> > > >> > > at
> > > >> > >
> > > >> > >
> > > >> >
> > > >>
> > >
> >
> org.apache.cxf.jaxrs.client.AbstractClient.reportNoMessageHandler(AbstractClient.java:487)
> > > >> > > at
> > > >> > >
> > > >> > >
> > > >> >
> > > >>
> > >
> >
> org.apache.cxf.jaxrs.client.AbstractClient.writeBody(AbstractClient.java:401)
> > > >> > > at
> > > >> > >
> > > >> > >
> > > >> >
> > > >>
> > >
> >
> org.apache.cxf.jaxrs.client.ClientProxyImpl$BodyWriter.handleMessage(ClientProxyImpl.java:514)
> > > >> > > ... 5 more
> > > >> > >
> > > >> > > Device is a JAXB Bean.:
> > > >> > > @Entity(name="device")
> > > >> > > @XmlRootElement(name="device")
> > > >> > > @XmlAccessorType(XmlAccessType.FIELD)
> > > >> > > public class Device extends DomainEntity {
> > > >> > >
> > > >> > > /**
> > > >> > > *
> > > >> > > */
> > > >> > > private static final long serialVersionUID = 1L;
> > > >> > >
> > > >> > > public Device() {}
> > > >> > >
> > > >> > >
> > > >> > > @XmlAttribute(name="deviceName")
> > > >> > > private String deviceName;
> > > >> > >
> > > >> > > @XmlAttribute(name="deviceType")
> > > >> > > private String deviceType;
> > > >> > >
> > > >> > > @XmlAttribute(name="modelNumber")
> > > >> > > private String modelNumber;
> > > >> > >
> > > >> > > @XmlAttribute(name="serialNumber")
> > > >> > > private String serialNumber;
> > > >> > > ..........
> > > >> > > }
> > > >> > >
> > > >> > > Who do I need to do next? Desparate to get this working.
> > > >> > > Thanks for all your help.
> > > >> > > --
> > > >> > > View this message in context:
> > > >> > >
> > > >> >
> > > >>
> > >
> >
> http://cxf.547215.n5.nabble.com/Help-required-with-apache-cxf-multiparts-tp3199975p3200103.html
> > > >> > > Sent from the cxf-user mailing list archive at Nabble.com.
> > > >> > >
> > > >> >
> > > >>
> > > >
> > > >
> > >
> >
>
Re: JAX-RS and Collections of JAXB objects (was: Help required with
apache cxf multiparts)
Posted by Josh Holtzman <jh...@berkeley.edu>.
Thank you for the hint! Returning a GenericEntity wrapped collection also
works, as you suggested.
@GET
@Path("/jobs.xml")
@Produces(MediaType.APPLICATION_XML)
public Response getJobs() {
GenericEntity<List<JobImpl>> entity = new
GenericEntity<List<JobImpl>>(getJobs()) {};
return Response.ok(entity).build();
}
Thanks,
Josh
On Wed, Oct 6, 2010 at 10:48 AM, Sergey Beryozkin <sb...@gmail.com>wrote:
> Cool, thanks for the confirmation...
>
> cheers, Sergey
>
>
> On 10/6/10, Josh Holtzman <jh...@berkeley.edu> wrote:
> >
> > It looks like the problem is in returning a Response with the Collection
> > set
> > as the entity, as described below. Changing the return type to
> > List<JobImpl> works as expected.
> >
> > Thanks,
> > Josh
> >
> > On Wed, Oct 6, 2010 at 10:10 AM, Josh Holtzman <jholtzman@berkeley.edu
> > >wrote:
> >
> > > When I do this:
> > >
> > > @GET
> > > @Path("/jobs.xml")
> > > @Produces(MediaType.APPLICATION_XML)
> > > public Response getJobs() {
> > > return Response.ok(getJobsImpls()).build();
> > > }
> > >
> > > @XmlType(name = "job", namespace = "http://remote.opencastproject.org/
> ")
> > > @XmlRootElement(name = "job", namespace = "
> > > http://remote.opencastproject.org/")
> > > public class JobImpl implements Job {
> > > ...
> > > }
> > >
> > >
> > > I get a 500 response with this in the body "No message body writer has
> > been
> > > found for response class Vector." I thought maybe the problem was that
> > this
> > > Vector is the one being returned by eclipselink, and there was some
> kind
> > of
> > > proxy voodoo interfering. If I copy all of the JobImpls into a new
> > > ArrayList, I get the same kind of message, "No message body writer has
> > been
> > > found for response class ArrayList."
> > >
> > > I'm building the JAX-RS endpoint manually using
> > cxf-bundle-jaxrs-2.2.9.jar
> > > and a CXFNonSpringServlet with some custom providers. Perhaps I'm
> > missing
> > > one of the providers needed to handle Collections?
> > >
> > > And I'm curious, what would the xml look like for this collection?
> Where
> > > does the root element name come from? And the namespace... is it
> copied
> > > from the objects in the collection?
> > >
> > > Thanks,
> > > Josh
> > >
> > > On Tue, Oct 5, 2010 at 11:20 PM, Sergey Beryozkin <
> sberyozkin@gmail.com
> > >wrote:
> > >
> > >> Hi Josh
> > >>
> > >> thanks for this tip, but my question is to do with you referring to
> > >> collections of JAXB beans not being supported.
> > >> I'd appreciate if you could send me an example of such a collection.
> > >> Explicit collection have been supported for a while and I recall users
> > >> confirming that it worked for them, so if there's some issue there
> > lurking
> > >> then I'd like to get it fixed :-)
> > >>
> > >> thanks, Sergey
> > >>
> > >> On Tue, Oct 5, 2010 at 7:24 PM, Josh Holtzman <jholtzman@berkeley.edu
> > >> >wrote:
> > >>
> > >> > This part of the stack trace:
> > >> >
> > >> > Caused by: javax.ws.rs.WebApplicationException at
> > >> >
> > >> >
> > >>
> >
> org.apache.cxf.jaxrs.client.AbstractClient.reportNoMessageHandler(AbstractClient.java:487)
> > >> >
> > >> > looks like there's no message body writer. I've run into this kind
> of
> > >> > problem when trying to return Collections, even collections of JAXB
> > >> > elements, from JAX-RS endpoints. I usually solve it by wrapping the
> > >> list
> > >> > in
> > >> > a root class, and passing the wrapper rather than the Collection,
> like
> > >> > this:
> > >> >
> > >> > @XmlRootElement(name="deviceList")
> > >> > public class DeviceList {
> > >> > @XmlElement
> > >> > protected List<Device> devices;
> > >> > }
> > >> >
> > >> > Perhaps this might help in your case too, switching from
> > >> > addDevice(List<Device> device) to addDevice(DeviceList deviceList).
> > >> >
> > >> > Josh
> > >> >
> > >> > On Tue, Oct 5, 2010 at 8:00 PM, oceanz <oc...@yahoo.com>
> > wrote:
> > >> >
> > >> > >
> > >> > > I changed it to:
> > >> > > @Path("user/site/plant/device/addDevice1")
> > >> > > @POST
> > >> > > @Produces("text/xml")
> > >> > > @Consumes("multipart/form-data;type=text/xml")
> > >> > > Device addDevice(List<Device> device);
> > >> > >
> > >> > > But it still doesn't work.
> > >> > > Same exception:Caused by: javax.ws.rs.WebApplicationException
> > >> > > at
> > >> > >
> > >> > >
> > >> >
> > >>
> >
> org.apache.cxf.jaxrs.client.AbstractClient.reportNoMessageHandler(AbstractClient.java:487)
> > >> > > at
> > >> > >
> > >> > >
> > >> >
> > >>
> >
> org.apache.cxf.jaxrs.client.AbstractClient.writeBody(AbstractClient.java:401)
> > >> > > at
> > >> > >
> > >> > >
> > >> >
> > >>
> >
> org.apache.cxf.jaxrs.client.ClientProxyImpl$BodyWriter.handleMessage(ClientProxyImpl.java:514)
> > >> > > ... 5 more
> > >> > >
> > >> > > Device is a JAXB Bean.:
> > >> > > @Entity(name="device")
> > >> > > @XmlRootElement(name="device")
> > >> > > @XmlAccessorType(XmlAccessType.FIELD)
> > >> > > public class Device extends DomainEntity {
> > >> > >
> > >> > > /**
> > >> > > *
> > >> > > */
> > >> > > private static final long serialVersionUID = 1L;
> > >> > >
> > >> > > public Device() {}
> > >> > >
> > >> > >
> > >> > > @XmlAttribute(name="deviceName")
> > >> > > private String deviceName;
> > >> > >
> > >> > > @XmlAttribute(name="deviceType")
> > >> > > private String deviceType;
> > >> > >
> > >> > > @XmlAttribute(name="modelNumber")
> > >> > > private String modelNumber;
> > >> > >
> > >> > > @XmlAttribute(name="serialNumber")
> > >> > > private String serialNumber;
> > >> > > ..........
> > >> > > }
> > >> > >
> > >> > > Who do I need to do next? Desparate to get this working.
> > >> > > Thanks for all your help.
> > >> > > --
> > >> > > View this message in context:
> > >> > >
> > >> >
> > >>
> >
> http://cxf.547215.n5.nabble.com/Help-required-with-apache-cxf-multiparts-tp3199975p3200103.html
> > >> > > Sent from the cxf-user mailing list archive at Nabble.com.
> > >> > >
> > >> >
> > >>
> > >
> > >
> >
>
Re: JAX-RS and Collections of JAXB objects (was: Help required with
apache cxf multiparts)
Posted by Sergey Beryozkin <sb...@gmail.com>.
Cool, thanks for the confirmation...
cheers, Sergey
On 10/6/10, Josh Holtzman <jh...@berkeley.edu> wrote:
>
> It looks like the problem is in returning a Response with the Collection
> set
> as the entity, as described below. Changing the return type to
> List<JobImpl> works as expected.
>
> Thanks,
> Josh
>
> On Wed, Oct 6, 2010 at 10:10 AM, Josh Holtzman <jholtzman@berkeley.edu
> >wrote:
>
> > When I do this:
> >
> > @GET
> > @Path("/jobs.xml")
> > @Produces(MediaType.APPLICATION_XML)
> > public Response getJobs() {
> > return Response.ok(getJobsImpls()).build();
> > }
> >
> > @XmlType(name = "job", namespace = "http://remote.opencastproject.org/")
> > @XmlRootElement(name = "job", namespace = "
> > http://remote.opencastproject.org/")
> > public class JobImpl implements Job {
> > ...
> > }
> >
> >
> > I get a 500 response with this in the body "No message body writer has
> been
> > found for response class Vector." I thought maybe the problem was that
> this
> > Vector is the one being returned by eclipselink, and there was some kind
> of
> > proxy voodoo interfering. If I copy all of the JobImpls into a new
> > ArrayList, I get the same kind of message, "No message body writer has
> been
> > found for response class ArrayList."
> >
> > I'm building the JAX-RS endpoint manually using
> cxf-bundle-jaxrs-2.2.9.jar
> > and a CXFNonSpringServlet with some custom providers. Perhaps I'm
> missing
> > one of the providers needed to handle Collections?
> >
> > And I'm curious, what would the xml look like for this collection? Where
> > does the root element name come from? And the namespace... is it copied
> > from the objects in the collection?
> >
> > Thanks,
> > Josh
> >
> > On Tue, Oct 5, 2010 at 11:20 PM, Sergey Beryozkin <sberyozkin@gmail.com
> >wrote:
> >
> >> Hi Josh
> >>
> >> thanks for this tip, but my question is to do with you referring to
> >> collections of JAXB beans not being supported.
> >> I'd appreciate if you could send me an example of such a collection.
> >> Explicit collection have been supported for a while and I recall users
> >> confirming that it worked for them, so if there's some issue there
> lurking
> >> then I'd like to get it fixed :-)
> >>
> >> thanks, Sergey
> >>
> >> On Tue, Oct 5, 2010 at 7:24 PM, Josh Holtzman <jholtzman@berkeley.edu
> >> >wrote:
> >>
> >> > This part of the stack trace:
> >> >
> >> > Caused by: javax.ws.rs.WebApplicationException at
> >> >
> >> >
> >>
> org.apache.cxf.jaxrs.client.AbstractClient.reportNoMessageHandler(AbstractClient.java:487)
> >> >
> >> > looks like there's no message body writer. I've run into this kind of
> >> > problem when trying to return Collections, even collections of JAXB
> >> > elements, from JAX-RS endpoints. I usually solve it by wrapping the
> >> list
> >> > in
> >> > a root class, and passing the wrapper rather than the Collection, like
> >> > this:
> >> >
> >> > @XmlRootElement(name="deviceList")
> >> > public class DeviceList {
> >> > @XmlElement
> >> > protected List<Device> devices;
> >> > }
> >> >
> >> > Perhaps this might help in your case too, switching from
> >> > addDevice(List<Device> device) to addDevice(DeviceList deviceList).
> >> >
> >> > Josh
> >> >
> >> > On Tue, Oct 5, 2010 at 8:00 PM, oceanz <oc...@yahoo.com>
> wrote:
> >> >
> >> > >
> >> > > I changed it to:
> >> > > @Path("user/site/plant/device/addDevice1")
> >> > > @POST
> >> > > @Produces("text/xml")
> >> > > @Consumes("multipart/form-data;type=text/xml")
> >> > > Device addDevice(List<Device> device);
> >> > >
> >> > > But it still doesn't work.
> >> > > Same exception:Caused by: javax.ws.rs.WebApplicationException
> >> > > at
> >> > >
> >> > >
> >> >
> >>
> org.apache.cxf.jaxrs.client.AbstractClient.reportNoMessageHandler(AbstractClient.java:487)
> >> > > at
> >> > >
> >> > >
> >> >
> >>
> org.apache.cxf.jaxrs.client.AbstractClient.writeBody(AbstractClient.java:401)
> >> > > at
> >> > >
> >> > >
> >> >
> >>
> org.apache.cxf.jaxrs.client.ClientProxyImpl$BodyWriter.handleMessage(ClientProxyImpl.java:514)
> >> > > ... 5 more
> >> > >
> >> > > Device is a JAXB Bean.:
> >> > > @Entity(name="device")
> >> > > @XmlRootElement(name="device")
> >> > > @XmlAccessorType(XmlAccessType.FIELD)
> >> > > public class Device extends DomainEntity {
> >> > >
> >> > > /**
> >> > > *
> >> > > */
> >> > > private static final long serialVersionUID = 1L;
> >> > >
> >> > > public Device() {}
> >> > >
> >> > >
> >> > > @XmlAttribute(name="deviceName")
> >> > > private String deviceName;
> >> > >
> >> > > @XmlAttribute(name="deviceType")
> >> > > private String deviceType;
> >> > >
> >> > > @XmlAttribute(name="modelNumber")
> >> > > private String modelNumber;
> >> > >
> >> > > @XmlAttribute(name="serialNumber")
> >> > > private String serialNumber;
> >> > > ..........
> >> > > }
> >> > >
> >> > > Who do I need to do next? Desparate to get this working.
> >> > > Thanks for all your help.
> >> > > --
> >> > > View this message in context:
> >> > >
> >> >
> >>
> http://cxf.547215.n5.nabble.com/Help-required-with-apache-cxf-multiparts-tp3199975p3200103.html
> >> > > Sent from the cxf-user mailing list archive at Nabble.com.
> >> > >
> >> >
> >>
> >
> >
>
Re: JAX-RS and Collections of JAXB objects (was: Help required with
apache cxf multiparts)
Posted by Josh Holtzman <jh...@berkeley.edu>.
It looks like the problem is in returning a Response with the Collection set
as the entity, as described below. Changing the return type to
List<JobImpl> works as expected.
Thanks,
Josh
On Wed, Oct 6, 2010 at 10:10 AM, Josh Holtzman <jh...@berkeley.edu>wrote:
> When I do this:
>
> @GET
> @Path("/jobs.xml")
> @Produces(MediaType.APPLICATION_XML)
> public Response getJobs() {
> return Response.ok(getJobsImpls()).build();
> }
>
> @XmlType(name = "job", namespace = "http://remote.opencastproject.org/")
> @XmlRootElement(name = "job", namespace = "
> http://remote.opencastproject.org/")
> public class JobImpl implements Job {
> ...
> }
>
>
> I get a 500 response with this in the body "No message body writer has been
> found for response class Vector." I thought maybe the problem was that this
> Vector is the one being returned by eclipselink, and there was some kind of
> proxy voodoo interfering. If I copy all of the JobImpls into a new
> ArrayList, I get the same kind of message, "No message body writer has been
> found for response class ArrayList."
>
> I'm building the JAX-RS endpoint manually using cxf-bundle-jaxrs-2.2.9.jar
> and a CXFNonSpringServlet with some custom providers. Perhaps I'm missing
> one of the providers needed to handle Collections?
>
> And I'm curious, what would the xml look like for this collection? Where
> does the root element name come from? And the namespace... is it copied
> from the objects in the collection?
>
> Thanks,
> Josh
>
> On Tue, Oct 5, 2010 at 11:20 PM, Sergey Beryozkin <sb...@gmail.com>wrote:
>
>> Hi Josh
>>
>> thanks for this tip, but my question is to do with you referring to
>> collections of JAXB beans not being supported.
>> I'd appreciate if you could send me an example of such a collection.
>> Explicit collection have been supported for a while and I recall users
>> confirming that it worked for them, so if there's some issue there lurking
>> then I'd like to get it fixed :-)
>>
>> thanks, Sergey
>>
>> On Tue, Oct 5, 2010 at 7:24 PM, Josh Holtzman <jholtzman@berkeley.edu
>> >wrote:
>>
>> > This part of the stack trace:
>> >
>> > Caused by: javax.ws.rs.WebApplicationException at
>> >
>> >
>> org.apache.cxf.jaxrs.client.AbstractClient.reportNoMessageHandler(AbstractClient.java:487)
>> >
>> > looks like there's no message body writer. I've run into this kind of
>> > problem when trying to return Collections, even collections of JAXB
>> > elements, from JAX-RS endpoints. I usually solve it by wrapping the
>> list
>> > in
>> > a root class, and passing the wrapper rather than the Collection, like
>> > this:
>> >
>> > @XmlRootElement(name="deviceList")
>> > public class DeviceList {
>> > @XmlElement
>> > protected List<Device> devices;
>> > }
>> >
>> > Perhaps this might help in your case too, switching from
>> > addDevice(List<Device> device) to addDevice(DeviceList deviceList).
>> >
>> > Josh
>> >
>> > On Tue, Oct 5, 2010 at 8:00 PM, oceanz <oc...@yahoo.com> wrote:
>> >
>> > >
>> > > I changed it to:
>> > > @Path("user/site/plant/device/addDevice1")
>> > > @POST
>> > > @Produces("text/xml")
>> > > @Consumes("multipart/form-data;type=text/xml")
>> > > Device addDevice(List<Device> device);
>> > >
>> > > But it still doesn't work.
>> > > Same exception:Caused by: javax.ws.rs.WebApplicationException
>> > > at
>> > >
>> > >
>> >
>> org.apache.cxf.jaxrs.client.AbstractClient.reportNoMessageHandler(AbstractClient.java:487)
>> > > at
>> > >
>> > >
>> >
>> org.apache.cxf.jaxrs.client.AbstractClient.writeBody(AbstractClient.java:401)
>> > > at
>> > >
>> > >
>> >
>> org.apache.cxf.jaxrs.client.ClientProxyImpl$BodyWriter.handleMessage(ClientProxyImpl.java:514)
>> > > ... 5 more
>> > >
>> > > Device is a JAXB Bean.:
>> > > @Entity(name="device")
>> > > @XmlRootElement(name="device")
>> > > @XmlAccessorType(XmlAccessType.FIELD)
>> > > public class Device extends DomainEntity {
>> > >
>> > > /**
>> > > *
>> > > */
>> > > private static final long serialVersionUID = 1L;
>> > >
>> > > public Device() {}
>> > >
>> > >
>> > > @XmlAttribute(name="deviceName")
>> > > private String deviceName;
>> > >
>> > > @XmlAttribute(name="deviceType")
>> > > private String deviceType;
>> > >
>> > > @XmlAttribute(name="modelNumber")
>> > > private String modelNumber;
>> > >
>> > > @XmlAttribute(name="serialNumber")
>> > > private String serialNumber;
>> > > ..........
>> > > }
>> > >
>> > > Who do I need to do next? Desparate to get this working.
>> > > Thanks for all your help.
>> > > --
>> > > View this message in context:
>> > >
>> >
>> http://cxf.547215.n5.nabble.com/Help-required-with-apache-cxf-multiparts-tp3199975p3200103.html
>> > > Sent from the cxf-user mailing list archive at Nabble.com.
>> > >
>> >
>>
>
>
Re: JAX-RS and Collections of JAXB objects (was: Help required with
apache cxf multiparts)
Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi Josh
thanks for this example.
500 is definitely wrong - but I suspect it is due to the fact the check for
the available writer is done late due to the actual entity being wrapped in
Response - I'll verify later on.
All the tests use explicit collections in return types, ex. List<Job> - so
I'll have to check what is happening in case of them being wrapped in
Response - I think in this case, given that Response.getEntity() is just an
Object - a type information is not visible to the JAXB provider.
Try to wrap getJobsImpls() into JAXRS GenericEntity and set it as Response
entity if you do prefer to return Response. It might work.
Personally I'd prefer to create a wrapper as it is more likely to be
represented better in WADL, etc.
Please check a section on Collections in the CXF JAXRS wiki page, by default
the name of the collection memebr such as Job + 's' will be used, but it is
possible to customize - in which case you'd need to register such a
configured JAXBElementProvider as an OSGI service.
thanks, Sergey
On 10/6/10, Josh Holtzman <jh...@berkeley.edu> wrote:
>
> When I do this:
>
> @GET
> @Path("/jobs.xml")
> @Produces(MediaType.APPLICATION_XML)
> public Response getJobs() {
> return Response.ok(getJobsImpls()).build();
> }
>
> @XmlType(name = "job", namespace = "http://remote.opencastproject.org/")
> @XmlRootElement(name = "job", namespace = "
> http://remote.opencastproject.org/")
> public class JobImpl implements Job {
> ...
> }
>
>
> I get a 500 response with this in the body "No message body writer has been
> found for response class Vector." I thought maybe the problem was that
> this
> Vector is the one being returned by eclipselink, and there was some kind of
> proxy voodoo interfering. If I copy all of the JobImpls into a new
> ArrayList, I get the same kind of message, "No message body writer has been
> found for response class ArrayList."
>
> I'm building the JAX-RS endpoint manually using cxf-bundle-jaxrs-2.2.9.jar
> and a CXFNonSpringServlet with some custom providers. Perhaps I'm missing
> one of the providers needed to handle Collections?
>
> And I'm curious, what would the xml look like for this collection? Where
> does the root element name come from? And the namespace... is it copied
> from the objects in the collection?
>
> Thanks,
> Josh
>
> On Tue, Oct 5, 2010 at 11:20 PM, Sergey Beryozkin <sberyozkin@gmail.com
> >wrote:
>
> > Hi Josh
> >
> > thanks for this tip, but my question is to do with you referring to
> > collections of JAXB beans not being supported.
> > I'd appreciate if you could send me an example of such a collection.
> > Explicit collection have been supported for a while and I recall users
> > confirming that it worked for them, so if there's some issue there
> lurking
> > then I'd like to get it fixed :-)
> >
> > thanks, Sergey
> >
> > On Tue, Oct 5, 2010 at 7:24 PM, Josh Holtzman <jholtzman@berkeley.edu
> > >wrote:
> >
> > > This part of the stack trace:
> > >
> > > Caused by: javax.ws.rs.WebApplicationException at
> > >
> > >
> >
> org.apache.cxf.jaxrs.client.AbstractClient.reportNoMessageHandler(AbstractClient.java:487)
> > >
> > > looks like there's no message body writer. I've run into this kind of
> > > problem when trying to return Collections, even collections of JAXB
> > > elements, from JAX-RS endpoints. I usually solve it by wrapping the
> list
> > > in
> > > a root class, and passing the wrapper rather than the Collection, like
> > > this:
> > >
> > > @XmlRootElement(name="deviceList")
> > > public class DeviceList {
> > > @XmlElement
> > > protected List<Device> devices;
> > > }
> > >
> > > Perhaps this might help in your case too, switching from
> > > addDevice(List<Device> device) to addDevice(DeviceList deviceList).
> > >
> > > Josh
> > >
> > > On Tue, Oct 5, 2010 at 8:00 PM, oceanz <oc...@yahoo.com> wrote:
> > >
> > > >
> > > > I changed it to:
> > > > @Path("user/site/plant/device/addDevice1")
> > > > @POST
> > > > @Produces("text/xml")
> > > > @Consumes("multipart/form-data;type=text/xml")
> > > > Device addDevice(List<Device> device);
> > > >
> > > > But it still doesn't work.
> > > > Same exception:Caused by: javax.ws.rs.WebApplicationException
> > > > at
> > > >
> > > >
> > >
> >
> org.apache.cxf.jaxrs.client.AbstractClient.reportNoMessageHandler(AbstractClient.java:487)
> > > > at
> > > >
> > > >
> > >
> >
> org.apache.cxf.jaxrs.client.AbstractClient.writeBody(AbstractClient.java:401)
> > > > at
> > > >
> > > >
> > >
> >
> org.apache.cxf.jaxrs.client.ClientProxyImpl$BodyWriter.handleMessage(ClientProxyImpl.java:514)
> > > > ... 5 more
> > > >
> > > > Device is a JAXB Bean.:
> > > > @Entity(name="device")
> > > > @XmlRootElement(name="device")
> > > > @XmlAccessorType(XmlAccessType.FIELD)
> > > > public class Device extends DomainEntity {
> > > >
> > > > /**
> > > > *
> > > > */
> > > > private static final long serialVersionUID = 1L;
> > > >
> > > > public Device() {}
> > > >
> > > >
> > > > @XmlAttribute(name="deviceName")
> > > > private String deviceName;
> > > >
> > > > @XmlAttribute(name="deviceType")
> > > > private String deviceType;
> > > >
> > > > @XmlAttribute(name="modelNumber")
> > > > private String modelNumber;
> > > >
> > > > @XmlAttribute(name="serialNumber")
> > > > private String serialNumber;
> > > > ..........
> > > > }
> > > >
> > > > Who do I need to do next? Desparate to get this working.
> > > > Thanks for all your help.
> > > > --
> > > > View this message in context:
> > > >
> > >
> >
> http://cxf.547215.n5.nabble.com/Help-required-with-apache-cxf-multiparts-tp3199975p3200103.html
> > > > Sent from the cxf-user mailing list archive at Nabble.com.
> > > >
> > >
> >
>