Skip to content

Commit e144457

Browse files
Merge with upstream and resolve conflicts.
2 parents 5e3a5f7 + 50a9248 commit e144457

14 files changed

+464
-188
lines changed

.github/dependabot.yml

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "maven"
4+
directory: "/"
5+
schedule:
6+
interval: "weekly"
7+
- package-ecosystem: "github-actions"
8+
directory: "/"
9+
schedule:
10+
interval: "weekly"

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ For more information on using the amazon-sqs-java-extended-client-lib, see our g
2525
<dependency>
2626
<groupId>com.amazonaws</groupId>
2727
<artifactId>amazon-sqs-java-extended-client-lib</artifactId>
28-
<version>2.0.2</version>
28+
<version>2.0.4</version>
2929
<type>jar</type>
3030
</dependency>
3131
```
@@ -35,7 +35,7 @@ For more information on using the amazon-sqs-java-extended-client-lib, see our g
3535
<dependency>
3636
<groupId>com.amazonaws</groupId>
3737
<artifactId>amazon-sqs-java-extended-client-lib</artifactId>
38-
<version>1.2.2</version>
38+
<version>1.2.5</version>
3939
<type>jar</type>
4040
</dependency>
4141
```

pom.xml

+14-13
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
</developers>
3838

3939
<properties>
40-
<aws-java-sdk.version>2.14.19</aws-java-sdk.version>
40+
<aws-java-sdk.version>2.20.153</aws-java-sdk.version>
4141
</properties>
4242

4343
<dependencies>
@@ -66,15 +66,15 @@
6666
</dependency>
6767

6868
<dependency>
69-
<groupId>junit</groupId>
70-
<artifactId>junit</artifactId>
71-
<version>4.13.1</version>
69+
<groupId>org.junit.jupiter</groupId>
70+
<artifactId>junit-jupiter</artifactId>
71+
<version>5.10.0</version>
7272
<scope>test</scope>
7373
</dependency>
7474
<dependency>
7575
<groupId>org.mockito</groupId>
7676
<artifactId>mockito-core</artifactId>
77-
<version>3.12.4</version>
77+
<version>5.5.0</version>
7878
<scope>test</scope>
7979
</dependency>
8080
</dependencies>
@@ -84,7 +84,7 @@
8484
<plugin>
8585
<groupId>org.apache.maven.plugins</groupId>
8686
<artifactId>maven-compiler-plugin</artifactId>
87-
<version>3.2</version>
87+
<version>3.11.0</version>
8888
<configuration>
8989
<source>1.8</source>
9090
<target>1.8</target>
@@ -107,30 +107,31 @@
107107
</execution>
108108
</executions>
109109
</plugin>
110+
<plugin>
111+
<groupId>org.apache.maven.plugins</groupId>
112+
<artifactId>maven-surefire-plugin</artifactId>
113+
<version>3.1.2</version>
114+
</plugin>
110115
<plugin>
111116
<groupId>org.apache.maven.plugins</groupId>
112117
<artifactId>maven-javadoc-plugin</artifactId>
113-
<version>2.9.1</version>
118+
<version>3.6.0</version>
114119
<executions>
115120
<execution>
116121
<id>attach-javadocs</id>
117122
<goals>
118123
<goal>jar</goal>
119124
</goals>
120125
<configuration>
121-
<!--
122-
TODO-RS: Java 8 is more strict about some javadoc tags.
123-
We'll need to update quite a few to remove this workaround.
124-
-->
125-
<additionalparam>-Xdoclint:none</additionalparam>
126+
<doclint>none</doclint>
126127
</configuration>
127128
</execution>
128129
</executions>
129130
</plugin>
130131
<plugin>
131132
<groupId>org.sonatype.plugins</groupId>
132133
<artifactId>nexus-staging-maven-plugin</artifactId>
133-
<version>1.6.7</version>
134+
<version>1.6.13</version>
134135
<extensions>true</extensions>
135136
<configuration>
136137
<serverId>ossrh</serverId>

src/main/java/com/amazon/sqs/javamessaging/AmazonSQSExtendedAsyncClient.java

+10-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import java.util.List;
1515
import java.util.Map;
1616
import java.util.Optional;
17+
import java.util.UUID;
1718
import java.util.concurrent.CompletableFuture;
1819
import java.util.stream.Collectors;
1920
import org.apache.commons.logging.Log;
@@ -469,7 +470,7 @@ private CompletableFuture<SendMessageBatchRequestEntry> storeMessageInS3(SendMes
469470
clientConfiguration.usesLegacyReservedAttributeName()));
470471

