Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Stardust/Knowledge Base/Integration/Camel/Calling RESTful Service Through Camel Route

Requirements

We are required to consume external RESTful service from within Stardust processes.

Appropach

To achieve this we will be using Stardust's application integration called Camel Producer Application.

How To Do

Let's assume we will be consuming following 2 RESTful services:

Note: Text in italic are variable values.

We will be modeling a 3 step process for each of the services, in first step we will enter values for the data to be sent to RESTful service, in the second step we will call these RESTful services and in third step we will show the returned results. So all in all we will be defining a 6 step process (4 manual activities and 2 application asctivities, these application activities will be mapped to respective Camel Producer Application interfaces). The process would look something like:


RESTImg6.JPG


The model file can be found here File:RESTConsumer.zip

Click on Application and pick Camel Producer Application, drag and drop it on canvas and then configure it like shown below. RESTImg7.JPG

Camel route:

<setHeader headerName="CamelHttpMethod"><constant>GET</constant></setHeader>
<setHeader headerName="CamelHttpUri">
<simple>http://localhost:8080/MyFisrtRESTService/pretech/cardNo?cardNo=$simple{header.cardNo}</simple>
</setHeader>
<to uri="http://isoverwritten" />
<convertBodyTo type="java.lang.String"/>

Note: The data which is not selected as Body Input Or Output Access point, will be available to the route in Message Header.

  • Now Let's configure the application activity (Call REST Service) that is associated with this application, double click on application activity and configure IN/OUT access points as shown:

INOUTAct1.jpg

RESTImg9.JPG

Camel route:

<setHeader headerName="CamelHttpMethod"><constant>GET</constant></setHeader>
<setHeader headerName="CamelHttpUri">
<simple>http://ajax.googleapis.com/ajax/services/search/web?q=$simple{header.q}&amp;v=$simple{header.v}</simple>
</setHeader>
<to uri="http://isoverwritten" />
<convertBodyTo type="java.lang.String"/>

Note: The data which is not selected as Body Input Or Output Access point, will be available to the route in Message Header.

  • Now Let's configure the application activity (Call Google Search) that is associated with this application, double click on application activity and configure IN/OUT access points as shown:

INOUTAct2.jpg

  • Once process modeling is done, deploy the model.
  • Start the process "Process Definition 1" you will be presented with first activity screen (Enter Card Number). Enter a card number:

RESTImg1.JPG

  • and complete the activity. The process will call RESTful service passing entered card number as query parameter to the service and fetch you the result:

RESTImg2.JPG

  • Enter the Search Key and Google REST API version on the activity screen (Enter Search Key and API Version- Google):

RESTImg4.JPG

  • and complete the activity. The process will call Google Serach RESTful service passing entered Search key and API version as query parameters to the service and fetch you the result:

RESTImg5.JPG

Copyright © Eclipse Foundation, Inc. All Rights Reserved.