You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by forumssj <fo...@gmail.com> on 2012/07/02 22:45:40 UTC

POSTing parameters with WebClient.post() throws Exception No message body writer

Hi,

   I am using CXF 2.5.3 SNAPSHOT version and calling a REST webservice using
webclient. The webservice looks like this :
	@Produces("application/json")
	@POST
	@Path("/EditUser")
	public Status editUser(@FormParam("sessionid") String sessionid,
@FormParam("user") User user);

  The code to call the WS is as follows:

        WebClient wc =
WebClient.create(address,Collections.singletonList(new
JacksonJsonProvider())); 
        wc.path("/EditUser");
        Status status = wc.post(new Form().set("sessionid",
strSessionId).set("user", userDataJSON),         Status.class); 

  I get the following exception :
org.apache.cxf.interceptor.Fault: .No message body writer has been found for
class : class org.apache.cxf.jaxrs.ext.form.Form, ContentType :
application/xml.

 What could be going wrong here?

Regards,
SJ


--
View this message in context: http://cxf.547215.n5.nabble.com/POSTing-parameters-with-WebClient-post-throws-Exception-No-message-body-writer-tp5710561.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: POSTing parameters with WebClient.post() throws Exception No message body writer

Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi
On 02/07/12 21:45, forumssj wrote:
> Hi,
>
>     I am using CXF 2.5.3 SNAPSHOT version and calling a REST webservice using
> webclient. The webservice looks like this :
> 	@Produces("application/json")
> 	@POST
> 	@Path("/EditUser")
> 	public Status editUser(@FormParam("sessionid") String sessionid,
> @FormParam("user") User user);
>
>    The code to call the WS is as follows:
>
>          WebClient wc =
> WebClient.create(address,Collections.singletonList(new
> JacksonJsonProvider()));
>          wc.path("/EditUser");
>          Status status = wc.post(new Form().set("sessionid",
> strSessionId).set("user", userDataJSON),         Status.class);
>
>    I get the following exception :
> org.apache.cxf.interceptor.Fault: .No message body writer has been found for
> class : class org.apache.cxf.jaxrs.ext.form.Form, ContentType :
> application/xml.
>
The issue here is that WebClient assumes a provided Object (Form) has 
the (default) application/xml media type given that no Content-Type of 
the outgoing payload has been set up, example, no

webClient.type(MediaType.APPLICATION_FORM_URLENCODED);

has been called.

However I'm pretty sure starting from CXF 2.5.4 or at least CXF 2.6.0,
MediaType.APPLICATION_FORM_URLENCODED is allocated by default for 
objects of type Form if no Content-Type is already set up.

Please try CXF 2.5.4 or simply add a webClient.type() invocation


Cheers, Sergey
>   What could be going wrong here?
>
> Regards,
> SJ
>
>
> --
> View this message in context: http://cxf.547215.n5.nabble.com/POSTing-parameters-with-WebClient-post-throws-Exception-No-message-body-writer-tp5710561.html
> Sent from the cxf-user mailing list archive at Nabble.com.