mirror of
https://github.com/floci-io/floci.git
synced 2026-11-23 22:11:36 -05:00
fix(sns): add PublishBatch support to JSON protocol handler
Add PublishBatch, GetSubscriptionAttributes, SetSubscriptionAttributes, and ConfirmSubscription to the SnsJsonHandler switch statement so modern AWS SDK v2+ clients using the JSON protocol can call these operations. Includes integration tests verifying PublishBatch via JSON protocol returns Successful entries with MessageIds, plus an empty-entries edge case.
This commit is contained in:
1 parent
7c95cfe1b6
commit
543df0539b
2 files changed
+208
-2
No files matched your search
@@ -44,6 +44,10 @@ public class SnsJsonHandler {
|
||||
case "ListSubscriptions" -> handleListSubscriptions(request, region);
|
||||
case "ListSubscriptionsByTopic" -> handleListSubscriptionsByTopic(request, region);
|
||||
case "Publish" -> handlePublish(request, region);
|
||||
case "PublishBatch" -> handlePublishBatch(request, region);
|
||||
case "GetSubscriptionAttributes" -> handleGetSubscriptionAttributes(request, region);
|
||||
case "SetSubscriptionAttributes" -> handleSetSubscriptionAttributes(request, region);
|
||||
case "ConfirmSubscription" -> handleConfirmSubscription(request, region);
|
||||
case "TagResource" -> handleTagResource(request, region);
|
||||
case "UntagResource" -> handleUntagResource(request, region);
|
||||
case "ListTagsForResource" -> handleListTagsForResource(request, region);
|
||||
@@ -203,6 +207,84 @@ public class SnsJsonHandler {
|
||||
return Response.ok(response).build();
|
||||
}
|
||||
|
||||
private Response handlePublishBatch(JsonNode request, String region) {
|
||||
String topicArn = request.path("TopicArn").asText(null);
|
||||
List<Map<String, Object>> entries = new ArrayList<>();
|
||||
|
||||
JsonNode entriesNode = request.path("PublishBatchRequestEntries");
|
||||
if (entriesNode.isArray()) {
|
||||
for (JsonNode entryNode : entriesNode) {
|
||||
Map<String, Object> entry = new HashMap<>();
|
||||
entry.put("Id", entryNode.path("Id").asText(null));
|
||||
entry.put("Message", entryNode.path("Message").asText(null));
|
||||
entry.put("Subject", entryNode.path("Subject").asText(null));
|
||||
entry.put("MessageGroupId", entryNode.path("MessageGroupId").asText(null));
|
||||
entry.put("MessageDeduplicationId", entryNode.path("MessageDeduplicationId").asText(null));
|
||||
|
||||
JsonNode attrsNode = entryNode.path("MessageAttributes");
|
||||
if (attrsNode.isObject()) {
|
||||
Map<String, String> messageAttributes = new HashMap<>();
|
||||
attrsNode.fields().forEachRemaining(field ->
|
||||
messageAttributes.put(field.getKey(), field.getValue().path("StringValue").asText())
|
||||
);
|
||||
entry.put("MessageAttributes", messageAttributes);
|
||||
}
|
||||
|
||||
entries.add(entry);
|
||||
}
|
||||
}
|
||||
|
||||
SnsService.BatchPublishResult result = snsService.publishBatch(topicArn, entries, region);
|
||||
|
||||
ObjectNode response = objectMapper.createObjectNode();
|
||||
ArrayNode successful = response.putArray("Successful");
|
||||
for (String[] s : result.successful()) {
|
||||
ObjectNode item = objectMapper.createObjectNode();
|
||||
item.put("Id", s[0]);
|
||||
item.put("MessageId", s[1]);
|
||||
successful.add(item);
|
||||
}
|
||||
ArrayNode failed = response.putArray("Failed");
|
||||
for (String[] f : result.failed()) {
|
||||
ObjectNode item = objectMapper.createObjectNode();
|
||||
item.put("Id", f[0]);
|
||||
item.put("Code", f[1]);
|
||||
item.put("Message", f[2]);
|
||||
item.put("SenderFault", Boolean.parseBoolean(f[3]));
|
||||
failed.add(item);
|
||||
}
|
||||
|
||||
return Response.ok(response).build();
|
||||
}
|
||||
|
||||
private Response handleGetSubscriptionAttributes(JsonNode request, String region) {
|
||||
String subscriptionArn = request.path("SubscriptionArn").asText(null);
|
||||
Map<String, String> attrs = snsService.getSubscriptionAttributes(subscriptionArn, region);
|
||||
ObjectNode response = objectMapper.createObjectNode();
|
||||
ObjectNode attrsNode = response.putObject("Attributes");
|
||||
for (var entry : attrs.entrySet()) {
|
||||
attrsNode.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
return Response.ok(response).build();
|
||||
}
|
||||
|
||||
private Response handleSetSubscriptionAttributes(JsonNode request, String region) {
|
||||
String subscriptionArn = request.path("SubscriptionArn").asText(null);
|
||||
String attributeName = request.path("AttributeName").asText(null);
|
||||
String attributeValue = request.path("AttributeValue").asText(null);
|
||||
snsService.setSubscriptionAttribute(subscriptionArn, attributeName, attributeValue, region);
|
||||
return Response.ok(objectMapper.createObjectNode()).build();
|
||||
}
|
||||
|
||||
private Response handleConfirmSubscription(JsonNode request, String region) {
|
||||
String topicArn = request.path("TopicArn").asText(null);
|
||||
String token = request.path("Token").asText(null);
|
||||
String subscriptionArn = snsService.confirmSubscription(topicArn, token, region);
|
||||
ObjectNode response = objectMapper.createObjectNode();
|
||||
response.put("SubscriptionArn", subscriptionArn);
|
||||
return Response.ok(response).build();
|
||||
}
|
||||
|
||||
private ObjectNode subscriptionToNode(Subscription s) {
|
||||
ObjectNode node = objectMapper.createObjectNode();
|
||||
node.put("SubscriptionArn", s.getSubscriptionArn());
|
||||
|
||||
Reference in new issue
Block a user