Create a Route and configure components to create and use external map variables.
Procedure
- In the Integration perspective, right-click the Route Designs node and click Create Route.
- Enter a name, purpose and description for your Route, then click Finish.
-
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: -
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. -
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>" -
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
anddue.date
external map variables that you will define in your map.