0

I want to use object-acl-expression in s3-outbound-gateway as mentioned below configuration but, its throwing "Illegal state Exception" due to null value in else section.I dont want to set any other access controll in else section. Could you please suggest some solution on this ?.

<int-aws:s3-outbound-gateway
        id="id" request-channel="requestChannelId"
        reply-channel="replayChannelId"
        transfer-manager="tm"
        bucket-expression="bucketName" 
        object-acl-expression="headers.S3_FULL_ACCESS_OWNER_ENABLED == 'Y' ? T(com.amazonaws.services.s3.model.CannedAccessControlList).BucketOwnerFullControl : null
        key-expression="headers.file_name" 
        command="UPLOAD">
    </int-aws:s3-outbound-gateway>

expected : object-acl-expression should be as default provided in the bucket Actual : Throwing "Illegal state exception"

Las
  • 37
  • 4

1 Answers1

0

This is not possible with the current implementation of the object-acl-expression. Just because it doesn't support null for evaluation result:

Object acl = this.objectAclExpression.getValue(this.evaluationContext, requestMessage);
Assert.state(acl instanceof AccessControlList || acl instanceof CannedAccessControlList,
                    "The 'objectAclExpression' ["
                            + this.objectAclExpression.getExpressionString()
                            + "] must evaluate to com.amazonaws.services.s3.model.AccessControlList " +
                            "or must evaluate to com.amazonaws.services.s3.model.CannedAccessControlList. " +
                            "Gotten: [" + acl + "]");

We can fix this, of course, and you feel free to raise an issue on the matter: https://github.com/spring-projects/spring-integration-aws/issues

Meanwhile as a workaround I see a solution based on the S3ProgressListener, similar to what we do internally:

progressListener = new S3ProgressListener() {

                @Override
                public void onPersistableTransfer(PersistableTransfer persistableTransfer) {

                }

                @Override
                public void progressChanged(ProgressEvent progressEvent) {
                    if (ProgressEventType.TRANSFER_COMPLETED_EVENT.equals(progressEvent.getEventType())) {
                        S3MessageHandler.this.transferManager.getAmazonS3Client().setObjectAcl(theAclRequest);
                    }
                }

            };

Only the problem here that you don't have access to the message in that progressChanged context... I think this is something we have to fix as well.

Maybe you can just live for now with the CannedAccessControlList.AuthenticatedRead instead of null ?

Artem Bilan
  • 113,505
  • 11
  • 91
  • 118
  • Thank you Artem. I will go for the solution you suggested for time being and i will raise a ticket for the same as well. – Las Jan 15 '19 at 04:24
  • 1
    I have raised a issue on the same https://github.com/spring-projects/spring-integration-aws/issues/106 – Las Jan 15 '19 at 04:51
  • Good. I’ll fix that tomorrow. – Artem Bilan Jan 15 '19 at 04:52