More Fun with SAP Cloud Integration and Camel’s Simple Expressions

Hello fellow Integrators,

there is a great article from Morten Wittrock about what’s possible in Camel’s Simple expression language. I was wondering if it would be possible to access maps and lists via simple expressions. That might come in pretty handy. If you want to read more blog posts and news about SAP Cloud Integration, follow the Kangoolution LinkedIn page.

But let’s get our hands dirty and create a simple IFlow to try it.

It took some attempts but the results seem pretty promising. First we create a map and a list in Groovy:

import com.sap.gateway.ip.core.customdev.util.Message;
def Message processData(Message message) {
    
    def animalsList = ["dog","cat","horse", "cow"]
    def countryMap = ["DE":"Germany","AT":"Austria", "IN":"India"]

    message.setProperty("animalsList", animalsList);
    message.setProperty("countryMap", countryMap);
    
    return message;
}

Now we add some expressions to the Content Modifier:

list
${property.animalsList}

get the size of a list
${property.animalsList.size}

get element
${property.animalsList[2]}

get last element
${property.animalsList[last]}

get element before last element
${property.animalsList[last-1]}

get last element in upper case
${property.animalsList[last].toUpperCase()}

maps
${property.countryMap}

get map element
${property.countryMap?.[IN]}

get map size
${property.countryMap.size()}

check if map contains element
${property.countryMap.containsKey(US)}

Deploy and check results with CPI Helper Plugin for Chrome and Edge:

I will definitely use this in future developments.

Unfortunately, there seems to be no way to pop elements from lists for example. In case you find a solution or if you have other interesting camel expressions, please write a comment.

BR

Dominic Beckbauer

Ein Gedanke zu „More Fun with SAP Cloud Integration and Camel’s Simple Expressions

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert