You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Vincenzo Vitale <vi...@gmail.com> on 2008/04/04 16:35:54 UTC

Problem with JAX-RS services in the last CXF snapshot.

Hi,

I'm trying to integrate the JAX-RS implementation now included in CXF 2.1
(snapshot).

The service is correctly called and the parameters arrive fine but then I
get a page with the message:

No message body writer found for response class : SimpleResponse.

Where SimpleResponse is my custom response bean extending the
javax.ws.rs.core.Response.

Here the code:

@Path("/ButtonService")
public class ButtonWebServiceImpl implements ButtonWebService {


    @Path("/addressButton/{action}/{apiKey}/{countryCode}/{state}/{city}/"
            +
"{street}/{number}/{postCode}/{attribution}/{logoUrl}/{name}/{description}/{source}/{buttonServer}/{buttonArtUrl}")
    @GET
    public SimpleResponse createForAddress(@PathParam(value = "action")
    String action, @PathParam(value = "apiKey")
    String apiKey, @PathParam(value = "countryCode")
    String countryCode, @PathParam(value = "state")
    String state, @PathParam(value = "city")
    String city, @PathParam(value = "street")
    String street, @PathParam(value = "number")
    String number, @PathParam(value = "postCode")
    String postCode, @PathParam(value = "attribution")
    String attribution, @PathParam(value = "logoUrl")
    String logoUrl, @PathParam(value = "name")
    String name, @PathParam(value = "description")
    String description, @PathParam(value = "source")
    String source, @PathParam(value = "buttonServer")
    String buttonServer, @PathParam(value = "buttonArtUrl")
    String buttonArtUrl) {
...
    }
}

and in Spring:

    <jaxrs:server id="buttonWebServiceRest"
        address="/rest/">
        <jaxrs:serviceBeans>
            <ref bean="buttonWebServiceImpl" />
        </jaxrs:serviceBeans>
    </jaxrs:server>


Have any glue on that?


Further questions:

- My SimpleResponse extend the javax Response as I red in the JAXRS new
documentation that this is a requirement for the HTTPMerthod annotation. Is
this valid also for the @GET annotation? How I have to implement it?

- Before the JAXRS implementation I always used to put the annotations at
the interface level but now in this way it doesn't seem to work anymore. I'm
missing something to make it possible? Maybe is this a JAXRS specification?




Thanks in advance,
Vicio.

Re: Problem with JAX-RS services in the last CXF snapshot.

Posted by Vincenzo Vitale <vi...@gmail.com>.
It worked! :-)

So now I'm just returning:

return Response.ok(simpleResponse).build();

where the SimpleResponse class has the @XmlRootElement annotation on top.


Thank you very much for your help,
V.


On Fri, Apr 4, 2008 at 5:51 PM, Beryozkin, Sergey <Se...@iona.com>
wrote:

