/*
Script to download file to Azure Blob folder using parameters provided
*/
import com.sap.gateway.ip.core.customdev.util.Message
import java.util.HashMap
import com.microsoft.azure.storage.*
import com.microsoft.azure.storage.blob.*
import com.sap.it.api.ITApiFactory;
import com.sap.it.api.securestore.SecureStoreService;
import com.sap.it.api.securestore.UserCredential;
import com.sap.it.api.securestore.exception.SecureStoreException;
def Message processData(Message message) {
def body = message.getBody(java.lang.String) as String
map = message.getProperties()
String accountKey = null;
String accountName=map.get("AzureAccountName")
String AzureAccountKey = map.get("AzureAccountKey")
String containerRef =map.get("ContainerRef")
String fileName = map.get("Filename")
def securestoreApi = ITApiFactory.getService(com.sap.it.api.securestore.SecureStoreService.class, null)
try{
accountKey = String.valueOf(securestoreApi.getUserCredential(AzureAccountKey).getPassword())
} catch(Exception e){
throw new SecureStoreException("Secure Parameter not available")
}
String storageConnectionString = "DefaultEndpointsProtocol=https;" + "AccountName=" + accountName+ ";" + "AccountKey=" + accountKey
try{
CloudStorageAccount account = CloudStorageAccount.parse(storageConnectionString)
CloudBlobClient serviceClient = account.createCloudBlobClient()
CloudBlobContainer container = serviceClient.getContainerReference(containerRef)
CloudBlockBlob blob = container.getBlockBlobReference(fileName)
message.setBody(blob.downloadText())
}
catch(Exception e){
throw new Exception("file can't be downloaded")
}
return message;
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
13 | |
10 | |
7 | |
7 | |
6 | |
5 | |
5 | |
5 | |
4 | |
4 |