mirror of
https://github.com/floci-io/floci.git
synced 2026-11-23 22:11:36 -05:00
fix(sqs): support binary message attributes and fix MD5OfMessageAttributes (#168)
This commit is contained in:
1 parent
7253559207
commit
5440ae8a55
5 files changed
+107
-21
No files matched your search
@@ -14,6 +14,7 @@ import jakarta.inject.Inject;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Base64;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -136,8 +137,14 @@ public class SqsJsonHandler {
|
||||
String name = entry.getKey();
|
||||
String dataType = entry.getValue().path("DataType").asText(null);
|
||||
String stringValue = entry.getValue().path("StringValue").asText(null);
|
||||
if (dataType != null && stringValue != null) {
|
||||
messageAttributes.put(name, new MessageAttributeValue(stringValue, dataType));
|
||||
String binaryValueBase64 = entry.getValue().path("BinaryValue").asText(null);
|
||||
if (dataType != null) {
|
||||
if (binaryValueBase64 != null) {
|
||||
byte[] binaryValue = Base64.getDecoder().decode(binaryValueBase64);
|
||||
messageAttributes.put(name, new MessageAttributeValue(binaryValue, dataType));
|
||||
} else if (stringValue != null) {
|
||||
messageAttributes.put(name, new MessageAttributeValue(stringValue, dataType));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -196,7 +203,11 @@ public class SqsJsonHandler {
|
||||
for (var entry : msg.getMessageAttributes().entrySet()) {
|
||||
ObjectNode valNode = msgAttrs.putObject(entry.getKey());
|
||||
valNode.put("DataType", entry.getValue().getDataType());
|
||||
valNode.put("StringValue", entry.getValue().getStringValue());
|
||||
if (entry.getValue().getBinaryValue() != null) {
|
||||
valNode.put("BinaryValue", Base64.getEncoder().encodeToString(entry.getValue().getBinaryValue()));
|
||||
} else {
|
||||
valNode.put("StringValue", entry.getValue().getStringValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -277,8 +288,14 @@ public class SqsJsonHandler {
|
||||
String name = attrEntry.getKey();
|
||||
String dataType = attrEntry.getValue().path("DataType").asText(null);
|
||||
String stringValue = attrEntry.getValue().path("StringValue").asText(null);
|
||||
if (dataType != null && stringValue != null) {
|
||||
messageAttributes.put(name, new MessageAttributeValue(stringValue, dataType));
|
||||
String binaryValueBase64 = attrEntry.getValue().path("BinaryValue").asText(null);
|
||||
if (dataType != null) {
|
||||
if (binaryValueBase64 != null) {
|
||||
byte[] binaryValue = Base64.getDecoder().decode(binaryValueBase64);
|
||||
messageAttributes.put(name, new MessageAttributeValue(binaryValue, dataType));
|
||||
} else if (stringValue != null) {
|
||||
messageAttributes.put(name, new MessageAttributeValue(stringValue, dataType));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import jakarta.ws.rs.core.Response;
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Base64;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -131,8 +132,14 @@ public class SqsQueryHandler {
|
||||
if (name == null) break;
|
||||
String dataType = getParam(params, "MessageAttribute." + i + ".Value.DataType");
|
||||
String stringValue = getParam(params, "MessageAttribute." + i + ".Value.StringValue");
|
||||
if (dataType != null && stringValue != null) {
|
||||
messageAttributes.put(name, new MessageAttributeValue(stringValue, dataType));
|
||||
String binaryValueBase64 = getParam(params, "MessageAttribute." + i + ".Value.BinaryValue");
|
||||
if (dataType != null) {
|
||||
if (binaryValueBase64 != null) {
|
||||
byte[] binaryValue = Base64.getDecoder().decode(binaryValueBase64);
|
||||
messageAttributes.put(name, new MessageAttributeValue(binaryValue, dataType));
|
||||
} else if (stringValue != null) {
|
||||
messageAttributes.put(name, new MessageAttributeValue(stringValue, dataType));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -189,9 +196,13 @@ public class SqsQueryHandler {
|
||||
xml.start("MessageAttribute")
|
||||
.elem("Name", entry.getKey())
|
||||
.start("Value")
|
||||
.elem("DataType", entry.getValue().getDataType())
|
||||
.elem("StringValue", entry.getValue().getStringValue())
|
||||
.end("Value")
|
||||
.elem("DataType", entry.getValue().getDataType());
|
||||
if (entry.getValue().getBinaryValue() != null) {
|
||||
xml.elem("BinaryValue", Base64.getEncoder().encodeToString(entry.getValue().getBinaryValue()));
|
||||
} else {
|
||||
xml.elem("StringValue", entry.getValue().getStringValue());
|
||||
}
|
||||
xml.end("Value")
|
||||
.end("MessageAttribute");
|
||||
}
|
||||
}
|
||||
@@ -257,8 +268,14 @@ public class SqsQueryHandler {
|
||||
if (name == null) break;
|
||||
String dataType = getParam(params, "SendMessageBatchRequestEntry." + i + ".MessageAttribute." + j + ".Value.DataType");
|
||||
String stringValue = getParam(params, "SendMessageBatchRequestEntry." + i + ".MessageAttribute." + j + ".Value.StringValue");
|
||||
if (dataType != null && stringValue != null) {
|
||||
messageAttributes.put(name, new MessageAttributeValue(stringValue, dataType));
|
||||
String binaryValueBase64 = getParam(params, "SendMessageBatchRequestEntry." + i + ".MessageAttribute." + j + ".Value.BinaryValue");
|
||||
if (dataType != null) {
|
||||
if (binaryValueBase64 != null) {
|
||||
byte[] binaryValue = Base64.getDecoder().decode(binaryValueBase64);
|
||||
messageAttributes.put(name, new MessageAttributeValue(binaryValue, dataType));
|
||||
} else if (stringValue != null) {
|
||||
messageAttributes.put(name, new MessageAttributeValue(stringValue, dataType));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -268,6 +285,9 @@ public class SqsQueryHandler {
|
||||
.elem("Id", id)
|
||||
.elem("MessageId", msg.getMessageId())
|
||||
.elem("MD5OfMessageBody", msg.getMd5OfBody());
|
||||
if (msg.getMd5OfMessageAttributes() != null) {
|
||||
xml.elem("MD5OfMessageAttributes", msg.getMd5OfMessageAttributes());
|
||||
}
|
||||
if (msg.getSequenceNumber() > 0) {
|
||||
xml.elem("SequenceNumber", msg.getSequenceNumber());
|
||||
}
|
||||
|
||||
@@ -109,13 +109,10 @@ public class Message {
|
||||
dos.writeInt(typeBytes.length);
|
||||
dos.write(typeBytes);
|
||||
|
||||
if ("Binary".equals(val.getDataType()) || val.getDataType().startsWith("Binary.")) {
|
||||
dos.write(2);
|
||||
// For now, emulator assumes string values for simplicity, but if it were binary we'd decode it.
|
||||
// Actually, the SDK encodes Binary attributes as base64 in StringValue if sent via JSON.
|
||||
byte[] valBytes = java.util.Base64.getDecoder().decode(val.getStringValue());
|
||||
dos.writeInt(valBytes.length);
|
||||
dos.write(valBytes);
|
||||
if (val.getBinaryValue() != null) {
|
||||
dos.write(2); // Binary type
|
||||
dos.writeInt(val.getBinaryValue().length);
|
||||
dos.write(val.getBinaryValue());
|
||||
} else {
|
||||
dos.write(1); // String or Number
|
||||
byte[] valBytes = val.getStringValue().getBytes(java.nio.charset.StandardCharsets.UTF_8);
|
||||
|
||||
@@ -8,6 +8,7 @@ import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
public class MessageAttributeValue {
|
||||
|
||||
private String stringValue;
|
||||
private byte[] binaryValue;
|
||||
private String dataType;
|
||||
|
||||
public MessageAttributeValue() {}
|
||||
@@ -17,9 +18,17 @@ public class MessageAttributeValue {
|
||||
this.dataType = dataType;
|
||||
}
|
||||
|
||||
public MessageAttributeValue(byte[] binaryValue, String dataType) {
|
||||
this.binaryValue = binaryValue;
|
||||
this.dataType = dataType;
|
||||
}
|
||||
|
||||
public String getStringValue() { return stringValue; }
|
||||
public void setStringValue(String stringValue) { this.stringValue = stringValue; }
|
||||
|
||||
public byte[] getBinaryValue() { return binaryValue; }
|
||||
public void setBinaryValue(byte[] binaryValue) { this.binaryValue = binaryValue; }
|
||||
|
||||
public String getDataType() { return dataType; }
|
||||
public void setDataType(String dataType) { this.dataType = dataType; }
|
||||
}
|
||||
Reference in new issue
Block a user