0

In spring integration aws application, files are routed from source folder to target S3 bucket using s3-outbound-gateway. Would like to encode the file UTF-8/16 using file-to-string-transformer and upload in target bucket. But the output file placed in target bucket is not encoding and the application does not throw error also.

Is there any thing am missing here and any other way to achieve this?

 <file:file-to-string-transformer input-channel="fileswithoutencoding" output-channel="filesOutS3Transformer" charset="UTF-8"/>
      <!-- added this line -->
<integration:transformer input-channel="filesOutS3Transformer" output-channel="filesS3GateWay" expression="payload.bytes" />
    <int-aws:s3-outbound-gateway id="s3File"
            request-channel="filesS3GateWay"
            reply-channel="filesS3ChainChannel"
            transfer-manager="transferManager"
            bucket-expression = "headers.TARGET_PATH"
            key-expression="headers.file_name"
            command="UPLOAD">
            <int-aws:request-handler-advice-chain>
                <ref bean="retryAdvice" />
            </int-aws:request-handler-advice-chain>
        </int-aws:s3-outbound-gateway>

routing to Local File : File is encoded to UTF-8 format only using file to string transformer though the charset is 8/16/32.

<integration:chain id="filesOutChain" input-channel="filesOut">
    <integration:transformer expression="headers.FILE"/>
    <file:file-to-string-transformer charset="UTF-16"/>
<!-- though bytes conversion is not required,just added for testing purpose -->
    <integration:transformer expression="payload.bytes"/>
        <file:outbound-gateway id="fileMover" 
            auto-create-directory="true"
            directory-expression="headers.TARGET_PATH"
            mode="REPLACE">
            <file:request-handler-advice-chain>
                <ref bean="retryAdvice" />
            </file:request-handler-advice-chain>
        </file:outbound-gateway>    
        <integration:gateway request-channel="filesOutChainChannel" error-channel="errorChannel"/>
    </integration:chain>
Jessie
  • 963
  • 5
  • 16
  • 26
  • Sorry, you are missing something in your config: the `S3MessageHandler` doesn't support `String` payload: `The only supported payloads for the upload request are java.io.File, java.io.InputStream, byte[] and PutObjectRequest.` – Artem Bilan Sep 17 '18 at 16:00
  • can i try, expression="payload.bytes" in transformer. Have edited the code above. – Jessie Sep 21 '18 at 15:08
  • Yes. That's OK. And what is the result of this configuration, please? Do you have some error? Can you share that with us? Thanks – Artem Bilan Sep 21 '18 at 15:11
  • it doesnot throw any error and file is placed in target bucket. But the file is not encoded (UTF-8) as expected. Charset of the file placed in S3 is charset=iso-8859-1 but expected charset = utf-8. – Jessie Sep 24 '18 at 15:22
  • Sounds like an AWS client concern. Or AWS S3 service already... Can you confirm that it is not a UTF-8 when just save those bytes to the local file? – Artem Bilan Sep 24 '18 at 15:35
  • just tried the same using file:outbound-gateway (code edited above), for this File is encoded to UTF-8 format only using file to string transformer though the charset is 8/16/32. Can you suggest any other way to do utf encoding before placing file in S3 bucket? – Jessie Sep 25 '18 at 12:33
  • s3-outbound-channel-adapter has attribute charset in aws 1.0 schema... but not available in latest schema 2.0. https://docs.spring.io/autorepo/schema/spring-integration-aws/0.5.0.RELEASE/integration/aws/spring-integration-aws-1.0.xsd – Jessie Sep 25 '18 at 12:41

0 Answers0