Adakbar Adakbar - 1 year ago 424
reST (reStructuredText) Question

Call REST service from Apache Camel Blueprint

I want to call external REST service that return a JSON, the REST itself have a basic authentication (which I don't know how to send a basic authentication), I've read some tutorial and also CXFRS component that lead me to this


<?xml version="1.0" encoding="UTF-8"?>

<blueprint xmlns=""

<bean id="jsonProvider" class="org.apache.cxf.jaxrs.provider.json.JSONProvider"/>

<cxf:rsClient id="rsClient" address="http://localhost/test.php">
<ref bean="jsonProvider"/>

<camelContext xmlns="">
<propertyPlaceholder location="" id="placeholder"/>

<from uri="cxfrs://bean://rsClient"/>
<log message="${body}"/>



If it's even relevant, I'm using JBoss Developer Studio to develop and to test using right click on
blueprint.xml -> Run As -> Local Camel Context (without tests)
here is output from that.

[ERROR] *************************************
[ERROR] Error occurred while running main from: org.apache.camel.test.blueprint.Main
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(
at sun.reflect.DelegatingMethodAccessorImpl.invoke(
at java.lang.reflect.Method.invoke(
at org.apache.camel.maven.RunMojo$
Caused by: java.lang.RuntimeException: Gave up waiting for service (objectClass=org.apache.camel.CamelContext)
at org.apache.camel.test.blueprint.CamelBlueprintHelper.getOsgiService(
at org.apache.camel.test.blueprint.CamelBlueprintHelper.getOsgiService(
at org.apache.camel.test.blueprint.Main.doStart(
at org.apache.camel.test.blueprint.Main.main(
... 6 more
[ERROR] *************************************
[INFO] ------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 01:07 min
[INFO] Finished at: 2016-10-04T12:11:28+07:00
[INFO] Final Memory: 30M/314M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.camel:camel-maven-plugin:2.15.1.redhat-621084:run (default-cli) on project dsource: null: MojoExecutionException: InvocationTargetException: Gave up waiting for service (objectClass=org.apache.camel.CamelContext) -> [Help 1]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1]

Apart the error I got, how exactly I can call or invoke REST service from Apache Camel using Blueprint and get the returned JSON?

Answer Source

I solved this, but using Camel HTTP component, I can easily call REST API and get the JSON response, but first I have to set some header before.

  <from uri="timer:foo?repeatCount=1"/>

  <setHeader headerName="Exchange.HTTP_METHOD">

  <to uri="http:localhost/api/test"/>
  <log message="${body}"/>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download