Sergey Beryozkin | 1 Feb 13:07 2012
Picon

Re: No message body reader has been found for request class

Hi,
On 31/01/12 23:10, cganesan wrote:
> Hi
>
> I'm trying to exectute an Http POST with following JSON in the request body:
>
> {
>     "id":  "9852654659650"
> }
>
> I expect the JSON to be mapped to the folllowing requestBean Java object to
> be injected before the service method is called:
>
> My service method is as follows:
>
>  <at> POST
>       <at> Consumes(MediaType.APPLICATION_JSON)
>       <at> Path("/test")
>      public String test(RequestBean requestBean) {
>          return "test";
>      }
>
> I get the error:
> No message body reader has been found for request class RequestBean.
>
> The problem is with maping the inputstream to java object.
> I'm using spring configuation as follows. Do I need to configure
> MessageBodyProvider? If so, could you provide some sample?
>
>      <import resource="classpath:META-INF/cxf/cxf.xml" />
>      <import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
>
>      <jaxrs:server id="myService" address="/myService">
>          <jaxrs:serviceBeans>
>              <ref bean="serviceImpl" />
>          </jaxrs:serviceBeans>
>      </jaxrs:server>
>
>      <bean id="serviceImpl" class="services.ServiceImpl" />
>
> Appreciate the help
>
The default JSONProvider which is Jettison based expects RequestBean be 
a JAXB bean, with XmlRootElement, etc.

You may want to register a Jackson provider (within the jaxrs:providers 
section), that should do. Alternatively, try to register a customized 
CXF JSONProvider with an 'unmarshalFromJaxbElement' property set to 
true, that might help too:
http://cxf.apache.org/docs/jax-rs-data-bindings.html#JAX-RSDataBindings-HandlingJAXBbeanswithoutXmlRootElementannotations

Cheers, Sergey

> Thanks
> Chandru
>
> --
> View this message in context: http://cxf.547215.n5.nabble.com/No-message-body-reader-has-been-found-for-request-class-tp5445998p5445998.html
> Sent from the cxf-user mailing list archive at Nabble.com.

--

-- 
Sergey Beryozkin

Talend Community Coders
http://coders.talend.com/

Blog: http://sberyozkin.blogspot.com


Gmane