diff --git a/aws-serverless-java-container-springboot4/src/main/java/com/amazonaws/serverless/proxy/spring/AwsSpringWebCustomRuntimeEventLoop.java b/aws-serverless-java-container-springboot4/src/main/java/com/amazonaws/serverless/proxy/spring/AwsSpringWebCustomRuntimeEventLoop.java index 970418246..d4e8cc0bc 100644 --- a/aws-serverless-java-container-springboot4/src/main/java/com/amazonaws/serverless/proxy/spring/AwsSpringWebCustomRuntimeEventLoop.java +++ b/aws-serverless-java-container-springboot4/src/main/java/com/amazonaws/serverless/proxy/spring/AwsSpringWebCustomRuntimeEventLoop.java @@ -130,7 +130,6 @@ private void eventLoop(ServletWebServerApplicationContext context) { HttpServletRequest httpServletRequest = AwsSpringHttpProcessingUtils.generateHttpServletRequest( incomingEvent.getBody(), null, mvc.getServletContext(), mapper); - httpServletRequest.startAsync(); AwsProxyResponse awsResponse = AwsSpringHttpProcessingUtils.processRequest( httpServletRequest, mvc, responseWriter); if (logger.isDebugEnabled()) { diff --git a/aws-serverless-java-container-springboot4/src/main/java/com/amazonaws/serverless/proxy/spring/SpringDelegatingLambdaContainerHandler.java b/aws-serverless-java-container-springboot4/src/main/java/com/amazonaws/serverless/proxy/spring/SpringDelegatingLambdaContainerHandler.java index 5af476d77..178abdb70 100644 --- a/aws-serverless-java-container-springboot4/src/main/java/com/amazonaws/serverless/proxy/spring/SpringDelegatingLambdaContainerHandler.java +++ b/aws-serverless-java-container-springboot4/src/main/java/com/amazonaws/serverless/proxy/spring/SpringDelegatingLambdaContainerHandler.java @@ -78,7 +78,6 @@ public void handleRequest(InputStream input, OutputStream output, Context lambda ServerlessMVC mvc = initHandler.getMvc(); HttpServletRequest httpServletRequest = AwsSpringHttpProcessingUtils .generateHttpServletRequest(input, lambdaContext, mvc.getServletContext(), this.mapper); - httpServletRequest.startAsync(); AwsProxyResponse awsProxyResponse = AwsSpringHttpProcessingUtils.processRequest(httpServletRequest, mvc, responseWriter); this.mapper.writeValue(output, awsProxyResponse); } diff --git a/aws-serverless-java-container-springboot4/src/test/java/com/amazonaws/serverless/proxy/spring/SpringDelegatingLambdaContainerHandlerTests.java b/aws-serverless-java-container-springboot4/src/test/java/com/amazonaws/serverless/proxy/spring/SpringDelegatingLambdaContainerHandlerTests.java index e98b19871..86fd8a966 100644 --- a/aws-serverless-java-container-springboot4/src/test/java/com/amazonaws/serverless/proxy/spring/SpringDelegatingLambdaContainerHandlerTests.java +++ b/aws-serverless-java-container-springboot4/src/test/java/com/amazonaws/serverless/proxy/spring/SpringDelegatingLambdaContainerHandlerTests.java @@ -23,175 +23,177 @@ @SuppressWarnings("rawtypes") public class SpringDelegatingLambdaContainerHandlerTests { - private static String API_GATEWAY_EVENT = "{\n" - + " \"version\": \"1.0\",\n" - + " \"resource\": \"$default\",\n" - + " \"path\": \"/async\",\n" - + " \"httpMethod\": \"POST\",\n" - + " \"headers\": {\n" - + " \"Content-Length\": \"45\",\n" - + " \"Content-Type\": \"application/json\",\n" - + " \"Host\": \"i76bfh111.execute-api.eu-west-3.amazonaws.com\",\n" - + " \"User-Agent\": \"curl/7.79.1\",\n" - + " \"X-Amzn-Trace-Id\": \"Root=1-64087690-2151375b219d3ba3389ea84e\",\n" - + " \"X-Forwarded-For\": \"109.210.252.44\",\n" - + " \"X-Forwarded-Port\": \"443\",\n" - + " \"X-Forwarded-Proto\": \"https\",\n" - + " \"accept\": \"*/*\"\n" - + " },\n" - + " \"multiValueHeaders\": {\n" - + " \"Content-Length\": [\n" - + " \"45\"\n" - + " ],\n" - + " \"Content-Type\": [\n" - + " \"application/json\"\n" - + " ],\n" - + " \"Host\": [\n" - + " \"i76bfhczs0.execute-api.eu-west-3.amazonaws.com\"\n" - + " ],\n" - + " \"User-Agent\": [\n" - + " \"curl/7.79.1\"\n" - + " ],\n" - + " \"X-Amzn-Trace-Id\": [\n" - + " \"Root=1-64087690-2151375b219d3ba3389ea84e\"\n" - + " ],\n" - + " \"X-Forwarded-For\": [\n" - + " \"109.210.252.44\"\n" - + " ],\n" - + " \"X-Forwarded-Port\": [\n" - + " \"443\"\n" - + " ],\n" - + " \"X-Forwarded-Proto\": [\n" - + " \"https\"\n" - + " ],\n" - + " \"accept\": [\n" - + " \"*/*\"\n" - + " ]\n" - + " },\n" - + " \"queryStringParameters\": {\n" - + " \"abc\": \"xyz\",\n" - + " \"name\": \"Ricky\",\n" - + " \"foo\": \"baz\"\n" - + " },\n" - + " \"multiValueQueryStringParameters\": {\n" - + " \"abc\": [\n" - + " \"xyz\"\n" - + " ],\n" - + " \"name\": [\n" - + " \"Ricky\"\n" - + " ],\n" - + " \"foo\": [\n" - + " \"bar\",\n" - + " \"baz\"\n" - + " ]\n" - + " },\n" - + " \"requestContext\": {\n" - + " \"accountId\": \"123456789098\",\n" - + " \"apiId\": \"i76bfhczs0\",\n" - + " \"domainName\": \"i76bfhc111.execute-api.eu-west-3.amazonaws.com\",\n" - + " \"domainPrefix\": \"i76bfhczs0\",\n" - + " \"extendedRequestId\": \"Bdd2ngt5iGYEMIg=\",\n" - + " \"httpMethod\": \"POST\",\n" - + " \"identity\": {\n" - + " \"accessKey\": null,\n" - + " \"accountId\": null,\n" - + " \"caller\": null,\n" - + " \"cognitoAmr\": null,\n" - + " \"cognitoAuthenticationProvider\": null,\n" - + " \"cognitoAuthenticationType\": null,\n" - + " \"cognitoIdentityId\": null,\n" - + " \"cognitoIdentityPoolId\": null,\n" - + " \"principalOrgId\": null,\n" - + " \"sourceIp\": \"109.210.252.44\",\n" - + " \"user\": null,\n" - + " \"userAgent\": \"curl/7.79.1\",\n" - + " \"userArn\": null\n" - + " },\n" - + " \"path\": \"/pets\",\n" - + " \"protocol\": \"HTTP/1.1\",\n" - + " \"requestId\": \"Bdd2ngt5iGYEMIg=\",\n" - + " \"requestTime\": \"08/Mar/2023:11:50:40 +0000\",\n" - + " \"requestTimeEpoch\": 1678276240455,\n" - + " \"resourceId\": \"$default\",\n" - + " \"resourcePath\": \"$default\",\n" - + " \"stage\": \"$default\"\n" - + " },\n" - + " \"pathParameters\": null,\n" - + " \"stageVariables\": null,\n" - + " \"body\": \"{\\\"name\\\":\\\"bob\\\"}\",\n" - + " \"isBase64Encoded\": false\n" - + "}"; + private static final String API_GATEWAY_EVENT = """ + { + "version": "1.0", + "resource": "$default", + "path": "/async", + "httpMethod": "POST", + "headers": { + "Content-Length": "45", + "Content-Type": "application/json", + "Host": "i76bfh111.execute-api.eu-west-3.amazonaws.com", + "User-Agent": "curl/7.79.1", + "X-Amzn-Trace-Id": "Root=1-64087690-2151375b219d3ba3389ea84e", + "X-Forwarded-For": "109.210.252.44", + "X-Forwarded-Port": "443", + "X-Forwarded-Proto": "https", + "accept": "*/*" + }, + "multiValueHeaders": { + "Content-Length": [ + "45" + ], + "Content-Type": [ + "application/json" + ], + "Host": [ + "i76bfhczs0.execute-api.eu-west-3.amazonaws.com" + ], + "User-Agent": [ + "curl/7.79.1" + ], + "X-Amzn-Trace-Id": [ + "Root=1-64087690-2151375b219d3ba3389ea84e" + ], + "X-Forwarded-For": [ + "109.210.252.44" + ], + "X-Forwarded-Port": [ + "443" + ], + "X-Forwarded-Proto": [ + "https" + ], + "accept": [ + "*/*" + ] + }, + "queryStringParameters": { + "abc": "xyz", + "name": "Ricky", + "foo": "baz" + }, + "multiValueQueryStringParameters": { + "abc": [ + "xyz" + ], + "name": [ + "Ricky" + ], + "foo": [ + "bar", + "baz" + ] + }, + "requestContext": { + "accountId": "123456789098", + "apiId": "i76bfhczs0", + "domainName": "i76bfhc111.execute-api.eu-west-3.amazonaws.com", + "domainPrefix": "i76bfhczs0", + "extendedRequestId": "Bdd2ngt5iGYEMIg=", + "httpMethod": "POST", + "identity": { + "accessKey": null, + "accountId": null, + "caller": null, + "cognitoAmr": null, + "cognitoAuthenticationProvider": null, + "cognitoAuthenticationType": null, + "cognitoIdentityId": null, + "cognitoIdentityPoolId": null, + "principalOrgId": null, + "sourceIp": "109.210.252.44", + "user": null, + "userAgent": "curl/7.79.1", + "userArn": null + }, + "path": "/pets", + "protocol": "HTTP/1.1", + "requestId": "Bdd2ngt5iGYEMIg=", + "requestTime": "08/Mar/2023:11:50:40 +0000", + "requestTimeEpoch": 1678276240455, + "resourceId": "$default", + "resourcePath": "$default", + "stage": "$default" + }, + "pathParameters": null, + "stageVariables": null, + "body": "{\\"name\\":\\"bob\\"}", + "isBase64Encoded": false + }"""; - private static String API_GATEWAY_EVENT_V2 = "{\n" + - " \"version\": \"2.0\",\n" + - " \"routeKey\": \"$default\",\n" + - " \"rawPath\": \"/my/path\",\n" + - " \"rawQueryString\": \"parameter1=value1¶meter1=value2&name=Ricky¶meter2=value\",\n" + - " \"cookies\": [\n" + - " \"cookie1\",\n" + - " \"cookie2\"\n" + - " ],\n" + - " \"headers\": {\n" + - " \"header1\": \"value1\",\n" + - " \"header2\": \"value1,value2\"\n" + - " },\n" + - " \"queryStringParameters\": {\n" + - " \"parameter1\": \"value1,value2\",\n" + - " \"name\": \"Ricky\",\n" + - " \"parameter2\": \"value\"\n" + - " },\n" + - " \"requestContext\": {\n" + - " \"accountId\": \"123456789012\",\n" + - " \"apiId\": \"api-id\",\n" + - " \"authentication\": {\n" + - " \"clientCert\": {\n" + - " \"clientCertPem\": \"CERT_CONTENT\",\n" + - " \"subjectDN\": \"www.example.com\",\n" + - " \"issuerDN\": \"Example issuer\",\n" + - " \"serialNumber\": \"a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1\",\n" + - " \"validity\": {\n" + - " \"notBefore\": \"May 28 12:30:02 2019 GMT\",\n" + - " \"notAfter\": \"Aug 5 09:36:04 2021 GMT\"\n" + - " }\n" + - " }\n" + - " },\n" + - " \"authorizer\": {\n" + - " \"jwt\": {\n" + - " \"claims\": {\n" + - " \"claim1\": \"value1\",\n" + - " \"claim2\": \"value2\"\n" + - " },\n" + - " \"scopes\": [\n" + - " \"scope1\",\n" + - " \"scope2\"\n" + - " ]\n" + - " }\n" + - " },\n" + - " \"domainName\": \"id.execute-api.us-east-1.amazonaws.com\",\n" + - " \"domainPrefix\": \"id\",\n" + - " \"http\": {\n" + - " \"method\": \"POST\",\n" + - " \"path\": \"/my/path\",\n" + - " \"protocol\": \"HTTP/1.1\",\n" + - " \"sourceIp\": \"IP\",\n" + - " \"userAgent\": \"agent\"\n" + - " },\n" + - " \"requestId\": \"id\",\n" + - " \"routeKey\": \"$default\",\n" + - " \"stage\": \"$default\",\n" + - " \"time\": \"12/Mar/2020:19:03:58 +0000\",\n" + - " \"timeEpoch\": 1583348638390\n" + - " },\n" + - " \"body\": \"Hello from Lambda\",\n" + - " \"pathParameters\": {\n" + - " \"parameter1\": \"value1\"\n" + - " },\n" + - " \"isBase64Encoded\": false,\n" + - " \"stageVariables\": {\n" + - " \"stageVariable1\": \"value1\",\n" + - " \"stageVariable2\": \"value2\"\n" + - " }\n" + - "}"; + private static final String API_GATEWAY_EVENT_V2 = """ + { + "version": "2.0", + "routeKey": "$default", + "rawPath": "/my/path", + "rawQueryString": "parameter1=value1¶meter1=value2&name=Ricky¶meter2=value", + "cookies": [ + "cookie1", + "cookie2" + ], + "headers": { + "header1": "value1", + "header2": "value1,value2" + }, + "queryStringParameters": { + "parameter1": "value1,value2", + "name": "Ricky", + "parameter2": "value" + }, + "requestContext": { + "accountId": "123456789012", + "apiId": "api-id", + "authentication": { + "clientCert": { + "clientCertPem": "CERT_CONTENT", + "subjectDN": "www.example.com", + "issuerDN": "Example issuer", + "serialNumber": "a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1", + "validity": { + "notBefore": "May 28 12:30:02 2019 GMT", + "notAfter": "Aug 5 09:36:04 2021 GMT" + } + } + }, + "authorizer": { + "jwt": { + "claims": { + "claim1": "value1", + "claim2": "value2" + }, + "scopes": [ + "scope1", + "scope2" + ] + } + }, + "domainName": "id.execute-api.us-east-1.amazonaws.com", + "domainPrefix": "id", + "http": { + "method": "POST", + "path": "/my/path", + "protocol": "HTTP/1.1", + "sourceIp": "IP", + "userAgent": "agent" + }, + "requestId": "id", + "routeKey": "$default", + "stage": "$default", + "time": "12/Mar/2020:19:03:58 +0000", + "timeEpoch": 1583348638390 + }, + "body": "Hello from Lambda", + "pathParameters": { + "parameter1": "value1" + }, + "isBase64Encoded": false, + "stageVariables": { + "stageVariable1": "value1", + "stageVariable2": "value2" + } + }"""; private SpringDelegatingLambdaContainerHandler handler; @@ -202,7 +204,7 @@ public void initServletAppTest() throws ContainerInitializationException { } public static Collection data() { - return Arrays.asList(new String[]{API_GATEWAY_EVENT, API_GATEWAY_EVENT_V2}); + return Arrays.asList(API_GATEWAY_EVENT, API_GATEWAY_EVENT_V2); } @MethodSource("data") @@ -281,6 +283,18 @@ public void messageObject_parsesObject_returnsCorrectMessage(String jsonEvent) t assertEquals("test message", result.get("body")); } + @MethodSource("data") + @ParameterizedTest + public void voidPost_returns200(String jsonEvent) throws Exception { + initServletAppTest(); + InputStream targetStream = new ByteArrayInputStream(this.generateHttpRequest(jsonEvent, "POST", + "/void-post", "{\"key\":\"value\"}", false, null)); + ByteArrayOutputStream output = new ByteArrayOutputStream(); + handler.handleRequest(targetStream, output, null); + Map result = mapper.readValue(output.toString(StandardCharsets.UTF_8), Map.class); + assertEquals(200, result.get("statusCode")); + } + @SuppressWarnings({"unchecked" }) @MethodSource("data") @ParameterizedTest diff --git a/aws-serverless-java-container-springboot4/src/test/java/com/amazonaws/serverless/proxy/spring/servletapp/ServletApplication.java b/aws-serverless-java-container-springboot4/src/test/java/com/amazonaws/serverless/proxy/spring/servletapp/ServletApplication.java index b2dc1a315..8ec4d57f2 100644 --- a/aws-serverless-java-container-springboot4/src/test/java/com/amazonaws/serverless/proxy/spring/servletapp/ServletApplication.java +++ b/aws-serverless-java-container-springboot4/src/test/java/com/amazonaws/serverless/proxy/spring/servletapp/ServletApplication.java @@ -22,4 +22,8 @@ public String complexRequest( ) { return gender + "/" + age + "/" + name; } + + @RequestMapping(path = "/void-post", method = RequestMethod.POST) + public void voidPost() { + } }