diff --git a/src/main/java/org/springframework/integration/aws/support/S3Session.java b/src/main/java/org/springframework/integration/aws/support/S3Session.java index d05a8a5..7477991 100644 --- a/src/main/java/org/springframework/integration/aws/support/S3Session.java +++ b/src/main/java/org/springframework/integration/aws/support/S3Session.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,6 +28,7 @@ import org.springframework.cloud.aws.core.env.ResourceIdResolver; import org.springframework.integration.file.remote.session.Session; import org.springframework.util.Assert; import org.springframework.util.StreamUtils; +import org.springframework.util.StringUtils; import com.amazonaws.services.s3.AmazonS3; import com.amazonaws.services.s3.model.AmazonS3Exception; @@ -44,6 +45,7 @@ import com.amazonaws.services.s3.model.S3ObjectSummary; * * @author Artem Bilan * @author Jim Krygowski + * @author Anwar Chirakkattil */ public class S3Session implements Session { @@ -228,6 +230,9 @@ public class S3Session implements Session { private String[] splitPathToBucketAndKey(String path, boolean requireKey) { Assert.hasText(path, "'path' must not be empty String."); + + path = StringUtils.trimLeadingCharacter(path, '/'); + String[] bucketKey = path.split("/", 2); if (requireKey) { @@ -236,7 +241,7 @@ public class S3Session implements Session { } else { Assert.state(bucketKey.length > 0 && bucketKey[0].length() >= 3, - "S3 bucket name must be at least 3 characters long."); + "S3 bucket name must be at least 3 characters long."); } bucketKey[0] = resolveBucket(bucketKey[0]); diff --git a/src/test/java/org/springframework/integration/aws/inbound/S3StreamingChannelAdapterTests.java b/src/test/java/org/springframework/integration/aws/inbound/S3StreamingChannelAdapterTests.java index 5c29a69..04f22be 100644 --- a/src/test/java/org/springframework/integration/aws/inbound/S3StreamingChannelAdapterTests.java +++ b/src/test/java/org/springframework/integration/aws/inbound/S3StreamingChannelAdapterTests.java @@ -141,7 +141,6 @@ public class S3StreamingChannelAdapterTests { S3ObjectSummary s3ObjectSummary = new S3ObjectSummary(); s3ObjectSummary.setBucketName(S3_BUCKET); s3ObjectSummary.setKey(s3Object.getKey()); - s3ObjectSummary.setLastModified(new Date(new File(s3Object.getKey()).lastModified())); objectSummaries.add(s3ObjectSummary); } @@ -163,7 +162,7 @@ public class S3StreamingChannelAdapterTests { S3RemoteFileTemplate s3FileTemplate = new S3RemoteFileTemplate(s3SessionFactory); S3StreamingMessageSource s3MessageSource = new S3StreamingMessageSource(s3FileTemplate, Comparator.comparing(FileInfo::getFilename)); - s3MessageSource.setRemoteDirectory(S3_BUCKET); + s3MessageSource.setRemoteDirectory("/" + S3_BUCKET); s3MessageSource.setFilter(new S3PersistentAcceptOnceFileListFilter(new SimpleMetadataStore(), "streaming")); return s3MessageSource;