LambdaContainerHandler - Error while mapping object to RequestType class

未關閉
#494 3 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

還沒有人認領這個 Issue。

評估

難度
4/5
預估耗時
3-5 天
新手友好度
25/100
Issue 類型
缺陷
描述清晰度
需要釐清
活躍度
停滯
技術堆疊
aws, java, spring-boot
領域
api, backend, cloud

研究方向

從 LambdaContainerHandler.java:256 開始,追蹤來自 StreamLambdaHandler.java:42 的請求映射呼叫。使用提供的 API Gateway payload 重現回報的 Spring Boot 2 請求,並檢查為什麼輸入到達 Jackson 時是空的;完成的標準是 endpoint 回傳預期的 JSON,且狀態為 HTTP 200 而不是 502。

由索引模型根據 Issue 內容生成。

描述

need feedback

To help us debug your issue fill in the basic information below using the options provided

Serverless Java Container version: 1.9

Implementations: Spring Boot 2

Framework version: SpringBoot 2.7.6.RELEASE

Frontend service: REST API

Deployment method: Console

Scenario

Describe what you are trying to accomplish
I have created an AP Gateway REST API which proxies to a Springboot Java application exposing differnet endpoints, mostly returning Monos and Fluxes. Payload inputted is below.
{ "resource": "/{proxy+}", "path": "/capitals", "httpMethod": "GET", "headers": { "Accept": "application/json", "Accept-Encoding": "gzip, deflate", "Cache-Control": "no-cache", "Content-Type": "application/json", "Host": "xxxxxxx.execute-api.eu-north-1.amazonaws.com", "Postman-Token": "zzzzzzz-4c21-4a6b-a71a-b5d39ce42332", "User-Agent": "PostmanRuntime/7.28.4", "X-Amzn-Trace-Id": "Root=1-638f4d15-626c445233b14ceb2f567363", "X-BlueCoat-Via": "0drrr83fc54be448", "X-Forwarded-For": "1.2.3.4", "X-Forwarded-Port": "443", "X-Forwarded-Proto": "https" }, "multiValueHeaders": { "Accept": [ "application/json" ], "Accept-Encoding": [ "gzip, deflate" ], "Cache-Control": [ "no-cache" ], "Content-Type": [ "application/json" ], "Host": [ "ay9vitrep4.execute-api.eu-north-1.amazonaws.com" ], "Postman-Token": [ "zzzzzzz-4c21-4a6b-a71a-b5d39ce42332" ], "User-Agent": [ "PostmanRuntime/7.28.4" ], "X-Amzn-Trace-Id": [ "Root=1-638f4d15-626c445233b14ceb2f567363" ], "X-BlueCoat-Via": [ "ggg3fc54be448" ], "X-Forwarded-For": [ "1.2.3.4" ], "X-Forwarded-Port": [ "443" ], "X-Forwarded-Proto": [ "https" ] }, "queryStringParameters": null, "multiValueQueryStringParameters": null, "pathParameters": { "proxy": "capitals" }, "stageVariables": null, "requestContext": { "resourceId": "sm5w9j", "resourcePath": "/{proxy+}", "httpMethod": "GET", "extendedRequestId": "cuj7cEsTgi0FkCA=", "requestTime": "06/Dec/2022:14:09:25 +0000", "path": "/dev/capitals", "accountId": "123456789", "protocol": "HTTP/1.1", "stage": "dev", "domainPrefix": "ay9vitrep4", "requestTimeEpoch": 1670335765833, "requestId": "50facc59-b889-44a0-8a58-f86431bf0897", "identity": { "cognitoIdentityPoolId": null, "accountId": null, "cognitoIdentityId": null, "caller": null, "sourceIp": "1.2.3.4", "principalOrgId": null, "accessKey": null, "cognitoAuthenticationType": null, "cognitoAuthenticationProvider": null, "userArn": null, "userAgent": "PostmanRuntime/7.28.4", "user": null }, "domainName": "xxxxxxxxx.execute-api.eu-north-1.amazonaws.com", "apiId": "xxxxxxxx" }, "body": null, "isBase64Encoded": false }

Nevertheless, when executing the endpoint, the call fails as seems that above payload cannot be mapped into a RequestType class (which is an AWSProxyRequest)

[main] ERROR com.amazonaws.serverless.proxy.internal.LambdaContainerHandler - Error while mapping object to RequestType class
  | 2022-12-06T15:38:16.811+01:00 | com.fasterxml.jackson.databind.exc.MismatchedInputException: No content to map due to end-of-input

Expected behavior

Describe how you would expect the application to behave
Json Payload should be returned with 200 response

Actual behavior

Describe what you are seeing instead
Response returns 502 with this error inCloudwatch:

[main] ERROR com.amazonaws.serverless.proxy.internal.LambdaContainerHandler - Error while mapping object to RequestType class   | 2022-12-06T15:38:16.811+01:00 | com.fasterxml.jackson.databind.exc.MismatchedInputException: No content to map due to end-of-input

Steps to reproduce

