I have created an executable jar and trying to call using Javacallout policy. This jar will read all the properties (as constructor parameter in the Execute implemented class) passed from policy and call the azure blob service classes from Azure SDK. Due to some Apigee bundle size limit, I am using following maven dependency(not updated version) of Azure. I am getting following error as response in callout policy, no exception variables (set in messageContext in exception block) available in Apigee trace as well. #Excpetation : SIGNED_TOKEN_KEY token in the callout response.
com.azure
azure-storage-file-datalake
12.3.0
This is working fine as a standalone jar as well as calling the execute(…) method from Junit test class. I am sharing the error details as well as code snippet. Appreciate for your help in advance.
Javacallout response (2 types error) :
access denied (“java.lang.RuntimePermission” “getenv.HTTP_PROXY”)
Failed to execute JavaCallout. null
ErrorPoint
PROXY_REQ_FLOW
com.apigee.kernel.exceptions.spi.UncheckedException
2)
Failed to execute JavaCallout. Could not initialize class com.azure.core.util.Configuration
ErrorPoint
PROXY_REQ_FLOW
com.apigee.kernel.exceptions.spi.UncheckedException
Could not initialize class com.azure.core.util.Configuration
Java code :
public AzureStorageCallout(Map <String,String> properties) {
super(properties); //#1 - called the parent class constructor and set the properties declared
}
public ExecutionResult execute(MessageContext messageContext, ExecutionContext executionContext) {
try {
String connString = getSimpleRequiredProperty(AZURE_CONNECTION_STRING_KEY, messageContext); // method to read the properties values (assigned in #1) from parent class
String containerName = getSimpleRequiredProperty(CONTAINER_NAME_KEY, messageContext);
String blobName = getSimpleRequiredProperty(BLOB_NAME_KEY, messageContext);
String directoryName = getSimpleOptionalProperty(DIRECTORY_KEY , messageContext);
String verb = getSimpleRequiredProperty(VERB_NAME_KEY, messageContext);
String expiry = getSimpleRequiredProperty(EXPIRY_TIME_KEY, messageContext);
String ctype = getSimpleOptionalProperty(C_TYPE_KEY, messageContext);
BlobServiceClient client = new BlobServiceClientBuilder().connectionString(connString).buildClient();
BlobClient blobClient = client.getBlobContainerClient(containerName)
.getBlobClient(getBlobNameWithDirectory(directoryName,blobName));
BlobSasPermission blobSasPermission = new BlobSasPermission();
if(verb.equals(“GET”)) {
blobSasPermission.setReadPermission(true);
}
if(verb.equals(“PUT”)) {
blobSasPermission.setReadPermission(true).setWritePermission(true);
}
OffsetDateTime currentTime = OffsetDateTime.now();
OffsetDateTime expiryTime = getExpiry(messageContext, currentTime);
BlobServiceSasSignatureValues values = new BlobServiceSasSignatureValues(expiryTime, blobSasPermission)
.setStartTime(OffsetDateTime.now()).setContentDisposition(blobName);
String sasToken = blobClient.generateSas(values);
messageContext.setVariable(SIGNED_TOKEN_KEY, sasToken);
return ExecutionResult.SUCCESS;
} catch (Exception ex) {
ExecutionResult executionResult = new ExecutionResult(false, Action.ABORT);
//–Returns custom error message and header
executionResult.setErrorResponse(ex.getMessage());
executionResult.addErrorResponseHeader(“ExceptionClass”, ex.getClass().getName());
//setExceptionVariables(ex, messageContext);
//–Set flow variables – may be useful for debugging.
messageContext.setVariable(“JAVA_ERROR”, ex.getMessage());
messageContext.setVariable(“JAVA_STACKTRACE”, exceptionStackTrace(ex));
return executionResult;//return ExecutionResult.ABORT;
}
}
}