aws / aws/serverless-java-container

LambdaContainerHandler - Error while mapping object to RequestType class

Đang mở
#494 3 bình luận 0 reaction 0 người được giao Xem trên GitHub
need feedback
Ngôn ngữ chính
Java
Star
1.6k
Fork
574
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

*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 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 getMono() {
return service.serve()
.collectList()
.map(Capitals::new);
}

@Data
private class Capitals {
final List values;
}
}
```
Service class:

````
@Service
public class AService {

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

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

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

```

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)

```

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Hướng nghiên cứu

Bắt đầu tại LambdaContainerHandler.java:256 và lần theo lệnh gọi ánh xạ request từ StreamLambdaHandler.java:42. Tái hiện request Spring Boot 2 đã được báo cáo bằng payload API Gateway được cung cấp và kiểm tra lý do input đến Jackson ở trạng thái rỗng; hoàn tất nghĩa là endpoint trả về JSON mong đợi với HTTP 200 thay vì 502.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
aws, java, spring-boot
Lĩnh vực
api, backend, cloud
Loại issue
Lỗi
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Cần làm rõ
Mức phù hợp với người mới
25/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.