cxf-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sergey Beryozkin <sberyoz...@gmail.com>
Subject Re: JAX-RS and Collections of JAXB objects (was: Help required with apache cxf multiparts)
Date Wed, 06 Oct 2010 08:46:50 GMT
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 <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 <oceanz_seven@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.
> > > >
> > >
> >
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message