Skip to Content
Technical Articles
Author's profile photo Sriprasad S Bhat

SAP Integration Suite- Deep dive into Content Modifier

Introduction:

Content Modifier is very essential and useful step of Cloud Integration which many of developers might have already tried.In below blog post I will try to cover some of the uses cases which are very helpful for beginners to understand how we can leverage this useful step.

Content Modifier Basics:

As most of you already aware of the fact that Cloud Integration leverages Apache Camel then what concept does Content Modifier represents,lets try to understand some basic characterstics of Content Modifier.

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 reciever 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 doesnt 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 thier 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.
    • 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.
    • Value: Place holder for source value.Its value depends on the type ( like Header,Property,Local Variable…)
    • 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 reciever 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:_command:pattern_

String

Date formatting using java.text.SimpleDateFormat patterns.

date-with-timezone:_command:timezone:pattern_

String

Date formatting using java.text.SimpleDateFormat timezones 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:ss.Sz} 20211201 15:34:48.54UTC
${date:now:yyyyMMdd’T’HH:mm:ss.SSS Z} 20211201T15:34:48.054 +0000
${date:now:yyyyMMdd HH:mm:ss.SSS 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 java.text.SimpleDateFormat

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 = Monday, …, 7 = Sunday) Number 1
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

Beow are the few functions that could be used with Headers,Properties and Body.

Function Description
${body.substring(8,14)} gets substring from given input data
${header.title.toUpperCase()} Converts the data into uppercase
${body.length()} gets the length of the body
${body.replaceFirst(‘S’,’K’)} Replaces first occurances of letter in input data
${body.replaceAll(‘\\’,’\+’)} Replaces all the occurance of matching data
${body.contains(“Sriprasad”)} returns true if data exist
${body.trim()} removes the whitespaces from start and end of the given 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 level.Refer XPath functions for deep diving more into the same.

Type Value Description
org.w3c.dom.NodeList string-join(Root/Record/CustomerID,’,’) Gives list of values seperated by comma ( like ‘1UUUYWYW,2,32,44’)
substring(Root/Record/CustomerID,1,3) Gives substring value 1UU
/*/local-name() Get root elements 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 spaces.Since XML standards doesnt allow to have spaces in element name its easy to tackle the same using content modifier.Also 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 managed.Here 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 ):

 

Will be adding more usecases going further please do watch this place more content!

 

Cheers!

Sriprasad Shivaram Bhat

Assigned Tags

      9 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Priyank Shrivastava
      Priyank Shrivastava

      Good one.. got the new java functions with header, properties and Body. Like substring and replace all

      Author's profile photo Kris Chau
      Kris Chau

      Nice and Crisp Explanation.

      Author's profile photo ravi subramanya
      ravi subramanya

      Hi Sriprasad,

      Nice blog.

      I have always found difficult to understand replaceAll.

      In your example also, you mentioned ${body.replaceAll(‘\\’,’\+’)}. Here these double slashes and inverted commas, I'm not able to understand. What will replace what here. If you can explain this. It will help.

      Author's profile photo Parth Khare
      Parth Khare

      Hi Sriprasad,

      Amazing blog!

      Can we also add Days to the Current date function in property itself?

      For eg; I want to add 10 days in the current date, so can I handle this in Content modifier without using any groovy?

      Author's profile photo Rashmi Joshi
      Rashmi Joshi

      Hi Sriprasad S Bhat,

      Is it possible to mask/hide body from content modifier at runtime?

      We are sending sensitive data CM - Body, receiver system doesnt accept encrypted payload.

      BR,

      RJ

      Author's profile photo Luvleen Gorea
      Luvleen Gorea

      Hello Sriprasad,

       

      Can we use these functions on XML body? I am trying to check if my xml payload has this node?

      I am getting the below error when I try that:

      org.apache.camel.language.bean.RuntimeBeanExpressionException: Failed to invoke method: contains(“Results”) on null due to: org.apache.camel.component.bean.MethodNotFoundException: Method with name: contains(“Results”) not found on bean:

      Author's profile photo Andrew Page
      Andrew Page

      Hi Luvleen, did you ever get this to work.  I am getting the same issue with replaceAll and substring but I  cannot see how to get it to work

      Author's profile photo Yash Arora
      Yash Arora

      Nicely Explained! Thanks for sharing this information.

      Can we extract XML path functions for the XMLs which are having the namespace and we are bound to not to remove that?

      Author's profile photo Andrew Page
      Andrew Page

      Hi Sriprasad

       

      I am using ${body.replaceAll(‘@’,’’)} to replace all @ symbols in the json body in CPI for an exchange property however I am getting the following error

       

      org.apache.camel.language.bean.RuntimeBeanExpressionException: Failed to invoke method: replaceAll(‘\\’,’\+’) on null due to: org.apache.camel.component.bean.MethodNotFoundException: Method with name: replaceAll(‘\\’,’\+’) not found on bean: org.apache.camel.converter.stream.ByteArrayInputStreamCache@25791c73 of type: org.apache.camel.converter.stream.ByteArrayInputStreamCache. Exchange[ID-65cca645-1ba9-45ff-6b81-0629-1701160349653-423-1], cause: org.apache.camel.component.bean.MethodNotFoundException: Method with name: replaceAll(‘\\’,’\+’) not found on bean: org.apache.camel.converter.stream.ByteArrayInputStreamCache@25791c73 of type: org.apache.camel.converter.stream.ByteArrayInputStreamCache. Exchange[ID-65cca645-1ba9-45ff-6b81-0629-1701160349653-423-1]

      Any ideas why?  Everything I have seen seems to indicate it should work but I always get this error.  I get a similar error when using substring as well