Tuesday, 30 June 2020

SFTP connection setup using Public key from SAP CPI

Configure SAP CPI with SFTP using Public key based authentication:


Step 1: Host Key retrieval from SAP CPI - Connectivity

For SSH based communication, CPI tenant needs the host key of the sftp server, which has to be added to the known hosts file and deployed on the cpi tenant. The host key can either be downloaded from sftp server or has to be provided by the administrator of the sftp server.



You can download the host key with the SSH connection test with Connectivity Test option and the Copy Host Key and add to knownhost file.


Creating Public key:

For SSH  based communication using public key authentication towards the sftp server, a private key pair with the any alias like id_rsa or id_dsa is required in CPI tenant’s keystore. Create this key pair in CPI keystore for the connection to the sftp server and use the same alias in the sftp adapter configuration at private key alias.



As provided, configure the channel with the below parameters:




Download Public OpenSSH key and send to the target/source system for uploading it. Then do connection test, that will work.. 





Tuesday, 23 June 2020

SuccessFactor Mutiple query on WHERE on SOAP

Query: SELECT person, employment_information, job_information FROM CompoundEmployee WHERE person_id_external IN ('94172064T','109996354T')



Tuesday, 26 May 2020

Replace double quotes for CSV files validation issue in SAP CPI

Some tools give a validation error on single double quote like:

123,Bricks measurement 24"/60cm,Erode,TN

where the double quotes cause an issue here.

So  in message mapping, we removed the single double quoted to two double quotes can escape the character.

Groovy Script:

import com.sap.it.api.mapping.*;

def String customFunc(String arg1){

def str2 = arg1.replaceAll("\"","\"\"")

return str2

}
Output:
123,Bricks measurement 24""/60cm,Erode,TN



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

}



Monday, 2 March 2020

Groovy script for DateTime formatting ODATA filter





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

import java.util.HashMap;

import java.util.TimeZone


def Message processData(Message message) {

//Body

def body = message.getBody();

//Properties

map = message.getProperties();

value = map.get("LastSuccessfulRun886PRD");

def curDateTime1 = "";

def tz = TimeZone.getTimeZone("Europe/Berlin")

def ts = new Date()

curDateTime1 = (ts.format("yyyy-MM-dd'T'HH:mm:ss", timezone=tz))

def datequery = "(CCSRQ_DOC_CREATED_DATE_TIME ge"+"'"+value+" CET"+"'"+" and CCSRQ_DOC_CREATED_DATE_TIME le"+"'"+curDateTime1+" CET"+"'"+")";

message.setHeader("datequery",datequery);

message.setProperty("CurrentDate",curDateTime1);

return message;

}