471472
// Store the message content in S3.
472-
return payloadStore.storeOriginalPayload(messageContentStr)
473+
return storeOriginalPayload(messageContentStr)
473474
.thenApply(largeMessagePointer -> {
474475
batchEntryBuilder.messageBody(largeMessagePointer);
475476
return batchEntryBuilder.build();
@@ -496,6 +497,14 @@ private CompletableFuture<SendMessageRequest> storeMessageInS3(SendMessageReques
496497
});
497498
}
498499

500+
private CompletableFuture<String> storeOriginalPayload(String messageContentStr) {
501+
String s3KeyPrefix = clientConfiguration.getS3KeyPrefix();
502+
if (StringUtils.isBlank(s3KeyPrefix)) {
503+
return payloadStore.storeOriginalPayload(messageContentStr);
504+
}
505+
return payloadStore.storeOriginalPayload(messageContentStr, s3KeyPrefix + UUID.randomUUID());
506+
}
507+
499508
private static <T extends AwsRequest.Builder> T appendUserAgent(final T builder) {
500509
return AmazonSQSExtendedClientUtil.appendUserAgent(builder, USER_AGENT_NAME, USER_AGENT_VERSION);
501510
}

src/main/java/com/amazon/sqs/javamessaging/AmazonSQSExtendedClient.java

+20-2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
import java.util.List;
3030
import java.util.Map;
3131
import java.util.Optional;
32+
import java.util.UUID;
33+
3234
import org.apache.commons.logging.Log;
3335
import org.apache.commons.logging.LogFactory;
3436
import software.amazon.awssdk.awscore.AwsRequest;
@@ -851,7 +853,7 @@ private SendMessageBatchRequestEntry storeMessageInS3(SendMessageBatchRequestEnt
851853
clientConfiguration.usesLegacyReservedAttributeName()));
852854

853855
// Store the message content in S3.
854-
String largeMessagePointer = payloadStore.storeOriginalPayload(messageContentStr);
856+
String largeMessagePointer = storeOriginalPayload(messageContentStr);
855857
batchEntryBuilder.messageBody(largeMessagePointer);
856858

857859
return batchEntryBuilder.build();
@@ -871,13 +873,29 @@ private SendMessageRequest storeMessageInS3(SendMessageRequest sendMessageReques
871873
clientConfiguration.usesLegacyReservedAttributeName()));
872874

873875
// Store the message content in S3.
874-
String largeMessagePointer = payloadStore.storeOriginalPayload(messageContentStr);
876+
String largeMessagePointer = storeOriginalPayload(messageContentStr);
875877
sendMessageRequestBuilder.messageBody(largeMessagePointer);
876878

877879
return sendMessageRequestBuilder.build();
878880
}
879881

882+
private String storeOriginalPayload(String messageContentStr) {
883+
String s3KeyPrefix = clientConfiguration.getS3KeyPrefix();
884+
if (StringUtils.isBlank(s3KeyPrefix)) {
885+
return payloadStore.storeOriginalPayload(messageContentStr);
886+
}
887+
return payloadStore.storeOriginalPayload(messageContentStr, s3KeyPrefix + UUID.randomUUID());
888+
}
889+
890+
@SuppressWarnings("unchecked")
880891
private static <T extends AwsRequest.Builder> T appendUserAgent(final T builder) {
881892
return AmazonSQSExtendedClientUtil.appendUserAgent(builder, USER_AGENT_NAME, USER_AGENT_VERSION);
882893
}
894+
895+
@Override
896+
public void close() {
897+
super.close();
898+
this.clientConfiguration.getS3Client().close();
899+
}
900+
883901
}

src/main/java/com/amazon/sqs/javamessaging/AmazonSQSExtendedClientUtil.java

+32
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import software.amazon.awssdk.services.sqs.model.MessageAttributeValue;
1616
import software.amazon.awssdk.services.sqs.model.SendMessageBatchRequestEntry;
1717
import software.amazon.awssdk.services.sqs.model.SendMessageRequest;
18+
import software.amazon.awssdk.utils.StringUtils;
1819
import software.amazon.payloadoffloading.PayloadS3Pointer;
1920
import software.amazon.payloadoffloading.Util;
2021

