Light, fluffy, and always free - The AWS Local Emulator alternative
fix(sqs): inject QueueUrl into form body for query protocol path-based requests (#670)
Avi Shefi4bb4f24fcd69
diff --git a/src/main/java/io/github/hectorvent/floci/core/common/SqsQueueUrlRouterFilter.java b/src/main/java/io/github/hectorvent/floci/core/common/SqsQueueUrlRouterFilter.javaindex 8c6055a45d..a4bc645ecc 100644--- a/src/main/java/io/github/hectorvent/floci/core/common/SqsQueueUrlRouterFilter.java+++ b/src/main/java/io/github/hectorvent/floci/core/common/SqsQueueUrlRouterFilter.java@@ -6,16 +6,25 @@ import jakarta.ws.rs.container.PreMatching;import jakarta.ws.rs.core.MediaType;import jakarta.ws.rs.ext.Provider;+import java.io.ByteArrayInputStream;+import java.io.InputStream;+import java.io.SequenceInputStream;import java.net.URI;+import java.net.URLEncoder;+import java.nio.charset.StandardCharsets;import java.util.regex.Pattern;/**- * Pre-matching filter that rewrites SQS JSON 1.0 requests sent to the queue URL path- * (/{accountId}/{queueName}) to POST / so they are handled by AwsJsonController.+ * Pre-matching filter that rewrites SQS requests sent to the queue URL path+ * (/{accountId}/{queueName}) to POST / so they are handled by the correct controller.* <p>* Newer AWS SDKs (e.g. aws-sdk-sqs Ruby gem >= 1.71) route operations to the queue URL* rather than POST /. Without this filter, those requests match S3Controller's* /{bucket}/{key:.+} handler and return NoSuchBucket errors.+ * <p>+ * For the query (form-encoded) protocol, AWS SDK v1 omits QueueUrl from the body and+ * uses the queue URL as the HTTP path instead. This filter appends it back into the+ * entity stream so SqsQueryHandler can look up the queue normally.*/@Provider@PreMatching@@ -53,10 +62,29 @@ public class SqsQueueUrlRouterFilter implements ContainerRequestFilter {return;}- URI rewritten = ctx.getUriInfo().getRequestUriBuilder()+ // Reconstruct the queue URL from the original path.+ URI reqUri = ctx.getUriInfo().getRequestUri();+ String queueUrl = reqUri.getScheme() + "://" + reqUri.getAuthority() + path;++ if (isSqsQuery) {+ // AWS SDK v1 omits QueueUrl from the form body and uses the queue URL as the+ // HTTP path instead. Append it to the entity stream so SqsQueryHandler gets it+ // naturally from form params — no changes needed in AwsQueryController.+ byte[] injection = ("&QueueUrl=" + URLEncoder.encode(queueUrl, StandardCharsets.UTF_8))+ .getBytes(StandardCharsets.UTF_8);+ ctx.setEntityStream(new SequenceInputStream(ctx.getEntityStream(),+ new ByteArrayInputStream(injection)));+ String cl = ctx.getHeaderString("Content-Length");+ if (cl != null) {+ ctx.getHeaders().putSingle("Content-Length",+ String.valueOf(Long.parseLong(cl) + injection.length));+ }+ }++ // Rewrite the path to / so AwsQueryController / AwsJsonController handles the request.+ ctx.setRequestUri(ctx.getUriInfo().getRequestUriBuilder().replacePath("/")- .build();- ctx.setRequestUri(rewritten);+ .build());}private boolean isSqsTarget(String target) {