Spring 云函数路由 api 网关空指针异常
Spring cloud function routing api gateway null pointer exception
我在使用 API 网关 headers 进行路由时遇到问题。我正在使用 org.springframework.cloud.function.adapter.aws.FunctionInvoker::handleRequest 作为处理程序请求。我有两个功能,它们在本地工作。如果我设置环境变量,它们就会工作。
如果我使用 API 网关 headers(spring.cloud.function.definition:小写),我得到:
{
"errorMessage": "java.lang.NullPointerException",
"errorType": "java.lang.NullPointerException",
"stackTrace": [
"org.springframework.cloud.function.adapter.aws.AWSLambdaUtils.generateMessage(AWSLambdaUtils.java:123)",
"org.springframework.cloud.function.adapter.aws.FunctionInvoker.handleRequest(FunctionInvoker.java:105)",
"java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)",
"java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)",
"java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)",
"java.base/java.lang.reflect.Method.invoke(Unknown Source)"
]
}
重现问题的示例代码在这里:https://github.com/cygi/cloudexample
POM 基于 Spring Cloud Function 代码库中的示例(示例代码 (https://github.com/spring-cloud/spring-cloud-function/tree/main/spring-cloud-function-samples/function-sample-aws-routing)。Spring Cloud Function 版本为 3.2.1(示例有一个 SNAPSHOT 版本,即使用 JAVA 11,这在 AWS Lambda 中不可用,至少没有 docker).
恢复到 Spring Cloud Function 3.1.6 已解决问题。
AWS Lambda 测试活动:
{
"body": "foo",
"httpMethod": "POST",
"isBase64Encoded": false,
"headers": {
"spring.cloud.function.definition": "uppercase"
}
}
3.2.2 的结果
{
"statusCode": 417,
"headers": null,
"body": "Failed to establish route, since neither were provided: 'spring.cloud.function.definition' as Message header or as application property or 'spring.cloud.function.routing-expression' as application property."
}
3.1.6 的结果
{
"isBase64Encoded": false,
"headers": {
"id": "758c1873-9377-25af-5ca2-84f55710ff2a",
"contentType": "application/json",
"timestamp": "1644500775689"
},
"body": "\"bbbb\"",
"statusCode": 200
}
我在使用 API 网关 headers 进行路由时遇到问题。我正在使用 org.springframework.cloud.function.adapter.aws.FunctionInvoker::handleRequest 作为处理程序请求。我有两个功能,它们在本地工作。如果我设置环境变量,它们就会工作。
如果我使用 API 网关 headers(spring.cloud.function.definition:小写),我得到:
{
"errorMessage": "java.lang.NullPointerException",
"errorType": "java.lang.NullPointerException",
"stackTrace": [
"org.springframework.cloud.function.adapter.aws.AWSLambdaUtils.generateMessage(AWSLambdaUtils.java:123)",
"org.springframework.cloud.function.adapter.aws.FunctionInvoker.handleRequest(FunctionInvoker.java:105)",
"java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)",
"java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)",
"java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)",
"java.base/java.lang.reflect.Method.invoke(Unknown Source)"
]
}
重现问题的示例代码在这里:https://github.com/cygi/cloudexample
POM 基于 Spring Cloud Function 代码库中的示例(示例代码 (https://github.com/spring-cloud/spring-cloud-function/tree/main/spring-cloud-function-samples/function-sample-aws-routing)。Spring Cloud Function 版本为 3.2.1(示例有一个 SNAPSHOT 版本,即使用 JAVA 11,这在 AWS Lambda 中不可用,至少没有 docker).
恢复到 Spring Cloud Function 3.1.6 已解决问题。
AWS Lambda 测试活动:
{
"body": "foo",
"httpMethod": "POST",
"isBase64Encoded": false,
"headers": {
"spring.cloud.function.definition": "uppercase"
}
}
3.2.2 的结果
{
"statusCode": 417,
"headers": null,
"body": "Failed to establish route, since neither were provided: 'spring.cloud.function.definition' as Message header or as application property or 'spring.cloud.function.routing-expression' as application property."
}
3.1.6 的结果
{
"isBase64Encoded": false,
"headers": {
"id": "758c1873-9377-25af-5ca2-84f55710ff2a",
"contentType": "application/json",
"timestamp": "1644500775689"
},
"body": "\"bbbb\"",
"statusCode": 200
}