@@ -165,4 +166,35 @@ private static int getMsgAttributesSize(Map<String, MessageAttributeValue> msgAt
165166
}
166167
return totalMsgAttributesSize;
167168
}
169+
170+
public static String trimAndValidateS3KeyPrefix(String s3KeyPrefix) {
171+
String trimmedPrefix = StringUtils.trimToEmpty(s3KeyPrefix);
172+
173+
if (trimmedPrefix.length() > SQSExtendedClientConstants.MAX_S3_KEY_PREFIX_LENGTH) {
174+
String errorMessage = "The S3 key prefix length must not be greater than "
175+
+ SQSExtendedClientConstants.MAX_S3_KEY_PREFIX_LENGTH;
176+
LOG.error(errorMessage);
177+
throw SdkClientException.create(errorMessage);
178+
}
179+
180+
if (trimmedPrefix.startsWith(".") || trimmedPrefix.startsWith("/")) {
181+
String errorMessage = "The S3 key prefix must not starts with '.' or '/'";
182+
LOG.error(errorMessage);
183+
throw SdkClientException.create(errorMessage);
184+
}
185+
186+
if (trimmedPrefix.contains("..")) {
187+
String errorMessage = "The S3 key prefix must not contains the string '..'";
188+
LOG.error(errorMessage);
189+
throw SdkClientException.create(errorMessage);
190+
}
191+
192+
if (SQSExtendedClientConstants.INVALID_S3_PREFIX_KEY_CHARACTERS_PATTERN.matcher(trimmedPrefix).find()) {
193+
String errorMessage = "The S3 key prefix contain invalid characters. The allowed characters are: letters, digits, '/', '_', '-', and '.'";
194+
LOG.error(errorMessage);
195+
throw SdkClientException.create(errorMessage);
196+
}
197+
198+
return trimmedPrefix;
199+
}
168200
}

src/main/java/com/amazon/sqs/javamessaging/ExtendedAsyncClientConfiguration.java

+33
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import software.amazon.awssdk.annotations.NotThreadSafe;
44
import software.amazon.awssdk.services.s3.S3AsyncClient;
55
import software.amazon.awssdk.services.s3.model.ObjectCannedACL;
6+
import software.amazon.awssdk.utils.StringUtils;
67
import software.amazon.payloadoffloading.PayloadStorageAsyncConfiguration;
78
import software.amazon.payloadoffloading.ServerSideEncryptionStrategy;
89

@@ -16,6 +17,7 @@ public class ExtendedAsyncClientConfiguration extends PayloadStorageAsyncConfigu
1617
private boolean cleanupS3Payload = true;
1718
private boolean useLegacyReservedAttributeName = true;
1819
private boolean ignorePayloadNotFound = false;
20+
private String s3KeyPrefix = "";
1921

2022
public ExtendedAsyncClientConfiguration() {
2123
this.setPayloadSizeThreshold(SQSExtendedClientConstants.DEFAULT_MESSAGE_SIZE_THRESHOLD);
@@ -26,6 +28,7 @@ public ExtendedAsyncClientConfiguration(ExtendedAsyncClientConfiguration other)
2628
this.cleanupS3Payload = other.doesCleanupS3Payload();
2729
this.useLegacyReservedAttributeName = other.usesLegacyReservedAttributeName();
2830
this.ignorePayloadNotFound = other.ignoresPayloadNotFound();
31+
this.s3KeyPrefix = other.s3KeyPrefix;
2932
}
3033

3134
/**
@@ -117,6 +120,36 @@ public ExtendedAsyncClientConfiguration withIgnorePayloadNotFound(boolean ignore
117120
setIgnorePayloadNotFound(ignorePayloadNotFound);
118121
return this;
119122
}
123+
/**
124+
* Sets a string that will be used as prefix of the S3 Key.
125+
*
126+
* @param s3KeyPrefix
127+
* A S3 key prefix value
128+
*/
129+
public void setS3KeyPrefix(String s3KeyPrefix) {
130+
this.s3KeyPrefix = AmazonSQSExtendedClientUtil.trimAndValidateS3KeyPrefix(s3KeyPrefix);
131+
}
132+
133+
/**
134+
* Sets a string that will be used as prefix of the S3 Key.
135+
*
136+
* @param s3KeyPrefix
137+
* A S3 key prefix value
138+
*
139+
* @return the updated ExtendedClientConfiguration object.
140+
*/
141+
public ExtendedAsyncClientConfiguration withS3KeyPrefix(String s3KeyPrefix) {
142+
setS3KeyPrefix(s3KeyPrefix);
143+
return this;
144+
}
145+
146+
/**
147+
* Gets the S3 key prefix
148+
* @return the prefix value which is being used for compose the S3 key.
149+
*/
150+
public String getS3KeyPrefix() {
151+
return this.s3KeyPrefix;
152+
}
120153

