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 87a8ad58..32d72e19 100644 --- a/src/main/java/org/springframework/integration/aws/support/S3Session.java +++ b/src/main/java/org/springframework/integration/aws/support/S3Session.java @@ -82,8 +82,11 @@ public S3Object[] list(String path) { List objectSummaries = new ArrayList<>(); do { objectListing = this.amazonS3.listObjects(listObjectsRequest.build()); - objectSummaries.addAll(objectListing.contents()); - listObjectsRequest.marker(objectListing.nextMarker()); + List contents = objectListing.contents(); + objectSummaries.addAll(contents); + if (objectListing.isTruncated()) { + listObjectsRequest.marker(contents.get(contents.size() - 1).key()); + } } while (objectListing.isTruncated()); @@ -108,10 +111,13 @@ public String[] listNames(String path) { List names = new ArrayList<>(); do { objectListing = this.amazonS3.listObjects(listObjectsRequest.build()); - for (S3Object objectSummary : objectListing.contents()) { + List contents = objectListing.contents(); + for (S3Object objectSummary : contents) { names.add(objectSummary.key()); } - listObjectsRequest.marker(objectListing.nextMarker()); + if (objectListing.isTruncated()) { + listObjectsRequest.marker(contents.get(contents.size() - 1).key()); + } } while (objectListing.isTruncated());