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