121154
/**
122155
* Checks whether or not clean up large objects in S3 is enabled.

src/main/java/com/amazon/sqs/javamessaging/ExtendedClientConfiguration.java

+36
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
package com.amazon.sqs.javamessaging;
1717

18+
import org.apache.commons.logging.Log;
19+
import org.apache.commons.logging.LogFactory;
1820
import software.amazon.awssdk.annotations.NotThreadSafe;
1921
import software.amazon.awssdk.services.s3.S3Client;
2022
import software.amazon.awssdk.services.s3.model.ObjectCannedACL;
@@ -28,10 +30,12 @@
2830
*/
2931
@NotThreadSafe
3032
public class ExtendedClientConfiguration extends PayloadStorageConfiguration {
33+
private static final Log LOG = LogFactory.getLog(ExtendedClientConfiguration.class);
3134

3235
private boolean cleanupS3Payload = true;
3336
private boolean useLegacyReservedAttributeName = true;
3437
private boolean ignorePayloadNotFound = false;
38+
private String s3KeyPrefix = "";
3539

3640
public ExtendedClientConfiguration() {
3741
super();
@@ -43,6 +47,7 @@ public ExtendedClientConfiguration(ExtendedClientConfiguration other) {
4347
this.cleanupS3Payload = other.doesCleanupS3Payload();
4448
this.useLegacyReservedAttributeName = other.usesLegacyReservedAttributeName();
4549
this.ignorePayloadNotFound = other.ignoresPayloadNotFound();
50+
this.s3KeyPrefix = other.s3KeyPrefix;
4651
}
4752

4853
/**
@@ -128,6 +133,37 @@ public ExtendedClientConfiguration withIgnorePayloadNotFound(boolean ignorePaylo
128133
return this;
129134
}
130135

136+
/**
137+
* Sets a string that will be used as prefix of the S3 Key.
138+
*
139+
* @param s3KeyPrefix
140+
* A S3 key prefix value
141+
*/
142+
public void setS3KeyPrefix(String s3KeyPrefix) {
143+
this.s3KeyPrefix = AmazonSQSExtendedClientUtil.trimAndValidateS3KeyPrefix(s3KeyPrefix);
144+
}
145+
146+
/**
147+
* Sets a string that will be used as prefix of the S3 Key.
148+
*
149+
* @param s3KeyPrefix
150+
* A S3 key prefix value
151+
*
152+
* @return the updated ExtendedClientConfiguration object.
153+
*/
154+
public ExtendedClientConfiguration withS3KeyPrefix(String s3KeyPrefix) {
155+
setS3KeyPrefix(s3KeyPrefix);
156+
return this;
157+
}
158+
159+
/**
160+
* Gets the S3 key prefix
161+
* @return the prefix value which is being used for compose the S3 key.
162+
*/
163+
public String getS3KeyPrefix() {
164+
return this.s3KeyPrefix;
165+
}
166+
131167
/**
132168
* Checks whether or not clean up large objects in S3 is enabled.
133169
*

src/main/java/com/amazon/sqs/javamessaging/SQSExtendedClientConstants.java

+10
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
package com.amazon.sqs.javamessaging;
1717

1818

19+
import java.util.regex.Pattern;
20+
1921
public class SQSExtendedClientConstants {
2022
// This constant is shared with SNSExtendedClient
2123
// SNS team should be notified of any changes made to this
@@ -31,4 +33,12 @@ public class SQSExtendedClientConstants {
3133

3234
public static final String S3_BUCKET_NAME_MARKER = "-..s3BucketName..-";
3335
public static final String S3_KEY_MARKER = "-..s3Key..-";
36+
37+
public static final int UUID_LENGTH = 36;
38+
39+
public static final int MAX_S3_KEY_LENGTH = 1024;
40+
41+
public static final int MAX_S3_KEY_PREFIX_LENGTH = MAX_S3_KEY_LENGTH - UUID_LENGTH;
42+
43+
public static final Pattern INVALID_S3_PREFIX_KEY_CHARACTERS_PATTERN = Pattern.compile("[^a-zA-Z0-9./_-]");
3444
}

0 commit comments

Comments
 (0)