Groovy script to add character at end of eachline in SAP CPI

I am new to groovy scripting world.
I am trying to add “!##!” characters at end of each line in a pipe seperated payload. Can you please help in getting desired output.

Input:

abc|123|test
111111|qqqq|dddd|ddd

Desired Output File:

abc|123|test!##!
111111|qqqq|dddd|ddd!##!

Tried to achieve using code in CPI

import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;
def Message processData(Message message) {
   //Body 
   def body = message.getBody(java.io.Reader);
   array =[]
   body.eachLine{ line ->
      line = line +"!##!"
      array.add(line)
      
   }
   message.setBody(array.toString());
   return message;
}

Please find Groovy IDE link

Leave a Comment