Skip to main content Skip to complementary content

Creating a Route to use an external map

Create a Route and configure components to create and use external map variables.

Procedure

  1. In the Integration perspective, right-click the Route Designs node and click Create Route.
  2. Enter a name, purpose and description for your Route, then click Finish.
  3. Add the following components to your design workspace and link them with Row > Route connections:
    • A cTimer
    • A cProcessor
    • A cSetBody
    • A cMap
    • A cLog
    • A second cProcessor
    Your Route should look like this:
  4. Double-click the first cProcessor component and configure it as follows:
    Parameter Value
    Import
    import java.util.*;
    Code
    Map<String, Object> externalMap = new HashMap<>();
    externalMap.put("current.date",TalendDate.getCurrentDate());
    Map<String, Object> executionProperties = exchange.getIn().getHeaders();
    if (executionProperties==null){
      executionProperties = new HashMap<>();
      exchange.getIn().setHeaders(executionProperties);
    }
    executionProperties.put("org.talend.transform.externalmap", externalMap);

    This code allows you to create an external map variable named current.date that you can then use in your map.

  5. Double-click the cSetBody component and configure it as follows:
    Parameter Value
    Language Constant
    Expression "<orders><order><orderId>abc-6545165186</orderId><shippingDetails><lastName>Kennedy</lastName><firstName>John</firstName><street>Santa Rosa South</street><city>Columbus</city><state>New York</state></shippingDetails><items><item><id>4987601</id><price>649.99</price><quantity>1</quantity></item><item><id>8570817</id><price>99.99</price><quantity>3</quantity></item></items></order></orders>"
  6. Double-click the second cProcessor component and configure it as follows:
    Parameter Value
    Code
    Map<String, Object> executionProperties = exchange.getIn().getHeaders();
    if (executionProperties==null){
      executionProperties = new HashMap<>();
      exchange.getIn().setHeaders(executionProperties);
    }
    Map<String, Object> externalMap = (Map<String, Object>)executionProperties.get("org.talend.transform.externalmap");
    System.out.println("Order ID: " + (String)externalMap.get("order.id"));
    System.out.println("Order due date: " + (String)externalMap.get("due.date"));

    This code allows you to print the order.id and due.date external map variables that you will define in your map.

Results

Your Route is configured, you can now generate and configure your map.

Did this page help you?

If you find any issues with this page or its content – a typo, a missing step, or a technical error – please let us know!