From e7be7d0e930fcf29c1e521588ecce2ae5e31e213 Mon Sep 17 00:00:00 2001 From: Rogerio Lino Date: Tue, 14 Nov 2023 12:12:10 -0300 Subject: [PATCH] fix: Fixing new AWS SDK v2 pagination --- .../integration/aws/support/S3Session.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) 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());