Hi Christian,

Thanks for this tip, FYI, CXF will try to use JSON provider (with the default configuration) if it has not been explicitly configured (example, a namespace map may be not strictly needed, etc). I wonder, if in this specific case, HTTP Accept header is actually set to application/xml, so the fact the service can produce JSON is ignored, not really sure though

Cheers, Sergey
On 29/06/13 14:45, Christian Müller wrote:
You have to tell CXF to use JSON. We do this with the following
configuration:

<util:map id="jsonNamespaceMap" map-class="java.util.Hashtable">
     <entry key="http://www.myCompany.com/product/service/model/1";
value="m"/>
</util:map>

<jaxrs:server id="jaxrsServer"
     address="${jaxrsServerEndpointUri}"
     staticSubresourceResolution="true">

     <jaxrs:serviceBeans>
         <bean
class="com.company.productname.servicename.services.jaxrs.XYZResourceImpl"
/>
     </jaxrs:serviceBeans>

     <jaxrs:providers>
         <bean class="org.apache.cxf.jaxrs.provider.json.JSONProvider">
             <property name="namespaceMap" ref="jsonNamespaceMap" />
         </bean>
         <bean class="org.apache.cxf.jaxrs.provider.JAXBElementProvider" />
     </jaxrs:providers>
</jaxrs:server>

You can read more about it here:
http://cxf.apache.org/docs/jax-rs-data-bindings.html

Best,
Christian
-----------------

Software Integration Specialist

Apache Camel committer: https://camel.apache.org/team
V.P. Apache Camel: https://www.apache.org/foundation/
Apache Member: https://www.apache.org/foundation/members.html

https://www.linkedin.com/pub/christian-mueller/11/551/642


On Fri, Jun 28, 2013 at 8:55 PM, ajaysam <ajay.sam...@gmail.com> wrote:

I have a resource class with method defined like this
@Produces({"application/json"})
         public Response getMessage(
                         @PathParam("referenceTypeName") String name,
@QueryParam("")
ReferenceDataRequest query)
{
    return null
}

Then i have applicationcontext.xml for camel as shown below:

- <jaxrs:server id="restService" staticSubresourceResolution="true">
-  <jaxrs:serviceBeans>
       <ref bean="restResource" />
   </jaxrs:serviceBeans>
- <jaxrs:providers>
   <ref bean="cxfJaxrsJsonProvider" />
      </jaxrs:providers>
   </jaxrs:server>

  <bean id="cxfJaxrsJsonProvider"
class="org.apache.cxf.jaxrs.provider.json.JSONProvider" />
  <bean id="restResource" class="com.bms.web.HelloResource" />




- <cxf:rsServer id="HelloRsServer" serviceClass="com.bms.web.HelloResource"
loggingFeatureEnabled="true">

   </cxf:rsServer>


- <camelContext xmlns="http://camel.apache.org/schema/spring";>

-
- <route id="restToSoap" streamCache="true">

   <from uri="cxfrs://bean://HelloRsServer?bindingStyle=SimpleConsumer" />
   <log message="**************** Got ${headers}" />
   <log message="**************** Got Body 111 : ${body}" />
   <to uri="bean:reqProcessor" />
   <log message="**************** Got Headers 222 : ${headers}" />
   <log message="**************** Got Body 333 : ${body}" />
   <to uri="cxf:bean:target_hello" />
   <log message="**************** Got Body 444 : ${body}" />
   <to uri="bean:restRespProcessor" />
   <log message="**************** Got Body 555 : ${body}" />

   </route>
   </camelContext>

My Processor is doing

in.setbody(Response.ok(pojoobject).build());

i m not getting json output..i m getting only xml output






--
View this message in context:
http://camel.465427.n5.nabble.com/Camel-CXFRS-endpoint-unable-to-produce-JSON-tp5734967.html
Sent from the Camel - Users mailing list archive at Nabble.com.



Reply via email to