Skip to content

Commit a30c8b1

Browse files
Support receiving message attributes with types of the form Binary or Binary.
1 parent 1aa7bab commit a30c8b1

File tree

6 files changed

+44
-9
lines changed

6 files changed

+44
-9
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
target/
2+
.idea/

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ for communicating with Amazon Simple Queue Service. This project builds on top o
1515
<dependency>
1616
<groupId>com.amazonaws</groupId>
1717
<artifactId>amazon-sqs-java-messaging-lib</artifactId>
18-
<version>1.2.0</version>
18+
<version>1.2.1</version>
1919
<type>jar</type>
2020
</dependency>
2121
```
2222
* **Further information** - Read the [API documentation](http://aws.amazon.com/documentation/sqs/).
2323

2424
## Feedback
2525
* Give us feedback [here](https://github.com/awslabs/amazon-sqs-java-messaging-lib/issues).
26-
* If you'd like to contribute a new feature or bug fix, we'd love to see Github pull requests from you.
26+
* If you'd like to contribute a new feature or bug fix, we'd love to see GitHub pull requests from you.
2727

2828

2929

pom.xml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<modelVersion>4.0.0</modelVersion>
33
<groupId>com.amazonaws</groupId>
44
<artifactId>amazon-sqs-java-messaging-lib</artifactId>
5-
<version>1.2.0</version>
5+
<version>1.2.1</version>
66
<name>Amazon SQS Java Messaging Library</name>
77
<description>The Amazon SQS Java Messaging Library holds the Java Message Service compatible classes, that are used
88
for communicating with Amazon Simple Queue Service.
@@ -29,7 +29,7 @@
2929
</developer>
3030
</developers>
3131
<properties>
32-
<aws-java-sdk.version>1.12.415</aws-java-sdk.version>
32+
<aws-java-sdk.version>1.12.778</aws-java-sdk.version>
3333
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
3434
</properties>
3535

@@ -47,19 +47,19 @@
4747
<dependency>
4848
<groupId>org.junit.jupiter</groupId>
4949
<artifactId>junit-jupiter</artifactId>
50-
<version>5.9.2</version>
50+
<version>5.11.3</version>
5151
<scope>test</scope>
5252
</dependency>
5353
<dependency>
5454
<groupId>junit</groupId>
5555
<artifactId>junit</artifactId>
56-
<version>4.13.1</version>
56+
<version>4.13.2</version>
5757
<scope>test</scope>
5858
</dependency>
5959
<dependency>
6060
<groupId>org.mockito</groupId>
6161
<artifactId>mockito-core</artifactId>
62-
<version>5.1.1</version>
62+
<version>5.14.2</version>
6363
<scope>test</scope>
6464
</dependency>
6565
<dependency>

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ public class SQSMessagingClientConstants {
5151

5252
public static final String SHORT = "Number.short";
5353

54+
public static final String BINARY = "Binary";
55+
5456
public static final String INT_FALSE = "0";
5557

5658
public static final String INT_TRUE = "1";

src/main/java/com/amazon/sqs/javamessaging/message/SQSMessage.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
import com.amazon.sqs.javamessaging.SQSQueueDestination;
3636
import com.amazon.sqs.javamessaging.acknowledge.Acknowledger;
3737
import com.amazonaws.services.sqs.model.MessageAttributeValue;
38+
import org.apache.commons.logging.Log;
39+
import org.apache.commons.logging.LogFactory;
3840

3941
import static com.amazon.sqs.javamessaging.SQSMessagingClientConstants.*;
4042

@@ -60,7 +62,8 @@
6062
* approximate Receive Count observed on the SQS side.
6163
*/
6264
public class SQSMessage implements Message {
63-
65+
66+
private static final Log LOG = LogFactory.getLog(SQSMessage.class);
6467
private static final Charset DEFAULT_CHARSET = StandardCharsets.UTF_8;
6568

6669
// Define constant message types.
@@ -1150,9 +1153,11 @@ private static Object getObjectValue(String value, String type) throws JMSExcept
11501153
return Float.valueOf(value);
11511154
} else if (SHORT.equals(type)) {
11521155
return Short.valueOf(value);
1153-
} else if (type != null && (type.startsWith(STRING) || type.startsWith(NUMBER))) {
1156+
} else if (type != null && (type.startsWith(STRING) || type.startsWith(NUMBER) || type.startsWith(BINARY))) {
11541157
return value;
11551158
} else {
1159+
LOG.debug("Caught exception while constructing message attribute. " +
1160+
"Unknown or yet supported JMS property type - " + type);
11561161
throw new JMSException(type + " is not a supported JMS property type");
11571162
}
11581163
}

src/test/java/com/amazon/sqs/javamessaging/message/SQSMessageTest.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
import org.junit.jupiter.api.BeforeEach;
2626
import org.junit.jupiter.api.Test;
2727

28+
import java.nio.ByteBuffer;
29+
import java.nio.charset.StandardCharsets;
2830
import java.util.Enumeration;
2931
import java.util.HashMap;
3032
import java.util.HashSet;
@@ -33,6 +35,7 @@
3335
import java.util.Set;
3436

3537
import static com.amazon.sqs.javamessaging.SQSMessagingClientConstants.APPROXIMATE_RECEIVE_COUNT;
38+
import static com.amazon.sqs.javamessaging.SQSMessagingClientConstants.BINARY;
3639
import static com.amazon.sqs.javamessaging.SQSMessagingClientConstants.JMSX_DELIVERY_COUNT;
3740
import static org.junit.jupiter.api.Assertions.assertEquals;
3841
import static org.junit.jupiter.api.Assertions.assertFalse;
@@ -59,6 +62,8 @@ public class SQSMessageTest {
5962
final String myString = "myString";
6063
final String myCustomString = "myCustomString";
6164
final String myNumber = "myNumber";
65+
final String myBinary = "myBinary";
66+
final String myCustomBinary = "myCustomBinary";
6267

6368
@BeforeEach
6469
public void setup() {
@@ -296,6 +301,18 @@ public void testSQSMessageAttributeToProperty() throws JMSException {
296301
.withDataType(SQSMessagingClientConstants.NUMBER)
297302
.withStringValue("500"));
298303

304+
messageAttributes.put(myBinary, new MessageAttributeValue()
305+
.withDataType(SQSMessagingClientConstants.BINARY)
306+
.withStringValue("BQUZTR1ZzYkc4PQ=="));
307+
308+
messageAttributes.put(myCustomBinary, new MessageAttributeValue()
309+
.withDataType(SQSMessagingClientConstants.BINARY + ".custom")
310+
.withStringValue("data:image/gif;base64,QABAAACAkQBADs=")
311+
.withBinaryValue(ByteBuffer.wrap("data:image/gif;base64,QABAAACAkQBADs="
312+
.getBytes(StandardCharsets.UTF_8))
313+
)
314+
);
315+
299316
com.amazonaws.services.sqs.model.Message sqsMessage = new com.amazonaws.services.sqs.model.Message()
300317
.withMessageAttributes(messageAttributes)
301318
.withAttributes(systemAttributes)
@@ -353,6 +370,12 @@ public void testSQSMessageAttributeToProperty() throws JMSException {
353370
assertEquals(message.getFloatProperty(myNumber), 500f);
354371
assertEquals(message.getDoubleProperty(myNumber), 500d);
355372

373+
assertTrue(message.propertyExists(myBinary));
374+
assertEquals(message.getObjectProperty(myBinary), "BQUZTR1ZzYkc4PQ==");
375+
assertEquals(message.getStringProperty(myBinary), "BQUZTR1ZzYkc4PQ==");
376+
assertTrue(message.propertyExists(myCustomBinary));
377+
assertEquals(message.getObjectProperty(myCustomBinary), "data:image/gif;base64,QABAAACAkQBADs=");
378+
assertEquals(message.getStringProperty(myCustomBinary), "data:image/gif;base64,QABAAACAkQBADs=");
356379

357380
// Validate property names
358381
Set<String> propertyNamesSet = Set.of(
@@ -367,6 +390,8 @@ public void testSQSMessageAttributeToProperty() throws JMSException {
367390
myString,
368391
myCustomString,
369392
myNumber,
393+
myBinary,
394+
myCustomBinary,
370395
JMSX_DELIVERY_COUNT
371396
);
372397

@@ -388,6 +413,8 @@ public void testSQSMessageAttributeToProperty() throws JMSException {
388413
assertFalse(message.propertyExists("myByteProperty"));
389414
assertFalse(message.propertyExists("myString"));
390415
assertFalse(message.propertyExists("myNumber"));
416+
assertFalse(message.propertyExists("myBinary"));
417+
assertFalse(message.propertyExists("myCustomBinary"));
391418

392419
propertyNames = message.getPropertyNames();
393420
assertFalse(propertyNames.hasMoreElements());

0 commit comments

Comments
 (0)