You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by rpd <Ro...@yahoo.co.uk> on 2013/08/30 08:27:51 UTC

Configure JSON Support to avoid "No message body writer has been found for response"

Hi

CXF is still very new to me and will be for sometime I guess.  My Hello
World service worked just fine when producing XML.  If I switch to
@Produces("application/json") I get the message on the client...

"No message body writer has been found for response"

I'm using REST with CXFNonSpringJaxrsServlet and I am sure that the message
arises because I have not configured JSON support. 

(1) First of all which specific jars should I include in my lib?  I'm not a
Maven user so therefore at a disadvantage here.  There are a plethora of
likely jar candidates (probably around 10) - things that have 'xjc' and
'jaxb' in their names.  I could just include them all of course but that
would be really messy.

(2) Do I need to configure anything in my web.xml? I read somewhere that
there's a need to initialise JSONProvider.

(3) I notice from the docs that Jettison (the default provider) has some
issues like array-serialization.  I don't really want to have these issues
to contend with myself.  Is it easy to use, say, Jackson instead? I 
have always found this to be a very good library when I used jaxb directly.

(4) Anything else I need to know?
Thanks for your patience.

Rob



--
View this message in context: http://cxf.547215.n5.nabble.com/Configure-JSON-Support-to-avoid-No-message-body-writer-has-been-found-for-response-tp5733320.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: Configure JSON Support to avoid "No message body writer has been found for response"

Posted by rpd <Ro...@yahoo.co.uk>.
Partly solved the problem.  The jettison default JAXB/JSON did not work
originally because, as I thought, I just did not have the right jar files in
lib.  The ones that seemed to work are...

jettison-1.3.4
jaxb-api-2.2.6.jar
jaxb-impl-2.2.6.jar
jaxb-xjc-2.2.6

Hard to know whether that list is definitive but it works for now (not a
maven user). No other configuration in web.xml was needed.  

It sure would be great to have a recipe for binding in, say, Jackson as a
json provider.  I can imagine it would be a good deal more complex than
simply including the jar.  There is also Google's GSON.

thks.





--
View this message in context: http://cxf.547215.n5.nabble.com/Configure-JSON-Support-to-avoid-No-message-body-writer-has-been-found-for-response-tp5733320p5733416.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: Configure JSON Support to avoid "No message body writer has been found for response"

Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi
On 30/08/13 14:32, rpd wrote:
> Hi Sergey
>
> Thanks for your response.  Unfortunately I am not a maven user. Like many people, I just have not got around to learning it. So I normally collate the necessary jars / use ant etc..  It seems like you almost cannot use CXF without maven if you want to have a nice tidy build.  Is that a fair comment?

No :-). We use the maven format in examples, etc, but if you do not use 
Maven then please pick up a library either in CXF libs or download it 
manually or via ant, etc, if it is a 3rd party library.

What is fair is that we do not really have step by step guides like 
"Developing a JAX-RS JSON service in Eclipse", etc, it would be goot to 
have them but it all requires a lot of effort but I agree it is worth 
trying to come up with the few guides like this. I think something like 
that is available for WS services, but not for RS ones

>
> If I want to use Jackson as my json provider, how do I do it without maven?  Which jars to I need and how do I 'bind' it to CXF in order that I may define JSONProvider properly in my web.xml.

Have a look at 
http://cxf.apache.org/docs/jax-rs-data-bindings.html#JAX-RSDataBindings-Jackson

I know newer versions of Jackson are available, but I've no idea if 
those libraries have other dependencies or not, I guess this is when 
Maven can become handy :-)

Re enabling it: list a Jackson provider class in jaxrs.providers servlet 
parameter or use JAX-RS Application to register it

Sergey

