GrooveBox

Groovy 2.4 vs Groovy 4 in SAP Integration Suite: what changes for your scripts

SAP Integration Suite scripts (formerly SAP CPI) have long run on Groovy 2.4 and Java 8. The newer runtime is Groovy 4 on Java 17, with the Script API v2. Most scripts keep working, but a few classic idioms break: moved packages, removed JDK classes and Date helpers. This guide lists the changes that matter for SAP Integration Suite scripts and how to test a script on both runtimes side by side.

At a glance

V1 runtimeV2 runtime
Groovy2.44.0
Java817
Message classcom.sap.gateway.ip.core.customdev.util.Messagecom.sap.it.script.v2.api.Message (Script API v2), plus Exchange
XmlSlurper / XmlParsergroovy.utilgroovy.xml

1. XmlSlurper and XmlParser moved to groovy.xml

In Groovy 3 the XML classes of the groovy.util package were deprecated in favour of groovy.xml, and Groovy 4 removed the old ones. On Groovy 2.4 XmlSlurper needs no import; on Groovy 4 the same code fails with unable to resolve class XmlSlurper.

// Groovy 2.4
def order = new XmlSlurper().parseText(body)

// Groovy 4
import groovy.xml.XmlSlurper
def order = new XmlSlurper().parseText(body)

The same applies to XmlParser and to GPathResult, which moved from groovy.util.slurpersupport to groovy.xml.slurpersupport. groovy.xml.XmlUtil, groovy.xml.MarkupBuilder and groovy.json.JsonSlurper / JsonOutput keep their packages.

2. Java 8 classes that no longer exist in Java 17

Java 8 idiomReplacement on Java 17
sun.misc.BASE64Encoder / BASE64Decoder (removed in Java 9)java.util.Base64.getEncoder(), or Groovy's bytes.encodeBase64() and text.decodeBase64()
javax.xml.bind.DatatypeConverter (JAXB, removed from the JDK in Java 11)java.util.Base64, java.util.HexFormat (Java 17) or Groovy's encodeHex()
Reflection on JDK internalsBlocked by default since Java 16 (strong encapsulation): use public APIs
// works on both runtimes
def encoded = 'user:password'.bytes.encodeBase64().toString()
def decoded = new String(encoded.decodeBase64(), 'UTF-8')

3. Date helpers: prefer java.time

Methods such as new Date().format('yyyy-MM-dd') and Date.parse(...) are Groovy extension methods. Since Groovy 2.5 they live in the separate groovy-dateutil module, so they are only available if that module is on the classpath. java.time works everywhere and handles time zones explicitly:

import java.time.ZonedDateTime
import java.time.ZoneId
import java.time.format.DateTimeFormatter

def now = ZonedDateTime.now(ZoneId.of('Europe/Rome'))
message.setProperty('Timestamp', now.format(DateTimeFormatter.ISO_OFFSET_DATE_TIME))

4. The Message class

With the Script API v2 the script imports com.sap.it.script.v2.api.Message instead of com.sap.gateway.ip.core.customdev.util.Message. Everyday methods such as getBody, setBody, getHeader, setHeader, getProperty and setProperty are used the same way; messageLogFactory and ITApiFactory lookups are unchanged.

import com.sap.it.script.v2.api.Message
import groovy.xml.XmlSlurper

def Message processData(Message message) {
    def order = new XmlSlurper().parseText(message.getBody(String))
    message.setProperty('OrderId', order.Id.text())
    return message
}

5. New syntax (Groovy 3 and 4 only)

The Groovy 4 parser accepts Java-style lambdas, !in, !instanceof, the identity operator === and the elvis assignment ?=. They are handy, but a script that uses them no longer compiles on Groovy 2.4: keep them out of scripts that must run on both runtimes.

How to test a script on both runtimes

  1. Open the GrooveBox playground and paste the script with its test input.
  2. Run it on V1 (Groovy 2.4, Java 8), then switch to V2 (Groovy 4, Java 17) and run it again: the inputs are kept.
  3. Compile errors such as unable to resolve class point to moved classes; compare output body, headers and properties between the two runs.

More on testing: How to test SAP Integration Suite Groovy scripts without deploying an iFlow.

Last updated: