Friday, 24 July 2020

Connect to Azure File storage using script from SAP CPI

There is no standard way to connect to Azure file storage and does not have a adapter aswell in SAP CPI. 
Advantco Azure Adapter used to connect Azure storage but that is not added in CPI.

So would need to connect externally using script from SAP CPI.


Script:

import com.sap.gateway.ip.core.customdev.util.Message
import java.io.*
import com.microsoft.azure.storage.*;
import com.microsoft.azure.storage.file.*;
import com.microsoft.azure.storage.common.*;

def Message processData(Message message) {
def body = message.getBody(java.lang.String) as String

String accountName = "myaccountstorage"
String accountKey = "Key"
String storageConnectionString = "DefaultEndpointsProtocol=https;" + "AccountName=" + accountName+ ";" + "AccountKey=" + accountKey;


CloudStorageAccount storageAccount = CloudStorageAccount.parse(storageConnectionString)
CloudFileClient fileClient = storageAccount.createCloudFileClient();


CloudFileShare share = fileClient.getShareReference("fsmshare");


String fileName = "filename1.jpg"
String fileContent = body
byte[] fileBytes = fileContent.getBytes()


CloudFileDirectory rootDir = share.getRootDirectoryReference();

CloudFileDirectory sampleDir = rootDir.getDirectoryReference("attachments_inbound");



CloudFile cloudFile = sampleDir.getFileReference(fileName); cloudFile.uploadFromByteArray(fileBytes, 0, fileBytes.length)


cloudFile.getProperties().setContentType("image/jpeg")
cloudFile.uploadProperties()


message.setBody("OK")


return message;
}






Thursday, 23 July 2020

Script error - unable to resolve class in sap cpi/scpi

If you are using eclipse then have a option to add the external jar libraries and import the class and solve this issue but if there is an error in WEB IDE which we use commonly now. Here is the solution for it.


Error:

com.sap.it.rt.adapter.http.api.exception.HttpResponseException: An internal server error occured: startup failed: script1__Script.groovy: 14: unable to resolve class CloudStorageAccount @ line 14, column 25.

Go to your integration flow and select the resource at the bottom and add -> archives, then select the jar file which is available in the local drive.




Now the issue will be resolved!!!

Hope this helps.


Monday, 13 July 2020

CPI IP range whitelisting


Region         
Key      
Host                                 

           IP Ranges    
Europe (Rot)
neo-eu1
hana.ondemand.com
eu1.hana.ondemand.com
Link
155.56.128.0/17



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;
}