> Hi
>
> MessageBodyWriter.isWriteable() checks if a given type can be
> serialized, so if say you custom type has no JAXB annotations then no
> matching writer will be found. You may want just to add @XmlRootElement
> to the root of your class, alternatively you can register your custom
> writer. Please check the JAXRS system tests on how this can be
> done...(I'm sorry, at the moment that's our documentation :-)).
>
> Typically You don't need to extend a Response, Response is a convenience
> holder for a status, the entity and response headers
>
> Cheers, Sergey
>
> -----Original Message-----
> From: Vincenzo Vitale [mailto:vincenzo.vitale@gmail.com]
> Sent: 04 April 2008 16:28
> To: cxf-user@incubator.apache.org
> Subject: Re: Problem with JAX-RS services in the last CXF snapshot.
>
> Looking at the CXF code it seems the problem is here:
>
> private <T> MessageBodyWriter<T> chooseMessageWriter(
>        List<MessageBodyWriter> writers, Class<T> type, MediaType
> mediaType)
> {
>        for (MessageBodyWriter<T> ep : writers) {
>            if (!ep.isWriteable(type)) {
>                continue;
>            }
>
> where [org.apache.cxf.jaxrs.provider.AtomFeedProvider@8163c6,
> org.apache.cxf.jaxrs.provider.AtomEntryProvider@bd8b9c,
> org.apache.cxf.jaxrs.provider.JSONProvider@18c8ca,
> org.apache.cxf.jaxrs.provider.BinaryDataProvider@1266392,
> org.apache.cxf.jaxrs.provider.JAXBElementProvider@1531f73,
> org.apache.cxf.jaxrs.provider.StringProvider@35dfb4,
> org.apache.cxf.jaxrs.provider.SourceProvider@f1d0b1]
>
> these are the writers and my class seems not be "registered with this
> writers. Maybe there is a way to make it possible for a writer to have
> my
> class in output... but I'm just guessing... :-)
>
> I will try your solution..
>
>
> Thnaks,
> V.
>
> On Fri, Apr 4, 2008 at 4:51 PM, Sergey Beryozkin
> <se...@iona.com>
> wrote:
>
> > Hi
> >
> > I think you need to return a Response and then in your code do :
> >
> > return Response.setEntity(yourObject).build()
> >
> > I think that just by the virtue of extending a Response you can not
> have
> > it serialized.
> >
> >
> > > - Before the JAXRS implementation I always used to put the
> annotations
> > at
> > > the interface level but now in this way it doesn't seem to work
> anymore.
> > I'm
> > > missing something to make it possible? Maybe is this a JAXRS
> > specification?
> >
> > I've seen on a Jersey list recently that it's a feature of the 0.7 API
> > (spec), we're at a 0.6 level currently...
> > and that annotations will only be supported at a method level, don't
> know
> > more about it at this stage
> >
> > Hope it helps, Sergey
> >
> >
> >
> > > Hi,
> > >
> > > I'm trying to integrate the JAX-RS implementation now included in
> CXF
> > 2.1
> > > (snapshot).
> > >
> > > The service is correctly called and the parameters arrive fine but
> then
> > I
> > > get a page with the message:
> > >
> > > No message body writer found for response class : SimpleResponse.
> > >
> > > Where SimpleResponse is my custom response bean extending the
> > > javax.ws.rs.core.Response.
> > >
> > > Here the code:
> > >
> > > @Path("/ButtonService")
> > > public class ButtonWebServiceImpl implements ButtonWebService {
> > >
> > >
> > >
> >
> @Path("/addressButton/{action}/{apiKey}/{countryCode}/{state}/{city}/"
> > >            +
> > >
> >
> "{street}/{number}/{postCode}/{attribution}/{logoUrl}/{name}/{descriptio
> n}/{source}/{buttonServer}/{buttonArtUrl}")
> > >    @GET
> > >    public SimpleResponse createForAddress(@PathParam(value =
> "action")
> > >    String action, @PathParam(value = "apiKey")
> > >    String apiKey, @PathParam(value = "countryCode")
> > >    String countryCode, @PathParam(value = "state")
> > >    String state, @PathParam(value = "city")
> > >    String city, @PathParam(value = "street")
> > >    String street, @PathParam(value = "number")
> > >    String number, @PathParam(value = "postCode")
> > >    String postCode, @PathParam(value = "attribution")
> > >    String attribution, @PathParam(value = "logoUrl")
> > >    String logoUrl, @PathParam(value = "name")
> > >    String name, @PathParam(value = "description")
> > >    String description, @PathParam(value = "source")
> > >    String source, @PathParam(value = "buttonServer")
> > >    String buttonServer, @PathParam(value = "buttonArtUrl")
> > >    String buttonArtUrl) {
> > > ...
> > >    }
> > > }
> > >
> > > and in Spring:
> > >
> > >    <jaxrs:server id="buttonWebServiceRest"
> > >        address="/rest/">
> > >        <jaxrs:serviceBeans>
> > >            <ref bean="buttonWebServiceImpl" />
> > >        </jaxrs:serviceBeans>
> > >    </jaxrs:server>
> > >
> > >
> > > Have any glue on that?
> > >
> > >
> > > Further questions:
> > >
> > > - My SimpleResponse extend the javax Response as I red in the JAXRS
> new
> > > documentation that this is a requirement for the HTTPMerthod
> annotation.
> > Is
> > > this valid also for the @GET annotation? How I have to implement it?
> > >
> > > - Before the JAXRS implementation I always used to put the
> annotations
> > at
> > > the interface level but now in this way it doesn't seem to work
> anymore.
> > I'm
> > > missing something to make it possible? Maybe is this a JAXRS
> > specification?
> > >
> > >
> > >
> > >
> > > Thanks in advance,
> > > Vicio.
> > >
> >
> > ----------------------------
> > IONA Technologies PLC (registered in Ireland)
> > Registered Number: 171387
> > Registered Address: The IONA Building, Shelbourne Road, Dublin 4,
> Ireland
> >
>
> ----------------------------
> IONA Technologies PLC (registered in Ireland)
> Registered Number: 171387
> Registered Address: The IONA Building, Shelbourne Road, Dublin 4, Ireland
>

RE: Problem with JAX-RS services in the last CXF snapshot.

Posted by "Beryozkin, Sergey" <Se...@iona.com>.
Hi

MessageBodyWriter.isWriteable() checks if a given type can be
serialized, so if say you custom type has no JAXB annotations then no
matching writer will be found. You may want just to add @XmlRootElement
to the root of your class, alternatively you can register your custom
writer. Please check the JAXRS system tests on how this can be
done...(I'm sorry, at the moment that's our documentation :-)).

Typically You don't need to extend a Response, Response is a convenience
holder for a status, the entity and response headers

Cheers, Sergey

-----Original Message-----
From: Vincenzo Vitale [mailto:vincenzo.vitale@gmail.com] 
Sent: 04 April 2008 16:28
To: cxf-user@incubator.apache.org
Subject: Re: Problem with JAX-RS services in the last CXF snapshot.

Looking at the CXF code it seems the problem is here:

private <T> MessageBodyWriter<T> chooseMessageWriter(
        List<MessageBodyWriter> writers, Class<T> type, MediaType
mediaType)
{
        for (MessageBodyWriter<T> ep : writers) {
            if (!ep.isWriteable(type)) {
                continue;
            }

where [org.apache.cxf.jaxrs.provider.AtomFeedProvider@8163c6,
org.apache.cxf.jaxrs.provider.AtomEntryProvider@bd8b9c,
org.apache.cxf.jaxrs.provider.JSONProvider@18c8ca,
org.apache.cxf.jaxrs.provider.BinaryDataProvider@1266392,
org.apache.cxf.jaxrs.provider.JAXBElementProvider@1531f73,
org.apache.cxf.jaxrs.provider.StringProvider@35dfb4,
org.apache.cxf.jaxrs.provider.SourceProvider@f1d0b1]

these are the writers and my class seems not be "registered with this
writers. Maybe there is a way to make it possible for a writer to have
my
class in output... but I'm just guessing... :-)

I will try your solution..


Thnaks,
V.

On Fri, Apr 4, 2008 at 4:51 PM, Sergey Beryozkin
<se...@iona.com>
wrote:

> Hi
>
> I think you need to return a Response and then in your code do :
>
> return Response.setEntity(yourObject).build()
>
> I think that just by the virtue of extending a Response you can not
have
> it serialized.
>
>
> > - Before the JAXRS implementation I always used to put the
annotations
> at
> > the interface level but now in this way it doesn't seem to work
anymore.
> I'm
> > missing something to make it possible? Maybe is this a JAXRS
> specification?
>
> I've seen on a Jersey list recently that it's a feature of the 0.7 API
> (spec), we're at a 0.6 level currently...
> and that annotations will only be supported at a method level, don't
know
> more about it at this stage
>
> Hope it helps, Sergey
>
>
>
> > Hi,
> >
> > I'm trying to integrate the JAX-RS implementation now included in
CXF
> 2.1
> > (snapshot).
> >
> > The service is correctly called and the parameters arrive fine but
then
> I
> > get a page with the message:
> >
> > No message body writer found for response class : SimpleResponse.
> >
> > Where SimpleResponse is my custom response bean extending the
> > javax.ws.rs.core.Response.
> >
> > Here the code:
> >
> > @Path("/ButtonService")
> > public class ButtonWebServiceImpl implements ButtonWebService {
> >
> >
> >
>
@Path("/addressButton/{action}/{apiKey}/{countryCode}/{state}/{city}/"
> >            +
> >
>
"{street}/{number}/{postCode}/{attribution}/{logoUrl}/{name}/{descriptio
n}/{source}/{buttonServer}/{buttonArtUrl}")
> >    @GET
> >    public SimpleResponse createForAddress(@PathParam(value =
"action")
> >    String action, @PathParam(value = "apiKey")
> >    String apiKey, @PathParam(value = "countryCode")
> >    String countryCode, @PathParam(value = "state")
> >    String state, @PathParam(value = "city")
> >    String city, @PathParam(value = "street")
> >    String street, @PathParam(value = "number")
> >    String number, @PathParam(value = "postCode")
> >    String postCode, @PathParam(value = "attribution")
> >    String attribution, @PathParam(value = "logoUrl")
> >    String logoUrl, @PathParam(value = "name")
> >    String name, @PathParam(value = "description")
> >    String description, @PathParam(value = "source")
> >    String source, @PathParam(value = "buttonServer")
> >    String buttonServer, @PathParam(value = "buttonArtUrl")
> >    String buttonArtUrl) {
> > ...
> >    }
> > }
> >
> > and in Spring:
> >
> >    <jaxrs:server id="buttonWebServiceRest"
> >        address="/rest/">
> >        <jaxrs:serviceBeans>
> >            <ref bean="buttonWebServiceImpl" />
> >        </jaxrs:serviceBeans>
> >    </jaxrs:server>
> >
> >
> > Have any glue on that?
> >
> >
> > Further questions:
> >
> > - My SimpleResponse extend the javax Response as I red in the JAXRS
new
> > documentation that this is a requirement for the HTTPMerthod
annotation.
> Is
> > this valid also for the @GET annotation? How I have to implement it?
> >
> > - Before the JAXRS implementation I always used to put the
annotations
> at
> > the interface level but now in this way it doesn't seem to work
anymore.
> I'm
> > missing something to make it possible? Maybe is this a JAXRS
> specification?
> >
> >
> >
> >
> > Thanks in advance,
> > Vicio.
> >
>
> ----------------------------
> IONA Technologies PLC (registered in Ireland)
> Registered Number: 171387
> Registered Address: The IONA Building, Shelbourne Road, Dublin 4,
Ireland
>

----------------------------
IONA Technologies PLC (registered in Ireland)
Registered Number: 171387
Registered Address: The IONA Building, Shelbourne Road, Dublin 4, Ireland

Re: Problem with JAX-RS services in the last CXF snapshot.

Posted by Vincenzo Vitale <vi...@gmail.com>.
Looking at the CXF code it seems the problem is here:

private <T> MessageBodyWriter<T> chooseMessageWriter(
        List<MessageBodyWriter> writers, Class<T> type, MediaType mediaType)
{
        for (MessageBodyWriter<T> ep : writers) {
            if (!ep.isWriteable(type)) {
                continue;
            }

where [org.apache.cxf.jaxrs.provider.AtomFeedProvider@8163c6,
org.apache.cxf.jaxrs.provider.AtomEntryProvider@bd8b9c,
org.apache.cxf.jaxrs.provider.JSONProvider@18c8ca,
org.apache.cxf.jaxrs.provider.BinaryDataProvider@1266392,
org.apache.cxf.jaxrs.provider.JAXBElementProvider@1531f73,
org.apache.cxf.jaxrs.provider.StringProvider@35dfb4,
org.apache.cxf.jaxrs.provider.SourceProvider@f1d0b1]

these are the writers and my class seems not be "registered with this
writers. Maybe there is a way to make it possible for a writer to have my
class in output... but I'm just guessing... :-)

I will try your solution..


Thnaks,
V.

On Fri, Apr 4, 2008 at 4:51 PM, Sergey Beryozkin <se...@iona.com>
wrote:

> Hi
>
> I think you need to return a Response and then in your code do :
>
> return Response.setEntity(yourObject).build()
>
> I think that just by the virtue of extending a Response you can not have
> it serialized.
>
>
> > - Before the JAXRS implementation I always used to put the annotations
> at
> > the interface level but now in this way it doesn't seem to work anymore.
> I'm
> > missing something to make it possible? Maybe is this a JAXRS
> specification?
>
> I've seen on a Jersey list recently that it's a feature of the 0.7 API
> (spec), we're at a 0.6 level currently...
> and that annotations will only be supported at a method level, don't know
> more about it at this stage
>
> Hope it helps, Sergey
>
>
>
> > Hi,
> >
> > I'm trying to integrate the JAX-RS implementation now included in CXF
> 2.1
> > (snapshot).
> >
> > The service is correctly called and the parameters arrive fine but then
> I
> > get a page with the message:
> >
> > No message body writer found for response class : SimpleResponse.
> >
> > Where SimpleResponse is my custom response bean extending the
> > javax.ws.rs.core.Response.
> >
> > Here the code:
> >
> > @Path("/ButtonService")
> > public class ButtonWebServiceImpl implements ButtonWebService {
> >
> >
> >
>  @Path("/addressButton/{action}/{apiKey}/{countryCode}/{state}/{city}/"
> >            +
> >
> "{street}/{number}/{postCode}/{attribution}/{logoUrl}/{name}/{description}/{source}/{buttonServer}/{buttonArtUrl}")
> >    @GET
> >    public SimpleResponse createForAddress(@PathParam(value = "action")
> >    String action, @PathParam(value = "apiKey")
> >    String apiKey, @PathParam(value = "countryCode")
> >    String countryCode, @PathParam(value = "state")
> >    String state, @PathParam(value = "city")
> >    String city, @PathParam(value = "street")
> >    String street, @PathParam(value = "number")
> >    String number, @PathParam(value = "postCode")
> >    String postCode, @PathParam(value = "attribution")
> >    String attribution, @PathParam(value = "logoUrl")
> >    String logoUrl, @PathParam(value = "name")
> >    String name, @PathParam(value = "description")
> >    String description, @PathParam(value = "source")
> >    String source, @PathParam(value = "buttonServer")
> >    String buttonServer, @PathParam(value = "buttonArtUrl")
> >    String buttonArtUrl) {
> > ...
> >    }
> > }
> >
> > and in Spring:
> >
> >    <jaxrs:server id="buttonWebServiceRest"
> >        address="/rest/">
> >        <jaxrs:serviceBeans>
> >            <ref bean="buttonWebServiceImpl" />
> >        </jaxrs:serviceBeans>
> >    </jaxrs:server>
> >
> >
> > Have any glue on that?
> >
> >
> > Further questions:
> >
> > - My SimpleResponse extend the javax Response as I red in the JAXRS new
> > documentation that this is a requirement for the HTTPMerthod annotation.
> Is
> > this valid also for the @GET annotation? How I have to implement it?
> >
> > - Before the JAXRS implementation I always used to put the annotations
> at
> > the interface level but now in this way it doesn't seem to work anymore.
> I'm
> > missing something to make it possible? Maybe is this a JAXRS
> specification?
> >
> >
> >
> >
> > Thanks in advance,
> > Vicio.
> >
>
> ----------------------------
> IONA Technologies PLC (registered in Ireland)
> Registered Number: 171387
> Registered Address: The IONA Building, Shelbourne Road, Dublin 4, Ireland
>

Re: Problem with JAX-RS services in the last CXF snapshot.

Posted by Sergey Beryozkin <se...@iona.com>.
Hi

I think you need to return a Response and then in your code do :

return Response.setEntity(yourObject).build()

I think that just by the virtue of extending a Response you can not have it serialized.


> - Before the JAXRS implementation I always used to put the annotations at
> the interface level but now in this way it doesn't seem to work anymore. I'm
> missing something to make it possible? Maybe is this a JAXRS specification?

I've seen on a Jersey list recently that it's a feature of the 0.7 API (spec), we're at a 0.6 level currently...
and that annotations will only be supported at a method level, don't know more about it at this stage 

Hope it helps, Sergey



> Hi,
> 
> I'm trying to integrate the JAX-RS implementation now included in CXF 2.1
> (snapshot).
> 
> The service is correctly called and the parameters arrive fine but then I
> get a page with the message:
> 
> No message body writer found for response class : SimpleResponse.
> 
> Where SimpleResponse is my custom response bean extending the
> javax.ws.rs.core.Response.
> 
> Here the code:
> 
> @Path("/ButtonService")
> public class ButtonWebServiceImpl implements ButtonWebService {
> 
> 
>    @Path("/addressButton/{action}/{apiKey}/{countryCode}/{state}/{city}/"
>            +
> "{street}/{number}/{postCode}/{attribution}/{logoUrl}/{name}/{description}/{source}/{buttonServer}/{buttonArtUrl}")
>    @GET
>    public SimpleResponse createForAddress(@PathParam(value = "action")
>    String action, @PathParam(value = "apiKey")
>    String apiKey, @PathParam(value = "countryCode")
>    String countryCode, @PathParam(value = "state")
>    String state, @PathParam(value = "city")
>    String city, @PathParam(value = "street")
>    String street, @PathParam(value = "number")
>    String number, @PathParam(value = "postCode")
>    String postCode, @PathParam(value = "attribution")
>    String attribution, @PathParam(value = "logoUrl")
>    String logoUrl, @PathParam(value = "name")
>    String name, @PathParam(value = "description")
>    String description, @PathParam(value = "source")
>    String source, @PathParam(value = "buttonServer")
>    String buttonServer, @PathParam(value = "buttonArtUrl")
>    String buttonArtUrl) {
> ...
>    }
> }
> 
> and in Spring:
> 
>    <jaxrs:server id="buttonWebServiceRest"
>        address="/rest/">
>        <jaxrs:serviceBeans>
>            <ref bean="buttonWebServiceImpl" />
>        </jaxrs:serviceBeans>
>    </jaxrs:server>
> 
> 
> Have any glue on that?
> 
> 
> Further questions:
> 
> - My SimpleResponse extend the javax Response as I red in the JAXRS new
> documentation that this is a requirement for the HTTPMerthod annotation. Is
> this valid also for the @GET annotation? How I have to implement it?
> 
> - Before the JAXRS implementation I always used to put the annotations at
> the interface level but now in this way it doesn't seem to work anymore. I'm
> missing something to make it possible? Maybe is this a JAXRS specification?
> 
> 
> 
> 
> Thanks in advance,
> Vicio.
> 

----------------------------
IONA Technologies PLC (registered in Ireland)
Registered Number: 171387
Registered Address: The IONA Building, Shelbourne Road, Dublin 4, Ireland