Provide code samples we can use to reproduce the issue as part of our integration tests. If there is a public repository for the misbehaving application link to it here

  1. Added aws-serverless-java-container springboot2 library in pom, version 1.9
    2)Added LambdaHandler as below
public class StreamLambdaHandler implements RequestStreamHandler {
    private static SpringBootLambdaContainerHandler<AwsProxyRequest, AwsProxyResponse> handler;
    static {
        try {
            handler = SpringBootLambdaContainerHandler.getAwsProxyHandler(Application.class);
            // If you are using HTTP APIs with the version 2.0 of the proxy model, use the getHttpApiV2ProxyHandler
            // method: handler = SpringBootLambdaContainerHandler.getHttpApiV2ProxyHandler(Application.class);
        } catch (ContainerInitializationException e) {
            // if we fail here. We re-throw the exception to force another cold start
            e.printStackTrace();
            throw new RuntimeException("Could not initialize Spring Boot application", e);
        }
    }

    @Override
    public void handleRequest(InputStream inputStream, OutputStream outputStream, Context context)
            throws IOException {
        handler.proxyStream(inputStream, outputStream, context);
    }
}

3)Add typical Application (annotated with @SpringBootpplication) + a RestController with this class:

@RestController
public class Resource {

    private AService service;

    public Resource1(AService service) {
        this.service = service;
    }
    
    @GetMapping("/capitals")
    public Mono<Capitals> getMono() {
        return service.serve()
                .collectList()
                .map(Capitals::new);
    }
    
    @Data
    private class Capitals {
        final List<String> values;
    }
}

Service class:

@Service
public class AService {

    public static final List<String> capitals = Arrays.asList("Copenhagen", "Rome", "Berlin", "Reykjavik");

    public Flux<String> serve() {
        return Flux.fromIterable(capitals);
    }
}
```



## Full log output
*Paste the full log output from the Lambda function's CloudWatch logs*

```
<html>
<body>
<!--StartFragment-->

