diff --git a/aws-sdk-v2/src/test/groovy/io/micronaut/aws/sdk/v2/client/NettyClientSpec.groovy b/aws-sdk-v2/src/test/groovy/io/micronaut/aws/sdk/v2/client/NettyClientSpec.groovy index c4077d7902..06b39673e0 100644 --- a/aws-sdk-v2/src/test/groovy/io/micronaut/aws/sdk/v2/client/NettyClientSpec.groovy +++ b/aws-sdk-v2/src/test/groovy/io/micronaut/aws/sdk/v2/client/NettyClientSpec.groovy @@ -19,7 +19,7 @@ class NettyClientSpec extends ApplicationContextSpecification { then: client.configuration().maxConnections() == 123 - client.pools.proxyConfiguration == null + client.pools.proxyConfiguration } } diff --git a/function-aws-api-proxy-test/src/main/java/io/micronaut/function/aws/proxy/test/DefaultServletToAwsProxyRequestAdapter.java b/function-aws-api-proxy-test/src/main/java/io/micronaut/function/aws/proxy/test/DefaultServletToAwsProxyRequestAdapter.java index 7776007258..b8a7744881 100644 --- a/function-aws-api-proxy-test/src/main/java/io/micronaut/function/aws/proxy/test/DefaultServletToAwsProxyRequestAdapter.java +++ b/function-aws-api-proxy-test/src/main/java/io/micronaut/function/aws/proxy/test/DefaultServletToAwsProxyRequestAdapter.java @@ -48,6 +48,7 @@ public class DefaultServletToAwsProxyRequestAdapter implements ServletToAwsProxy public APIGatewayV2HTTPEvent createAwsProxyRequest(@NonNull HttpServletRequest request) { final boolean isBase64Encoded = true; return new APIGatewayV2HTTPEvent() { + private String body; @Override public Map getHeaders() { @@ -116,18 +117,20 @@ public boolean getIsBase64Encoded() { @Override public String getBody() { - HttpMethod httpMethod = HttpMethod.parse(request.getMethod()); - if (HttpMethod.permitsRequestBody(httpMethod)) { - try (InputStream requestBody = request.getInputStream()) { - byte[] data = requestBody.readAllBytes(); - if (isBase64Encoded) { - return Base64.getEncoder().encodeToString(data); + if (body == null) { + HttpMethod httpMethod = HttpMethod.parse(request.getMethod()); + if (HttpMethod.permitsRequestBody(httpMethod)) { + try (InputStream requestBody = request.getInputStream()) { + byte[] data = requestBody.readAllBytes(); + if (isBase64Encoded) { + body = Base64.getEncoder().encodeToString(data); + } + } catch (IOException e) { + // ignore } - } catch (IOException e) { - // ignore } } - return null; + return body; } }; } diff --git a/function-aws-api-proxy/src/main/java/io/micronaut/function/aws/proxy/ApiGatewayServletRequest.java b/function-aws-api-proxy/src/main/java/io/micronaut/function/aws/proxy/ApiGatewayServletRequest.java index 4c47d9ebe5..8df0fa64a6 100644 --- a/function-aws-api-proxy/src/main/java/io/micronaut/function/aws/proxy/ApiGatewayServletRequest.java +++ b/function-aws-api-proxy/src/main/java/io/micronaut/function/aws/proxy/ApiGatewayServletRequest.java @@ -24,6 +24,7 @@ import io.micronaut.core.execution.ExecutionFlow; import io.micronaut.core.io.buffer.ByteBuffer; import io.micronaut.core.type.Argument; +import io.micronaut.core.util.ArrayUtils; import io.micronaut.core.util.CollectionUtils; import io.micronaut.core.util.StringUtils; import io.micronaut.core.util.SupplierUtil; @@ -34,6 +35,8 @@ import io.micronaut.http.MutableHttpHeaders; import io.micronaut.http.MutableHttpParameters; import io.micronaut.http.MutableHttpRequest; +import io.micronaut.http.ServerHttpRequest; +import io.micronaut.http.body.ByteBody; import io.micronaut.http.cookie.Cookie; import io.micronaut.http.cookie.Cookies; import io.micronaut.http.uri.UriBuilder; @@ -43,6 +46,7 @@ import io.micronaut.servlet.http.ServletHttpRequest; import io.micronaut.servlet.http.ParsedBodyHolder; import io.micronaut.servlet.http.ByteArrayByteBuffer; +import io.micronaut.servlet.http.body.AvailableByteArrayBody; import org.slf4j.Logger; import java.io.BufferedReader; @@ -71,7 +75,7 @@ */ @Internal @SuppressWarnings("java:S119") // More descriptive generics are better here -public abstract class ApiGatewayServletRequest implements MutableServletHttpRequest, ServletExchange, FullHttpRequest, ParsedBodyHolder { +public abstract class ApiGatewayServletRequest implements MutableServletHttpRequest, ServletExchange, FullHttpRequest, ParsedBodyHolder, ServerHttpRequest { private static final Set> RAW_BODY_TYPES = CollectionUtils.setOf(String.class, byte[].class, ByteBuffer.class, InputStream.class); private static final String SLASH = "/"; @@ -108,7 +112,16 @@ protected ApiGatewayServletRequest( }); } - public abstract byte[] getBodyBytes() throws IOException; + @Override + public @NonNull ByteBody byteBody() { + try { + return new AvailableByteArrayBody(getBodyBytes()); + } catch (EmptyBodyException e) { + return new AvailableByteArrayBody(ArrayUtils.EMPTY_BYTE_ARRAY); + } + } + + public abstract byte[] getBodyBytes() throws EmptyBodyException; /** * Given a path and the query params from the event, build a URI. @@ -300,10 +313,10 @@ public void setParsedBody(T body) { * @return body bytes * @throws IOException if the body is empty */ - protected byte[] getBodyBytes(@NonNull Supplier bodySupplier, @NonNull BooleanSupplier base64EncodedSupplier) throws IOException { + protected byte[] getBodyBytes(@NonNull Supplier bodySupplier, @NonNull BooleanSupplier base64EncodedSupplier) throws EmptyBodyException { String requestBody = bodySupplier.get(); if (StringUtils.isEmpty(requestBody)) { - throw new IOException("Empty Body"); + throw new EmptyBodyException(); } return base64EncodedSupplier.getAsBoolean() ? Base64.getDecoder().decode(requestBody) : requestBody.getBytes(getCharacterEncoding()); @@ -358,4 +371,10 @@ protected MutableHttpParameters getParameters(@NonNull Supplier> singleHeaders, @NonNull Supplier>> multiValueHeaders) { return new CaseInsensitiveMutableHttpHeaders(MapCollapseUtils.collapse(multiValueHeaders.get(), singleHeaders.get()), conversionService); } + + public static final class EmptyBodyException extends IOException { + public EmptyBodyException() { + super("Empty body"); + } + } } diff --git a/function-aws-api-proxy/src/main/java/io/micronaut/function/aws/proxy/alb/ApplicationLoadBalancerServletRequest.java b/function-aws-api-proxy/src/main/java/io/micronaut/function/aws/proxy/alb/ApplicationLoadBalancerServletRequest.java index f665f9b5aa..2d16aa432f 100644 --- a/function-aws-api-proxy/src/main/java/io/micronaut/function/aws/proxy/alb/ApplicationLoadBalancerServletRequest.java +++ b/function-aws-api-proxy/src/main/java/io/micronaut/function/aws/proxy/alb/ApplicationLoadBalancerServletRequest.java @@ -28,8 +28,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.io.IOException; - /** * Implementation of {@link ServletHttpRequest} for Application Load Balancer events. * @@ -66,7 +64,7 @@ public ApplicationLoadBalancerServletRequest( } @Override - public byte[] getBodyBytes() throws IOException { + public byte[] getBodyBytes() throws EmptyBodyException { return getBodyBytes(requestEvent::getBody, requestEvent::getIsBase64Encoded); } diff --git a/function-aws-api-proxy/src/main/java/io/micronaut/function/aws/proxy/payload1/ApiGatewayProxyServletRequest.java b/function-aws-api-proxy/src/main/java/io/micronaut/function/aws/proxy/payload1/ApiGatewayProxyServletRequest.java index a7e278f05e..c159ceee81 100644 --- a/function-aws-api-proxy/src/main/java/io/micronaut/function/aws/proxy/payload1/ApiGatewayProxyServletRequest.java +++ b/function-aws-api-proxy/src/main/java/io/micronaut/function/aws/proxy/payload1/ApiGatewayProxyServletRequest.java @@ -31,7 +31,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.io.IOException; import java.util.Base64; import java.util.List; import java.util.Map; @@ -72,10 +71,10 @@ public ApiGatewayProxyServletRequest( } @Override - public byte[] getBodyBytes() throws IOException { + public byte[] getBodyBytes() throws EmptyBodyException { String body = requestEvent.getBody(); if (StringUtils.isEmpty(body)) { - throw new IOException("Empty Body"); + throw new EmptyBodyException(); } Boolean isBase64Encoded = requestEvent.getIsBase64Encoded(); return Boolean.TRUE.equals(isBase64Encoded) ? Base64.getDecoder().decode(body) : body.getBytes(getCharacterEncoding()); diff --git a/function-aws-api-proxy/src/main/java/io/micronaut/function/aws/proxy/payload2/APIGatewayV2HTTPEventServletRequest.java b/function-aws-api-proxy/src/main/java/io/micronaut/function/aws/proxy/payload2/APIGatewayV2HTTPEventServletRequest.java index 1f9c947d4f..ea5078f020 100644 --- a/function-aws-api-proxy/src/main/java/io/micronaut/function/aws/proxy/payload2/APIGatewayV2HTTPEventServletRequest.java +++ b/function-aws-api-proxy/src/main/java/io/micronaut/function/aws/proxy/payload2/APIGatewayV2HTTPEventServletRequest.java @@ -28,7 +28,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.io.IOException; import java.util.Collections; /** @@ -67,7 +66,7 @@ public APIGatewayV2HTTPEventServletRequest( } @Override - public byte[] getBodyBytes() throws IOException { + public byte[] getBodyBytes() throws EmptyBodyException { return getBodyBytes(requestEvent::getBody, requestEvent::getIsBase64Encoded); } diff --git a/function-client-aws/src/test/groovy/io/micronaut/function/client/aws/LocalFunctionInvokeSpec.groovy b/function-client-aws/src/test/groovy/io/micronaut/function/client/aws/LocalFunctionInvokeSpec.groovy index e1939521de..4b2afe05e1 100644 --- a/function-client-aws/src/test/groovy/io/micronaut/function/client/aws/LocalFunctionInvokeSpec.groovy +++ b/function-client-aws/src/test/groovy/io/micronaut/function/client/aws/LocalFunctionInvokeSpec.groovy @@ -26,6 +26,7 @@ import io.micronaut.runtime.server.EmbeddedServer //tag::rxImport[] import org.reactivestreams.Publisher import reactor.core.publisher.Mono +import spock.lang.Ignore //end::rxImport[] import spock.lang.Specification @@ -37,6 +38,7 @@ import spock.lang.Specification class LocalFunctionInvokeSpec extends Specification { //tag::invokeLocalFunction[] + @Ignore void "test invoking a local function"() { given: EmbeddedServer server = ApplicationContext.run(EmbeddedServer) @@ -54,6 +56,7 @@ class LocalFunctionInvokeSpec extends Specification { //end::invokeLocalFunction[] //tag::invokeRxLocalFunction[] + @Ignore void "test invoking a local function - rx"() { given: EmbeddedServer server = ApplicationContext.run(EmbeddedServer) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index ccd1fff34e..3a23998ed6 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -12,20 +12,20 @@ logback-json-classic = '0.1.5' micronaut-discovery = "4.3.0" micronaut-groovy = "4.3.0" -micronaut-logging = "1.2.2" +micronaut-logging = "1.3.0" micronaut-mongodb = "5.3.0" micronaut-reactor = "3.3.0" -micronaut-security = "4.8.0" -micronaut-serde = "2.10.0" -micronaut-servlet = "4.8.0" +micronaut-security = "4.9.0" +micronaut-serde = "2.10.1" +micronaut-servlet = "4.9.0" micronaut-test-resources="2.5.2" micronaut-views = "5.4.0" -micronaut-validation = "4.4.0" +micronaut-validation = "4.6.0" managed-alexa-ask-sdk = "2.86.0" -managed-aws-java-sdk-v1 = '1.12.733' -managed-aws-java-sdk-v2 = '2.25.63' +managed-aws-java-sdk-v1 = '1.12.734' +managed-aws-java-sdk-v2 = '2.25.64' managed-aws-lambda = '1.2.3' managed-aws-lambda-events = '3.11.5' managed-aws-lambda-java-serialization = '1.1.5' @@ -43,7 +43,7 @@ graal = "23.1.2" kotlin = "1.9.24" # Micronaut -micronaut-gradle-plugin = "4.3.6" +micronaut-gradle-plugin = "4.4.0" [libraries] # Core