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

Difference between revisions of "Stardust/Knowledge Base/Integration/Camel/Calling RESTful Service Through Camel Route"

 
(3 intermediate revisions by the same user not shown)
Line 9: Line 9:
 
Let's assume we will be consuming following 2 RESTful services:
 
Let's assume we will be consuming following 2 RESTful services:
  
:* http://localhost:8080/MyFisrtRESTService/pretech/cardNo?cardNo=''1002''
+
:* http://localhost:8080/MyFisrtRESTService/pretech/cardNo?cardNo=''1002'' - ''Custom REST service, you may need to create your own.''
  
 
:* http://ajax.googleapis.com/ajax/services/search/web?q=''Himalya''&v=''1.0''  
 
:* http://ajax.googleapis.com/ajax/services/search/web?q=''Himalya''&v=''1.0''  
Line 23: Line 23:
  
 
:* Configuring Camel Producer Application to Consume http://localhost:8080/MyFisrtRESTService/pretech/cardNo?cardNo=''1002''
 
:* Configuring Camel Producer Application to Consume http://localhost:8080/MyFisrtRESTService/pretech/cardNo?cardNo=''1002''
 +
Click on Application and pick Camel Producer Application, drag and drop it on canvas and then configure it like shown below.
 
[[File:RESTImg7.JPG]]
 
[[File:RESTImg7.JPG]]
  
Line 34: Line 35:
 
<convertBodyTo type="java.lang.String"/>
 
<convertBodyTo type="java.lang.String"/>
 
</source>
 
</source>
 +
 +
'''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:
 +
[[File:INOUTAct1.jpg]]
 
:* Configuring Camel Producer Application to Consume http://ajax.googleapis.com/ajax/services/search/web?q=''Himalya''&v=''1.0''
 
:* Configuring Camel Producer Application to Consume http://ajax.googleapis.com/ajax/services/search/web?q=''Himalya''&v=''1.0''
 +
[[File:RESTImg9.JPG]]
 +
 
Camel route:
 
Camel route:
 
<source lang="xml">
 
<source lang="xml">
Line 44: Line 52:
 
<convertBodyTo type="java.lang.String"/>
 
<convertBodyTo type="java.lang.String"/>
 
</source>
 
</source>
 +
 +
'''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:
 +
[[File: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:
 +
[[File: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:
 +
[[File:RESTImg2.JPG]]
 +
 +
:* Enter the Search Key and Google REST API version on the activity screen (Enter Search Key and API Version- Google):
 +
[[File: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:
 +
[[File:RESTImg5.JPG]]

Latest revision as of 07:43, 9 January 2014

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

Back to the top