serverless-java-container
serverless-java-container copied to clipboard
Not getting reponse back directly from filter
Serverless Java Container version: 2.0.0
Implementations: Spring Boot 3
Framework version: SpringBoot 3.3.0-SNAPSHOT
Frontend service: HTTP API
Deployment method: SAM
Scenario
I was trying to send response back directly from filter itself for certain condition.
Expected behavior
Was expecting that I will get the response which is provided in code.
Actual behavior
Getting 502 BAD GATEWAY as function got timed out.
Steps to reproduce
It can be reproduce by running this demo application using docker or on linux architecture as a native web app using sam-cli. This demo app build upon base project pet-store-native. Filter created
@Component
public class OutsideSecurityFilter extends OncePerRequestFilter{
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
throws ServletException, IOException {
System.out.println("Outside security filter chain.");
if("OPTIONS".equals(request.getMethod())) {
System.out.println("Inside OPTIONS call");
response.addHeader("Name", "Aniket Saini");
response.setStatus(200);
return;
} else {
filterChain.doFilter(request, response);
}
}
}
To check just make a OPTIONS call on /hello. Or just run following command
curl --request OPTIONS http://127.0.0.1:3000/hello
Full log output
2024-03-04T11:07:03.808Z DEBUG 15 --- [pool-6-thread-1] s.p.s.AwsSpringWebCustomRuntimeEventLoop : New Event received from AWS Gateway: {"body": null, "headers": {"Accept": "*/*", "Host": "127.0.0.1:3000", "User-Agent": "curl/7.68.0", "X-Forwarded-Port": "3000", "X-Forwarded-Proto": "http"}, "httpMethod": "OPTIONS", "isBase64Encoded": false, "multiValueHeaders": {"Accept": ["*/*"], "Host": ["127.0.0.1:3000"], "User-Agent": ["curl/7.68.0"], "X-Forwarded-Port": ["3000"], "X-Forwarded-Proto": ["http"]}, "multiValueQueryStringParameters": null, "path": "/hello", "pathParameters": {"any_path": "hello"}, "queryStringParameters": null, "requestContext": {"accountId": "123456789012", "apiId": "1234567890", "domainName": "127.0.0.1:3000", "extendedRequestId": null, "httpMethod": "OPTIONS", "identity": {"accountId": null, "apiKey": null, "caller": null, "cognitoAuthenticationProvider": null, "cognitoAuthenticationType": null, "cognitoIdentityPoolId": null, "sourceIp": "127.0.0.1", "user": null, "userAgent": "Custom User Agent String", "userArn": null}, "path": "/{any_path+}", "protocol": "HTTP/1.1", "requestId": "a198410f-e7f1-433d-ab4f-354bc0b14f9a", "requestTime": "04/Mar/2024:11:06:50 +0000", "requestTimeEpoch": 1709550410, "resourceId": "123456", "resourcePath": "/{any_path+}", "stage": null}, "resource": "/{any_path+}", "stageVariables": null, "version": "1.0"}
2024-03-04T11:07:03.808Z DEBUG 15 --- [pool-6-thread-1] s.p.s.AwsSpringWebCustomRuntimeEventLoop : Submitting request to the user's web application
Outside security filter chain.
Inside OPTIONS call
Function 'ServerlessWebNativeFunction' timed out after 15 seconds
No response from invoke container for ServerlessWebNativeFunction
Invalid lambda response received: Lambda response must be valid json
2024-03-04 16:37:19 127.0.0.1 - - [04/Mar/2024 16:37:19] "OPTIONS /hello HTTP/1.1" 502 -