2022-12-06T15:38:16.811+01:00 | 14:38:16.811 [main] ERROR com.amazonaws.serverless.proxy.internal.LambdaContainerHandler - Error while mapping object to RequestType class
-- | --
  | 2022-12-06T15:38:16.811+01:00 | com.fasterxml.jackson.databind.exc.MismatchedInputException: No content to map due to end-of-input
  | 2022-12-06T15:38:16.811+01:00 | at [Source: (ByteArrayInputStream); line: 1, column: 0]
  | 2022-12-06T15:38:16.811+01:00 | at com.fasterxml.jackson.databind.exc.MismatchedInputException.from(MismatchedInputException.java:59)
  | 2022-12-06T15:38:16.811+01:00 | at com.fasterxml.jackson.databind.DeserializationContext.reportInputMismatch(DeserializationContext.java:1741)
  | 2022-12-06T15:38:16.811+01:00 | at com.fasterxml.jackson.databind.ObjectReader._initForReading(ObjectReader.java:359)
  | 2022-12-06T15:38:16.811+01:00 | at com.fasterxml.jackson.databind.ObjectReader._bindAndClose(ObjectReader.java:2041)
  | 2022-12-06T15:38:16.811+01:00 | at com.fasterxml.jackson.databind.ObjectReader.readValue(ObjectReader.java:1427)
  | 2022-12-06T15:38:16.811+01:00 | at com.amazonaws.serverless.proxy.internal.LambdaContainerHandler.proxyStream(LambdaContainerHandler.java:256)
  | 2022-12-06T15:38:16.811+01:00 | at com.nordea.ndf.lambda.StreamLambdaHandler.handleRequest(StreamLambdaHandler.java:42)
  | 2022-12-06T15:38:16.811+01:00 | at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  | 2022-12-06T15:38:16.811+01:00 | at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
  | 2022-12-06T15:38:16.811+01:00 | at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
  | 2022-12-06T15:38:16.811+01:00 | at java.base/java.lang.reflect.Method.invoke(Unknown Source)
  | 2022-12-06T15:38:16.811+01:00 | at lambdainternal.EventHandlerLoader$StreamMethodRequestHandler.handleRequest(EventHandlerLoader.java:375)
  | 2022-12-06T15:38:16.811+01:00 | at lambdainternal.EventHandlerLoader$2.call(EventHandlerLoader.java:899)
  | 2022-12-06T15:38:16.811+01:00 | at lambdainternal.AWSLambda.startRuntime(AWSLambda.java:268)
  | 2022-12-06T15:38:16.811+01:00 | at lambdainternal.AWSLambda.startRuntime(AWSLambda.java:206)
  | 2022-12-06T15:38:16.811+01:00 | at lambdainternal.AWSLambda.main(AWSLambda.java:200)
  | 2022-12-06T15:38:16.811+01:00 | 14:38:16.811 [main] ERROR com.amazonaws.serverless.proxy.AwsProxyExceptionHandler - Called exception handler for:
  | 2022-12-06T15:38:16.811+01:00 | com.fasterxml.jackson.databind.exc.MismatchedInputException: No content to map due to end-of-input
  | 2022-12-06T15:38:16.811+01:00 | at [Source: (ByteArrayInputStream); line: 1, column: 0]
  | 2022-12-06T15:38:16.811+01:00 | at com.fasterxml.jackson.databind.exc.MismatchedInputException.from(MismatchedInputException.java:59)
  | 2022-12-06T15:38:16.811+01:00 | at com.fasterxml.jackson.databind.DeserializationContext.reportInputMismatch(DeserializationContext.java:1741)
  | 2022-12-06T15:38:16.811+01:00 | at com.fasterxml.jackson.databind.ObjectReader._initForReading(ObjectReader.java:359)
  | 2022-12-06T15:38:16.811+01:00 | at com.fasterxml.jackson.databind.ObjectReader._bindAndClose(ObjectReader.java:2041)
  | 2022-12-06T15:38:16.811+01:00 | at com.fasterxml.jackson.databind.ObjectReader.readValue(ObjectReader.java:1427)
  | 2022-12-06T15:38:16.811+01:00 | at com.amazonaws.serverless.proxy.internal.LambdaContainerHandler.proxyStream(LambdaContainerHandler.java:256)
  | 2022-12-06T15:38:16.811+01:00 | at com.nordea.ndf.lambda.StreamLambdaHandler.handleRequest(StreamLambdaHandler.java:42)
  | 2022-12-06T15:38:16.811+01:00 | at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  | 2022-12-06T15:38:16.811+01:00 | at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
  | 2022-12-06T15:38:16.811+01:00 | at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
  | 2022-12-06T15:38:16.811+01:00 | at java.base/java.lang.reflect.Method.invoke(Unknown Source)
  | 2022-12-06T15:38:16.811+01:00 | at lambdainternal.EventHandlerLoader$StreamMethodRequestHandler.handleRequest(EventHandlerLoader.java:375)
  | 2022-12-06T15:38:16.811+01:00 | at lambdainternal.EventHandlerLoader$2.call(EventHandlerLoader.java:899)
  | 2022-12-06T15:38:16.811+01:00 | at lambdainternal.AWSLambda.startRuntime(AWSLambda.java:268)
  | 2022-12-06T15:38:16.811+01:00 | at lambdainternal.AWSLambda.startRuntime(AWSLambda.java:206)
  | 2022-12-06T15:38:16.811+01:00 | at lambdainternal.AWSLambda.main(AWSLambda.java:200)
  | 2022-12-06T15:38:16.812+01:00 | com.fasterxml.jackson.databind.exc.MismatchedInputException: No content to map due to end-of-input
  | 2022-12-06T15:38:16.812+01:00 | at [Source: (ByteArrayInputStream); line: 1, column: 0]
  | 2022-12-06T15:38:16.812+01:00 | at com.fasterxml.jackson.databind.exc.MismatchedInputException.from(MismatchedInputException.java:59)
  | 2022-12-06T15:38:16.812+01:00 | at com.fasterxml.jackson.databind.DeserializationContext.reportInputMismatch(DeserializationContext.java:1741)
  | 2022-12-06T15:38:16.812+01:00 | at com.fasterxml.jackson.databind.ObjectReader._initForReading(ObjectReader.java:359)
  | 2022-12-06T15:38:16.812+01:00 | at com.fasterxml.jackson.databind.ObjectReader._bindAndClose(ObjectReader.java:2041)
  | 2022-12-06T15:38:16.812+01:00 | at com.fasterxml.jackson.databind.ObjectReader.readValue(ObjectReader.java:1427)
  | 2022-12-06T15:38:16.812+01:00 | at com.amazonaws.serverless.proxy.internal.LambdaContainerHandler.proxyStream(LambdaContainerHandler.java:256)
  | 2022-12-06T15:38:16.812+01:00 | at com.nordea.ndf.lambda.StreamLambdaHandler.handleRequest(StreamLambdaHandler.java:42)
  | 2022-12-06T15:38:16.812+01:00 | at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  | 2022-12-06T15:38:16.812+01:00 | at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
  | 2022-12-06T15:38:16.828+01:00 | at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
  | 2022-12-06T15:38:16.848+01:00 | at java.base/java.lang.reflect.Method.invoke(Unknown Source)
  | 2022-12-06T15:38:16.848+01:00 | at lambdainternal.EventHandlerLoader$StreamMethodRequestHandler.handleRequest(EventHandlerLoader.java:375)
  | 2022-12-06T15:38:16.848+01:00 | at lambdainternal.EventHandlerLoader$2.call(EventHandlerLoader.java:899)
  | 2022-12-06T15:38:16.848+01:00 | at lambdainternal.AWSLambda.startRuntime(AWSLambda.java:268)
  | 2022-12-06T15:38:16.848+01:00 | at lambdainternal.AWSLambda.startRuntime(AWSLambda.java:206)

<!--EndFragment-->
</body>
</html>
```
主要語言
Java
星號
1.6k
分支
575
平均合併
1 天 15 小時
30 天內合併 PR
12

環境準備

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

aws/serverless-java-container 的其他 Issue

查看 aws/serverless-java-container 的全部 Issue

相似的 Issue

更多 Java Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。