Content Modifier
Introduction:
Content Modifier is very essential and useful step of Cloud Integration which many of
developers might have already tried.
Content Modifier Basics:
Camel Exchange:
Camel Exchange represents an abstraction for an exchange of messages which involves a input
message and its corresponding output or an exception message.
Exchange ID: A unique ID that identifies the exchange.
MEP( Message Exchange Pattern Represents pattern of the exchange.
InOnly when a route handles a one-way message, where the sender doesn’t wait for a
reply from the receiver.
This represents asynchronous message handling where sender doesnt expect Response.
InOut is when a route handles a request-response message. The sender expects a reply
from the route, which will be stored as an out-message in the exchange.
This represents synchronous message handling where sender expect Response ( part of
out-message ).
Exception: If an error occurs during message processing, the reason for the error is stored in the
Exception field of the exchange.
Properties: A form of temporary storage where process steps can store data. Data stored in
property in exist till exchange Exist.
Attachment: Attachment to In-Message or Out-Message which is optional
Content Modifier:
As shown in the above section there are 4 parts to Content Modifier on high level i.e. General,
Headers ,Properties and Body. Lets deep dive into each sections to see what are the different
possibilities or brief use cases we can leverage this step.
1. General:
Always try to enter some meaning full name that helps you to identify high level action
you are going to perform using that Content Modifier.
For example SetParamters, RestrctureData, ReadVariable. Also valid name here will help
you to easily identify the step details in trace.
2. Message Header:
Headers are important aspect of Message which will get propagated to receiver system
or target system. If developers use the headers across their integration flows and don’t
like them to be sent out of Cloud Integration, it's recommended to use properties since
those doesn’t gets propagated to receiver system.
These headers values can be set with values coming from different input data.
Action
Action can have 2 possible values either Create or Delete. Create will add headers to
message and delete will remove the headers from message. Most of the developers use
create headers to use it across their integration process and forget to delete those when
its not necessary. Its always important to reset those headers when not required and
follow the blog to understand how to do it.
Name
Name of the header that is used for later flow steps. These values can be called using
camel expression ${header.<HEADER NAME>}
Type
This field refers different type of values can be assigned to this headers.
1. Constant: Any constant value that will be carried across integration process.
2. Expression:Values can be called using camel simple expressions like
${header.<HEADER_NAME>} ,${property.<PROPERTY_NAME>.Refer the blog to know
more about Camel Simple Expressions.
3. Global Variable: We can use Write Variables step type to create a variable at a certain
point within the message processing sequence to be used across Integration Flows of
cloud integration tenant. To consume the Global variable ( with the scope of tenant )
we can set type as Global Variable and set it to header or property in Content
Modifier.
4. Header: Pass value from other header to newly created header.
5. Local Variable: We can use Write Variables step type to create a variable at a certain
point within the message processing sequence within same integration flow. To
consume the Local variable ( with the scope of integration flow ) we can set type as
Local Variable and set it to header or property in Content Modifier.
6. Number Range: It helps to insert unique sequence numbers as part of the inbound
or outbound messages. To consume Number Ranges we can set type as Number
Ranges and set it to header or property in Content Modifier.
7. Property: source value depending on the type either header name, a property name,
a variable name or any other type.
8. XPath: Set the value of XPath to header. Refer to know different XPath functions
supported.
9. Data Type: The Data Type column is used only for the types XPath and Expression.
The data type can belong to any Java class. Refer to know more about supported
datatypes.
10. Value: Place holder for source value. Its value depends on the type ( like Header,
Property, Local Variable...)
o Default: If you have selected Local Variable or Global Variable as Type, the value
specified as Default will be assigned to the header value if the variable is not found
at runtime.
3. Exchange Property:
Properties are important aspect of Message which will not get propagated to receiver
system or target system. Boundary condition for properties is integration flow. Rest of
the configuration. remains same as header.
4. Message Body
Body contains actual message or content. There are 2 ways you can set the body value
either a constant or using camel simple expressions. If body is kept empty that the body
is not changed.
Lets try to document some of the usefull tricks and tips with Content Modifier.
Use Case 1 - Dealing with date function
Its very easy to set headers or properties with date values using simple expressions. As per
Apache camel simple expression guide below well defines date and date with timezone.
Date formatting
String
date:_command:pattern using [Link] patterns.
Date formatting
date-with-
String using [Link] timezones
timezone:_command:timezone:pattern_
and patterns.
Examples:
Simple Expression Output Value
${date:now:yyyyMMdd'T'hh:mm:ss} 20211201T03:34:48
${date:now:yyyyMMdd} 20211201
${date:now:yyyyMMdd HH:mm:ss} 20211201 15:34:48
${date:now:yyyyMMdd HH:mm:[Link]} 20211201 15:34:48.54UTC
${date:now:yyyyMMdd'T'HH:mm:[Link] Z} 20211201T15:34:48.054 +0000
${date:now:yyyyMMdd HH:mm:[Link] aaa} 20211201 15:34:48.054 PM
How to add more details into date time patterns:
Refer below table that would help you to get more values as per [Link].
Letter Date or Time Component Presentation Examples
G Era designator Text AD
y Year Year 1996; 96
Y Week year Year 2009; 09
M Month in year Month July; Jul; 07
w Week in year Number 27
W Week in month Number 2
D Day in year Number 189
d Day in month Number 10
F Day of week in month Number 2
E Day name in week Text Tuesday; Tue
u Day number of week (1 = Number 1
Monday, ..., 7 = Sunday)
a Am/pm marker Text PM
H Hour in day (0-23) Number 0
k Hour in day (1-24) Number 24
K Hour in am/pm (0-11) Number 0
h Hour in am/pm (1-12) Number 12
m Minute in hour Number 30
s Second in minute Number 55
S Millisecond Number 978
z Time zone General time zone Pacific Standard
Time; PST; GMT-08:00
Z Time zone RFC 822 time zone -800
X Time zone ISO 8601 time zone -08; -0800; -08:00
Use Case 2:Using Java string functions with headers and properties
We can use java string functions with headers ,properties and body to set the manipulated
values
Below are the few functions that could be used with Headers,Properties and Body.
Function Description
${[Link](8,14)} gets substring from given input data
${[Link]()} Converts the data into uppercase
${[Link]()} gets the length of the body
${[Link]('S','K')} Replaces first occurances of letter in input data
${[Link]('\\','\+')} Replaces all the occurance of matching data
${[Link]("dinacpi")} returns true if data exist
removes the whitespaces from start and end of the given
${[Link]()}
string
Use Case 3 : Handling XPATH expressions
Xpath expressions are very usefull while dealing with XML data and inside content modifier we
can achieve transformation to certains [Link] XPath functions for deep diving more into the
same.
Type Value Description
Gives list of values seperated
[Link] string-join(Root/Record/CustomerID,',') by comma ( like
'1UUUYWYW,2,32,44')
substring(Root/Record/CustomerID,1,3) Gives substring value 1UU
Get root elements name
/*/local-name() exlcuding namespace and
prefix
Use Case 4: Playing around message content
Usually most of us come across generating CSV file having field header names with [Link]
XML standards doesnt allow to have spaces in element name its easy to tackle the same using
content [Link] while concating the data content encoding needs to be carefully
considered to avoid any data corruption issues.
Use Case 5: simplify configuration of runtime parameters
Using content modifier most of the user runtime input parameters for iflow can be
[Link] we use Parameter Externalization concept to achieve the same.
Simple Input parameter screen ( configure option in Iflow)
How content modifier can be used ( most of the parameters are part of content modifier which
later used across Integration Process