This post show Groovy scripting to read and log all header, properties in message log, and payload body as attachment, then can be viewed in Monitoring Message Processing Log, for troubleshooting and debug purpose.
Reuse previous iFlow, the completed iFlow is like below. Added 2 steps before and after message mapping step, name it log01 and log02 respectively.

Create script called logger.groovy:

import java.util.HashMap;
import java.text.SimpleDateFormat;
import java.util.Date;
def Message log01(Message message) {processData("log01_before_mapping", message);}
def Message log02(Message message) {processData("log02_after_mapping", message);}
def Message log03(Message message) {processData("log03", message);}
def Message log04(Message message) {processData("log04", message);}
def Message log05(Message message) {processData("log05", message);}
def Message log06(Message message) {processData("log06", message);}
def Message log07(Message message) {processData("log07", message);}
def Message log08(Message message) {processData("log08", message);}
def Message log09(Message message) {processData("log09", message);}
def Message log10(Message message) {processData("log10", message);}
def Message processData(String prefix, Message message) {
	def headers = message.getHeaders();
	def body = message.getBody(java.lang.String) as String;
	def messageLog = messageLogFactory.getMessageLog(message);
	for (header in headers) {
	   messageLog.setStringProperty("header." + header.getKey().toString(), header.getValue().toString())
	for (property in properties) {
	   messageLog.setStringProperty("property." + property.getKey().toString(), property.getValue().toString())
    if(messageLog != null){
        messageLog.addAttachmentAsString(prefix, body, "text/plain");
    return message;

At log01 and log02 steps, put value in Name and Script Function as well:

After test run, will able to see 2 attachments:

All header and properties is showing at “Log” tab:

Attachment are showing and 2nd and 3rd tabs:

Keep on exploring 🙂

Debug/Logging Headers, Properties, Payload Body using Groovy Scripts
Tagged on:             

2 thoughts on “Debug/Logging Headers, Properties, Payload Body using Groovy Scripts

  • April 12, 2019 at 5:02 am

    Using the above steps, the attachment is generated in an iFlow, however, when we try to access it gives the below message

    “Request for log attachments failed with error: Invalid server response: Couldn’t parse message.
    Status Code: 500
    Message: Internal Server Errorwhile trying to invoke the method[]) of a null object loaded from local variable ‘is'”

    any thoughts on why it throws the above error?

    • January 13, 2020 at 1:11 pm

      Hi Virendra,

      Even we are facing the same issues. Were you able to solve it. Your response will be of great help.



Leave a Reply

Your email address will not be published. Required fields are marked *