>
>
> rgds
>
> Rob
>
>
> ________________________________
>   From: Sergey Beryozkin [via CXF] <ml...@n5.nabble.com>
> To: rpd <Ro...@yahoo.co.uk>
> Sent: Friday, 30 August 2013, 11:53
> Subject: Re: Configure JSON Support to avoid "No message body writer has been found for response"
>
>
>
> Hi Angelo
> On 30/08/13 10:32, Angelo zerr wrote:
>> Hi Sergey,
>>
>> I tell me if it's interesting that CXF provides a servlet status (or
>> another thing) which list the available provider. As CXF is very modular, I
>> find it's hard to know which JARs you must to use when you are newbie.
>> This servlet status could tell this info (JSON provider is not available,
>> please add Jettison in your classpath for instance).
>>
> Thanks for this idea; I think it probably falls into the management
> category. The runtime won't really know that JSONProvider is needed
> because the user may prefer Jackson, etc, but at least it can list the
> registered providers and show what media and Java types they support.
>
> The problem is how to set it up. I'd prefer to have a LogBrowser module
> enhanced, there is a lot of potential there, one tab shows (as it is
> now) the logs, next one - in/out exchange details, next - other
> management info related to WS & RS endpoints, but it would require a
> dedicated effort, I'm hoping it will happen sooner rather than later :-)
>
> Cheers, Sergey
>
>
>
>> Regards Angelo
>>
>>
>> 2013/8/30 Sergey Beryozkin <[hidden email]>
>>
>>> Hi
>>>
>>> On 30/08/13 07:27, rpd wrote:
>>>
>>>> Hi
>>>>
>>>> CXF is still very new to me and will be for sometime I guess.  My Hello
>>>> World service worked just fine when producing XML.  If I switch to
>>>> @Produces("application/json") I get the message on the client...
>>>>
>>>> "No message body writer has been found for response"
>>>>
>>>> I'm using REST with CXFNonSpringJaxrsServlet and I am sure that the
>>>> message
>>>> arises because I have not configured JSON support.
>>>>
>>>> (1) First of all which specific jars should I include in my lib?  I'm not
>>>> a
>>>> Maven user so therefore at a disadvantage here.  There are a plethora of
>>>> likely jar candidates (probably around 10) - things that have 'xjc' and
>>>> 'jaxb' in their names.  I could just include them all of course but that
>>>> would be really messy.
>>>>
>>>>    Default JSONProvider is in cxf-rt-rs-extensions-providers module, and
>>> you also need to add
>>> <dependency>
>>>       <groupId>org.codehaus.**jettison</groupId>
>>>       <artifactId>jettison</**artifactId>
>>>       <version>1.3.4</version>
>>> </dependency>
>>>
>>>
>>>    (2) Do I need to configure anything in my web.xml? I read somewhere that
>>>> there's a need to initialise JSONProvider.
>>>>
>>>
>>> If default provider is used then adding the above dependencies can be
>>> enough, unless you need to configure JSONProvider (ex, to support single
>>> element collections correctly)
>>>
>>>
>>>
>>>> (3) I notice from the docs that Jettison (the default provider) has some
>>>> issues like array-serialization.  I don't really want to have these issues
>>>> to contend with myself.  Is it easy to use, say, Jackson instead? I
>>>> have always found this to be a very good library when I used jaxb
>>>> directly.
>>>>
>>>>
>>> Sure, please add a Jackon dependency and list a provider in web.xml
>>>
>>> Cheers, Sergey
>>>
>>>
>>>    (4) Anything else I need to know?
>>>> Thanks for your patience.
>>>>
>>>> Rob
>>>>
>>>>
>>>>
>>>> --
>>>> View this message in context: http://cxf.547215.n5.nabble.**
>>>> com/Configure-JSON-Support-to-**avoid-No-message-body-writer-**
>>>> has-been-found-for-response-**tp5733320.html<http://cxf.547215.n5.nabble.com/Configure-JSON-Support-to-avoid-No-message-body-writer-has-been-found-for-response-tp5733320.html>
>>>> Sent from the cxf-user mailing list archive at Nabble.com.
>>>>
>>>>
>>>
>>>
>>
>
>
> ________________________________
>
> If you reply to this email, your message will be added to the discussion below:http://cxf.547215.n5.nabble.com/Configure-JSON-Support-to-avoid-No-message-body-writer-has-been-found-for-response-tp5733320p5733335.html
> To unsubscribe from Configure JSON Support to avoid "No message body writer has been found for response", click here.
> NAML
>
>
>
> --
> View this message in context: http://cxf.547215.n5.nabble.com/Configure-JSON-Support-to-avoid-No-message-body-writer-has-been-found-for-response-tp5733320p5733355.html
> Sent from the cxf-user mailing list archive at Nabble.com.
>


Re: Configure JSON Support to avoid "No message body writer has been found for response"

Posted by rpd <Ro...@yahoo.co.uk>.
Hi Sergey 

Thanks for your response.  Unfortunately I am not a maven user. Like many people, I just have not got around to learning it. So I normally collate the necessary jars / use ant etc..  It seems like you almost cannot use CXF without maven if you want to have a nice tidy build.  Is that a fair comment?

If I want to use Jackson as my json provider, how do I do it without maven?  Which jars to I need and how do I 'bind' it to CXF in order that I may define JSONProvider properly in my web.xml.


rgds

Rob


________________________________
 From: Sergey Beryozkin [via CXF] <ml...@n5.nabble.com>
To: rpd <Ro...@yahoo.co.uk> 
Sent: Friday, 30 August 2013, 11:53
Subject: Re: Configure JSON Support to avoid "No message body writer has been found for response"
 


Hi Angelo 
On 30/08/13 10:32, Angelo zerr wrote: 
> Hi Sergey, 
> 
> I tell me if it's interesting that CXF provides a servlet status (or 
> another thing) which list the available provider. As CXF is very modular, I 
> find it's hard to know which JARs you must to use when you are newbie. 
> This servlet status could tell this info (JSON provider is not available, 
> please add Jettison in your classpath for instance). 
> 
Thanks for this idea; I think it probably falls into the management 
category. The runtime won't really know that JSONProvider is needed 
because the user may prefer Jackson, etc, but at least it can list the 
registered providers and show what media and Java types they support. 

The problem is how to set it up. I'd prefer to have a LogBrowser module 
enhanced, there is a lot of potential there, one tab shows (as it is 
now) the logs, next one - in/out exchange details, next - other 
management info related to WS & RS endpoints, but it would require a 
dedicated effort, I'm hoping it will happen sooner rather than later :-) 

Cheers, Sergey 



> Regards Angelo 
> 
> 
> 2013/8/30 Sergey Beryozkin <[hidden email]> 
> 
>> Hi 
>> 
>> On 30/08/13 07:27, rpd wrote: 
>> 
>>> Hi 
>>> 
>>> CXF is still very new to me and will be for sometime I guess.  My Hello 
>>> World service worked just fine when producing XML.  If I switch to 
>>> @Produces("application/json") I get the message on the client... 
>>> 
>>> "No message body writer has been found for response" 
>>> 
>>> I'm using REST with CXFNonSpringJaxrsServlet and I am sure that the 
>>> message 
>>> arises because I have not configured JSON support. 
>>> 
>>> (1) First of all which specific jars should I include in my lib?  I'm not 
>>> a 
>>> Maven user so therefore at a disadvantage here.  There are a plethora of 
>>> likely jar candidates (probably around 10) - things that have 'xjc' and 
>>> 'jaxb' in their names.  I could just include them all of course but that 
>>> would be really messy. 
>>> 
>>>   Default JSONProvider is in cxf-rt-rs-extensions-providers module, and 
>> you also need to add 
>> <dependency> 
>>      <groupId>org.codehaus.**jettison</groupId> 
>>      <artifactId>jettison</**artifactId> 
>>      <version>1.3.4</version> 
>> </dependency> 
>> 
>> 
>>   (2) Do I need to configure anything in my web.xml? I read somewhere that 
>>> there's a need to initialise JSONProvider. 
>>> 
>> 
>> If default provider is used then adding the above dependencies can be 
>> enough, unless you need to configure JSONProvider (ex, to support single 
>> element collections correctly) 
>> 
>> 
>> 
>>> (3) I notice from the docs that Jettison (the default provider) has some 
>>> issues like array-serialization.  I don't really want to have these issues 
>>> to contend with myself.  Is it easy to use, say, Jackson instead? I 
>>> have always found this to be a very good library when I used jaxb 
>>> directly. 
>>> 
>>> 
>> Sure, please add a Jackon dependency and list a provider in web.xml 
>> 
>> Cheers, Sergey 
>> 
>> 
>>   (4) Anything else I need to know? 
>>> Thanks for your patience. 
>>> 
>>> Rob 
>>> 
>>> 
>>> 
>>> -- 
>>> View this message in context: http://cxf.547215.n5.nabble.**
>>> com/Configure-JSON-Support-to-**avoid-No-message-body-writer-** 
>>> has-been-found-for-response-**tp5733320.html<http://cxf.547215.n5.nabble.com/Configure-JSON-Support-to-avoid-No-message-body-writer-has-been-found-for-response-tp5733320.html> 
>>> Sent from the cxf-user mailing list archive at Nabble.com. 
>>> 
>>> 
>> 
>> 
> 


________________________________
 
If you reply to this email, your message will be added to the discussion below:http://cxf.547215.n5.nabble.com/Configure-JSON-Support-to-avoid-No-message-body-writer-has-been-found-for-response-tp5733320p5733335.html 
To unsubscribe from Configure JSON Support to avoid "No message body writer has been found for response", click here.
NAML



--
View this message in context: http://cxf.547215.n5.nabble.com/Configure-JSON-Support-to-avoid-No-message-body-writer-has-been-found-for-response-tp5733320p5733355.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: Configure JSON Support to avoid "No message body writer has been found for response"

Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi Angelo
On 30/08/13 10:32, Angelo zerr wrote:
> Hi Sergey,
>
> I tell me if it's interesting that CXF provides a servlet status (or
> another thing) which list the available provider. As CXF is very modular, I
> find it's hard to know which JARs you must to use when you are newbie.
> This servlet status could tell this info (JSON provider is not available,
> please add Jettison in your classpath for instance).
>
Thanks for this idea; I think it probably falls into the management 
category. The runtime won't really know that JSONProvider is needed 
because the user may prefer Jackson, etc, but at least it can list the 
registered providers and show what media and Java types they support.

The problem is how to set it up. I'd prefer to have a LogBrowser module 
enhanced, there is a lot of potential there, one tab shows (as it is 
now) the logs, next one - in/out exchange details, next - other 
management info related to WS & RS endpoints, but it would require a 
dedicated effort, I'm hoping it will happen sooner rather than later :-)

Cheers, Sergey


> Regards Angelo
>
>
> 2013/8/30 Sergey Beryozkin <sb...@gmail.com>
>
>> Hi
>>
>> On 30/08/13 07:27, rpd wrote:
>>
>>> Hi
>>>
>>> CXF is still very new to me and will be for sometime I guess.  My Hello
>>> World service worked just fine when producing XML.  If I switch to
>>> @Produces("application/json") I get the message on the client...
>>>
>>> "No message body writer has been found for response"
>>>
>>> I'm using REST with CXFNonSpringJaxrsServlet and I am sure that the
>>> message
>>> arises because I have not configured JSON support.
>>>
>>> (1) First of all which specific jars should I include in my lib?  I'm not
>>> a
>>> Maven user so therefore at a disadvantage here.  There are a plethora of
>>> likely jar candidates (probably around 10) - things that have 'xjc' and
>>> 'jaxb' in their names.  I could just include them all of course but that
>>> would be really messy.
>>>
>>>   Default JSONProvider is in cxf-rt-rs-extensions-providers module, and
>> you also need to add
>> <dependency>
>>      <groupId>org.codehaus.**jettison</groupId>
>>      <artifactId>jettison</**artifactId>
>>      <version>1.3.4</version>
>> </dependency>
>>
>>
>>   (2) Do I need to configure anything in my web.xml? I read somewhere that
>>> there's a need to initialise JSONProvider.
>>>
>>
>> If default provider is used then adding the above dependencies can be
>> enough, unless you need to configure JSONProvider (ex, to support single
>> element collections correctly)
>>
>>
>>
>>> (3) I notice from the docs that Jettison (the default provider) has some
>>> issues like array-serialization.  I don't really want to have these issues
>>> to contend with myself.  Is it easy to use, say, Jackson instead? I
>>> have always found this to be a very good library when I used jaxb
>>> directly.
>>>
>>>
>> Sure, please add a Jackon dependency and list a provider in web.xml
>>
>> Cheers, Sergey
>>
>>
>>   (4) Anything else I need to know?
>>> Thanks for your patience.
>>>
>>> Rob
>>>
>>>
>>>
>>> --
>>> View this message in context: http://cxf.547215.n5.nabble.**
>>> com/Configure-JSON-Support-to-**avoid-No-message-body-writer-**
>>> has-been-found-for-response-**tp5733320.html<http://cxf.547215.n5.nabble.com/Configure-JSON-Support-to-avoid-No-message-body-writer-has-been-found-for-response-tp5733320.html>
>>> Sent from the cxf-user mailing list archive at Nabble.com.
>>>
>>>
>>
>>
>


Re: Configure JSON Support to avoid "No message body writer has been found for response"

Posted by Angelo zerr <an...@gmail.com>.
Hi Sergey,

I tell me if it's interesting that CXF provides a servlet status (or
another thing) which list the available provider. As CXF is very modular, I
find it's hard to know which JARs you must to use when you are newbie.
This servlet status could tell this info (JSON provider is not available,
please add Jettison in your classpath for instance).

Regards Angelo


2013/8/30 Sergey Beryozkin <sb...@gmail.com>

> Hi
>
> On 30/08/13 07:27, rpd wrote:
>
>> Hi
>>
>> CXF is still very new to me and will be for sometime I guess.  My Hello
>> World service worked just fine when producing XML.  If I switch to
>> @Produces("application/json") I get the message on the client...
>>
>> "No message body writer has been found for response"
>>
>> I'm using REST with CXFNonSpringJaxrsServlet and I am sure that the
>> message
>> arises because I have not configured JSON support.
>>
>> (1) First of all which specific jars should I include in my lib?  I'm not
>> a
>> Maven user so therefore at a disadvantage here.  There are a plethora of
>> likely jar candidates (probably around 10) - things that have 'xjc' and
>> 'jaxb' in their names.  I could just include them all of course but that
>> would be really messy.
>>
>>  Default JSONProvider is in cxf-rt-rs-extensions-providers module, and
> you also need to add
> <dependency>
>     <groupId>org.codehaus.**jettison</groupId>
>     <artifactId>jettison</**artifactId>
>     <version>1.3.4</version>
> </dependency>
>
>
>  (2) Do I need to configure anything in my web.xml? I read somewhere that
>> there's a need to initialise JSONProvider.
>>
>
> If default provider is used then adding the above dependencies can be
> enough, unless you need to configure JSONProvider (ex, to support single
> element collections correctly)
>
>
>
>> (3) I notice from the docs that Jettison (the default provider) has some
>> issues like array-serialization.  I don't really want to have these issues
>> to contend with myself.  Is it easy to use, say, Jackson instead? I
>> have always found this to be a very good library when I used jaxb
>> directly.
>>
>>
> Sure, please add a Jackon dependency and list a provider in web.xml
>
> Cheers, Sergey
>
>
>  (4) Anything else I need to know?
>> Thanks for your patience.
>>
>> Rob
>>
>>
>>
>> --
>> View this message in context: http://cxf.547215.n5.nabble.**
>> com/Configure-JSON-Support-to-**avoid-No-message-body-writer-**
>> has-been-found-for-response-**tp5733320.html<http://cxf.547215.n5.nabble.com/Configure-JSON-Support-to-avoid-No-message-body-writer-has-been-found-for-response-tp5733320.html>
>> Sent from the cxf-user mailing list archive at Nabble.com.
>>
>>
>
>

Re: Configure JSON Support to avoid "No message body writer has been found for response"

Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi
On 30/08/13 07:27, rpd wrote:
> Hi
>
> CXF is still very new to me and will be for sometime I guess.  My Hello
> World service worked just fine when producing XML.  If I switch to
> @Produces("application/json") I get the message on the client...
>
> "No message body writer has been found for response"
>
> I'm using REST with CXFNonSpringJaxrsServlet and I am sure that the message
> arises because I have not configured JSON support.
>
> (1) First of all which specific jars should I include in my lib?  I'm not a
> Maven user so therefore at a disadvantage here.  There are a plethora of
> likely jar candidates (probably around 10) - things that have 'xjc' and
> 'jaxb' in their names.  I could just include them all of course but that
> would be really messy.
>
Default JSONProvider is in cxf-rt-rs-extensions-providers module, and 
you also need to add
<dependency>
     <groupId>org.codehaus.jettison</groupId>
     <artifactId>jettison</artifactId>
     <version>1.3.4</version>
</dependency>

> (2) Do I need to configure anything in my web.xml? I read somewhere that
> there's a need to initialise JSONProvider.

If default provider is used then adding the above dependencies can be 
enough, unless you need to configure JSONProvider (ex, to support single 
element collections correctly)

>
> (3) I notice from the docs that Jettison (the default provider) has some
> issues like array-serialization.  I don't really want to have these issues
> to contend with myself.  Is it easy to use, say, Jackson instead? I
> have always found this to be a very good library when I used jaxb directly.
>

Sure, please add a Jackon dependency and list a provider in web.xml

Cheers, Sergey

> (4) Anything else I need to know?
> Thanks for your patience.
>
> Rob
>
>
>
> --
> View this message in context: http://cxf.547215.n5.nabble.com/Configure-JSON-Support-to-avoid-No-message-body-writer-has-been-found-for-response-tp5733320.html
> Sent from the cxf-user mailing list archive at Nabble.com.
>