Groovy Scripts and Custom Mapping Functions in SAP Cloud Integration
Course quiz
Groovy Scripts and Custom Mapping Functions in SAP Cloud Integration
Keep this: job aid
CPI Groovy cheat sheet
- Skeleton: import com.sap.gateway.ip.core.customdev.util.Message; def Message processData(Message message) { … return message }.
- Body: getBody(String | java.io.Reader | java.io.InputStream), setBody; size: getBodySize().
- Properties stay in the flow; headers go to the receiver (keep them small).
- Mapping function: def String f(String a, MappingContext context) → context.getHeader / getProperty / setHeader / setProperty.
- Context function: def void f(String[] a, Output output, MappingContext context) → output.addValue / addContextChange / addSuppress; runs once per context.
- Script 1.1 = Groovy 2.4.21; 2.0 = Groovy 4.0.29 → import groovy.xml.XmlSlurper; fix the Upgrade Readiness Check.
- Parse from a Reader; StringBuilder; no binding variables; compact output; disable XXE.
- Logging: SAP_ApplicationID or addCustomHeaderProperty; setStringProperty shows at Debug/Trace only; attachments switched and masked.
- Script collection: deploy, Add References, Assign → Reference Resources; script version must match step version.
- Test: script.api / script.v2.api from Maven Central, stub Message, GroovyShell + Binding; simulate; contract-test the endpoint.