Thursday, 16 April 2020

Delay processing of iflow on every message in SAP CPI

Processing delay of 8s for every messages sent to the end system.

1. Replace xml node
2. delay code of 8 secs

Groovy Script

import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;
import java.lang.*

def Message processData(Message message) {

def body = message.getBody(java.lang.String) as String;

body = body.replaceAll("\\<\\?xml(.+?)\\?\\>", "").trim(); //Replace xml node

message.setBody(body);


sleep(8000)    // wait for 8 secs

return message;
}



Monday, 6 April 2020

Remove certain string from the query/url passing to target using groovy script in SAP CPI

Read the query parameters from the source system and remove the $filter= from it as shown below:


CamelHttpQuery from source :$filter=ContactID%3d%271925053%27%2cContactOrigin%3d%27SAP_C4C_BUPA%27

URL should be as send to target system: https://myXXX-api.s4hana.ondemand.com/sap/opu/odata/sap/API_MKT_CONTACT_SRV;v=0003/ContactOriginData(ContactOrigin='SAP_XXX',ContactID='190000')

Query in the channel:

https://myXXX-api.s4hana.ondemand.com/sap/opu/odata/sap/API_MKT_CONTACT_SRV;v=0003/ContactOriginData(${header.Query})

Script:

import com.sap.gateway.ip.core.customdev.util.Message;

import java.util.HashMap;

def Message processData(Message message) {

def map = message.getHeaders();

def value = map.get("CamelHttpQuery");

value = value.drop(8);

message.setHeader("Query", value);

return message;

}



Standard Character encoding change in SAP CPI

Standard Character encoding change like UTF-8 or different ISO standard formats.

Groovy script:

import com.sap.gateway.ip.core.customdev.util.Message

import java.nio.charset.StandardCharsets

def Message processData(Message message) {

def body = message.getBody(java.lang.String)

message.setBody(body.getBytes(StandardCharsets.ISO_8859_1))

return message

}