micronaut-projects / micronaut-aws

Projects specific to integrating Micronaut and Amazon Web Services (AWS)
Apache License 2.0
87 stars 80 forks source link

io.micronaut.web.router.exceptions.UnsatisfiedBodyRouteException: Required Body [text] not specified #543

Closed codekirukkan closed 4 years ago

codekirukkan commented 4 years ago

Thanks for reporting an issue, please review the task list below before submitting the issue. Your issue report will be closed if the issue is incomplete and the below tasks not completed.

NOTE: If you are unsure about something and the issue is more of a question a better place to ask questions is on Stack Overflow (https://stackoverflow.com/tags/micronaut) or Gitter (https://gitter.im/micronautfw/). DO NOT use the issue tracker to ask questions.

Task List

Steps to Reproduce

  1. Create a new controller
  2. Deployed in AWS Lambda + API Gateway - Maven build
  3. Created a POST request with necessary body and content type in the request

Expected Behaviour

Should respond 200 OK with the given data, However only GET request is working. POST is failing with error. Tried everything from using JSON POJO as well with correct media type at both the request and handler end. However none of the @Body options are working.

Actual Behaviour

Controller code

`@Controller public class PingController {

@Get(uri="/ping")
public String ping(){
    return "pong!!!";

}

@Post(value = "/echo", consumes = MediaType.TEXT_PLAIN) 
String echo(@Size(max = 1024) @Body String text) { 
    return text; 
}

} `

Exception in AWS logs

io.micronaut.web.router.exceptions.UnsatisfiedBodyRouteException: Required Body [text] not specified at io.micronaut.web.router.exceptions.UnsatisfiedRouteException.create(UnsatisfiedRouteException.java:58) ... .... io.micronaut.function.aws.proxy.MicronautLambdaContainerHandler.lambda$handleRequest$8(MicronautLambdaContainerHandler.java:329)

Environment Information

Example Application

graemerocher commented 4 years ago

I ran into this issue and it is specific to using String, if you use byte[] a the body it will be fine. It was fixed as part of this commit https://github.com/micronaut-projects/micronaut-aws/commit/9c7bb57470a8a4d1ea6210403fcd73cf22ee3e8d

graemerocher commented 4 years ago

You should probably try the released 2.1.0.RC1 version of the aws modules which includes the fix