chris chris - 1 year ago 177
JSON Question

How to invoke a REST call (POST with JSON body) from Camel in blueprint

I want to call a POST rest service in camel blueprint. My blueprint xml file is the following:

<blueprint xmlns=""
xmlns:xsi="" xsi:schemaLocation="">
<bean class="org.apache.cxf.jaxrs.provider.json.JSONProvider" id="jsonProvider"/>
<cxf:rsClient address=""
id="rsClient" loggingFeatureEnabled="true">
<ref bean="jsonProvider" component-id="jsonProvider"/>
<camelContext id="RESTCamelContext" xmlns="">
<route id="RESTRoute">
<from id="_from1" uri="timer:foor?repeatCount=1"/>
<to id="_to1" uri="log:body?level=INFO"/>
<setHeader headerName="Content-Type" id="_setHeader1">
<setHeader headerName="Exchange.HTTP_METHOD" id="_setHeader2">

<to id="_to2" uri="cxfrs:bean:rsClient"/>
<to id="_to3" uri="log:body?level=INFO"/>

but I don't know how to pass the JSON object in the body request.

Answer Source

The easiest way would be to use HTTP4 component:

<setHeader headerName="CamelHttpMethod">
<setBody>  make your POJO here </setBody>
    <json library="Jackson" />
<to uri="http4://"/>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download