For the list of all supported Decision Insight downloads and releases, see the Downloads page.

How to inject data into a remote node from a route using the Web services API

Introduction

This cookbook is for educational purpose only. This is not the recommended way to integrate multiple nodes.

 

In this cookbook, you will learn how to invoke a mapping located on a node from a route running on another node.

If you want to quickly execute the cookbook, you can use the same product instance for the local & remote one.

Remote node

On the remote node, follow these steps, or directly import the application export_Cookbook_Web_services API_remote.appx.

Create a simple application

  • Create an application "Cookbook for Web services API (remote)"
  • Create a space "remote"
  • Create a 1 minute rhythm
  • Create an entity "Customer"
    • Create an attribute "name" of type String
    • Create an attribute "vip" of type Boolean
    • Create a key with "name" as attribute

Create the mapping

  • Create a Data integration mapping "createCustomer" with 2 parameters: name (String) and vip (Boolean)

Local node

On the local node, follow these steps, or directly import the application export_Cookbook_Web_services API_local.appx

Install Gson DataFormat

Create the route to invoke the mapping

  • Create a route "RemoteMapping" with the following content
    • replace localhost with the name of the remote host if applicable
    • replace the admin/admin credentials if applicable
<routes xmlns="http://camel.apache.org/schema/spring" xmlns:u="http://www.systar.com/aluminium/camel-util">
    <route>
        <from uri="timer://foo?repeatCount=1"/>
         
        <!-- Set proper HTTP headers -->
        <setHeader headerName="CamelHttpMethod">
            <constant>POST</constant>
        </setHeader>
        <setHeader headerName="Content-type">
            <constant>application/json</constant>
        </setHeader>
        <setHeader headerName="Version">
            <constant>1</constant>
        </setHeader>
         
        <!-- Set body using map, then generate a JSON from that -->
        <setBody>
            <u:map-create>
                <u:map-entry key="name" value="Acme Corp" />
                <u:map-entry key="vip">
                    <simple resultType="java.lang.Boolean">true</simple>
                </u:map-entry>
            </u:map-create>
        </setBody>
        <marshal>
            <json library="Gson" />
        </marshal>
        <convertBodyTo type="String" />
        
        <!-- Call Web service -->
        <log message="Creating customer on remote node..."/>
        <to uri="http4://localhost:8080/ws/absorb/remote/createCustomer?authMethod=Basic&amp;authUsername=admin&amp;authPassword=admin"/>
        
        <!-- Convert the result to GSON, then extract the transactionTime into the body -->
        <unmarshal>
            <json library="Gson" />
        </unmarshal>
        <setBody>
            <simple resultType="java.lang.Long">${body['transactionTime']}</simple>
        </setBody>
         
        <!-- Log a nice message -->
        <log message="...Customer successfully created on remote node with transactionTime ${body}"/>
    </route>
</routes>

Run the route

  • Start the route
  • Go to the logs for the routes, you should see the following messages
Creating customer on remote node...
...Customer successfully created on remote node with transactionTime 1487948593413226496

On the remote node, you should now have a customer named "Acme Corp"  (if not, move the time machine forward as the Customer is created at Now). 

Related Links