Skip to Content

Background

As discussed in my previous blog, HCI – Payload Logging using Groovy Scripts logging of payloads should be used prudently. Typically you would like the logging to be disabled and have options to enable this only on a need basis.

If you are from a PI background, you would be well aware of parameters like TRACE_LEVEL, LOGGING_SYNC and Integrated Configuration Logging Options that enable you to turn on / off logging & staging when required. So how can this be done in HCI using the Groovy scripts we described in the previous blogs?

Externalized Parameters in HCI

Some background first – HCI enables you to define parameters that can be controlled externally in your Integration Flow. Typical examples of these are SOAP/HTTP URLs, FTP Server Host,etc which will typically vary in each environment. There is already content on Externalized Parameters for HCI on SCN and would recommend you read that or the corresponding documentation from SAP – Externalizing Parameters of Integration Flow

To be able to define Logging Dynamically we will be using a custom Externalized Parameters, so you can enable and disable logging without having to make changes to your Integration Flow or the Groovy script.

Integration Flow Changes

We will continue to use the sample Integration Flow described in my previous blog with an additional Content Modifier Step and some changes in the Groovy script as described below.

/wp-content/uploads/2016/04/19_933828.png

Step Description
Delta Changes
Content Modifier
  • The  New Content Modifier step is used to read the External Parameter into a local property.
  • Name = logger ( Message Property to be used in the Groovy Script )
  • Type = External Parameter
  • Data Type = java.lang.String
  • Value = externalParamLogger ( Name of the External Parameter whose value will be set externally )

/wp-content/uploads/2016/04/10_933906.png

Groovy Script Change
  • Read Message Properties
  • Read the value of property logger as set in the previous content modifier step
  • If Logger is set to 1, then log the payload else, do not perform any logging.

import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;
def Message processData(Message message) {
    def body = message.getBody(java.lang.String) as String;
    def messageLog = messageLogFactory.getMessageLog(message);
    def propertyMap = message.getProperties()
    //Read logger from the Message Properties
    String logger = propertyMap.get("logger");
    if(logger.equals("1")){
        if(messageLog != null){
            messageLog.setStringProperty("Logging#1", "Printing Payload As Attachment")
            messageLog.addAttachmentAsString("ResponsePayload:", body, "text/plain");
         }
    }
  return message;
}


Setting of Externalized Parameters

Once the Content Modifier step is defined, the Externalized Parameters tab should contain the Parameter with the name as defined in our Content Modifier step. In this case: externalParamLogger. Set the default value of the Parameter as 0 (Zero). Save and Deploy your Integration Flow.


/wp-content/uploads/2016/04/11_933881.png

Test your flow with External Parameter Value set to 0

Trigger your Integration flow with the External Parameter Value set a 0. The Integration Flow executes and the Groovy Script does not log the payload as the value is set to 0. As seen in the image below no attachment is available.

/wp-content/uploads/2016/04/12_933882.png

Test your flow with External Parameter Value set to 1

To update your external parameters, navigate to Window –> Show View –> Other. In your Show View dialog box, navigate to Other –> Configurations

/wp-content/uploads/2016/04/13_933883.png

In the Configurations Pane that opens, navigate to your project and double click on the same. In my case the name of my project is – Prj_PayloadAsAttachment
/wp-content/uploads/2016/04/14_933899.png

Go to Externalized Parameters tab and update the value of externalParamLogger as 1 and click on Save Parameters

/wp-content/uploads/2016/04/15_933900.png

Right Click on your project in Configurations –> Deploy Integration Content. Your Integration Flow is now updated to have the Logging Enabled!

/wp-content/uploads/2016/04/16_933905.png

Re-trigger the Interface and you should see the logs with the attachment as the Logger is now set to Value 1.

/wp-content/uploads/2016/04/17_933911.png


Final Note

As seen in this blog, Externalized Parameters provide you with options to provide parameters to your Integration flow dynamically. This along with some smart Groovy Scripting enables you to dynamically control payload logging.


To report this post you need to login first.

5 Comments

You must be Logged on to comment or reply to a post.

  1. vijay kumar

    Hi Bhavesh,

    Good blog bhavesh,

    One doubt, as explained how to use the externalized parameters in SOAP for trigger or in SFTP. (Via  the SOAP UI )

    Thanks in advance,
    Vijay

    (0) 
    1. Bhavesh Kantilal Post author

      Hello Vijay,

      This help link is a good starting point on how to Externalize Parameters for the adapter’s in question. Externalizing Parameters
      Regards,
      Bhavesh

      (0) 
  2. Jay Malla

    Hi Bhavesh,

    We are not able to create an external parameter for the Content modifier exchange property as it is greyed out:

     

    We can set this up in Eclipse:

    When we deploy, the deployment is successful – but the content modifier still does not show this property.  Seems like a issue with SAP HCI.  Is there a work around to do this?  It seemed like this feature was not supported in the Web UI so it was recommended to create the external parameter through Eclipse but it’s not working.

    Thanks for your help in advance.

    Thanks,

    Jay

     

     

     

    (0) 
    1. Jay Malla

      I did the same steps as per your BLOG:

       

      Deployment shows successful – but when I open this up in Web UI – it still has the old constant that I had defined in the Web UI.  So somehow the issue is with the deployment it seems.

       

      Any ideas why this is not working?

      Thanks!

      Jay

       

       

       

       

      (0) 

Leave a Reply