在具有代理集成的 Micronaut Lambda 中,我有一个控制器应该将 JSON 内容解组为 Ping 对象:
@Controller("/ping")
class PingController {
private val logger = LoggerFactory.getLogger(javaClass)
@Get("/")
fun getPing(@Header("Host") host: String): Ping {
logger.info("Host Header {}", host)
return Ping("myPing")
}
@Post("/")
@Status(HttpStatus.CREATED)
fun createPing(@Body ping: Ping): Ping {
logger.info("ping {}", ping)
return ping
}
}
如果我将此应用程序作为本地 micronaut webapp 启动,我可以成功执行此操作:
curl -X POST localhost:8080/ping -d '{"value": "myvalue"}' -H "Content-type: application/json"
日志信息:
INFO m.aws.api2.poc.PingController - ping Ping(value=myvalue)
但是,当从 AWS API Manager 调用此控制器方法时,传递 Content-Type 标头和正文信息...
... 它失败:
14:56:18
io.micronaut.web.router.exceptions.UnsatisfiedRouteException: Required argument [Ping ping] not specified
14:56:18
at io.micronaut.web.router.AbstractRouteMatch.execute(AbstractRouteMatch.java:279)
14:56:18
at io.micronaut.web.router.RouteMatch.execute(RouteMatch.java:122)
14:56:18
at io.micronaut.function.aws.proxy.MicronautLambdaContainerHandler.lambda$null$1(MicronautLambdaContainerHandler.java:240)
14:56:18
at io.reactivex.internal.operators.flowable.FlowableDefer.subscribeActual(FlowableDefer.java:35)
14:56:18
at io.reactivex.Flowable.subscribe(Flowable.java:14805)
14:56:18
at io.reactivex.Flowable.subscribe(Flowable.java:14752)
14:56:18
at io.micronaut.reactive.rxjava2.RxInstrumentedFlowable.subscribeActual(RxInstrumentedFlowable.java:68)
奇怪的是Ping
,调用中对象的编组@Get
既可以用作 webapp,也可以用作 lambda。
我在 Github 上传了一个示例项目:https ://github.com/codependent/micronaut-aws-lambda-proxy