micronaut-projects / micronaut-aws

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

Changing jackson config causes weird behavior of Lambda request handling #186

Closed sturmm closed 4 years ago

sturmm commented 4 years ago

I found a problem with the whole Lambda handling, when changing the configuration of the default ObjectMapper in Micronaut:

jackson:
  bean-introspection-module: true
  propertyNamingStrategy: SNAKE_CASE
  serializationInclusion: NON_ABSENT
  dateFormat: yyyy-MM-dd'T'HH:mm:ss:SSSZ
  timeZone: CET

This is because the MicronautLambdaContainerHandler uses the global ObjectMapper. I would expect, that the framework would use a seperate one, which is configured to just met the Lambda specifications or at least that the properties of classes used for Lambda API (like AwsProxyRequest) are annotated with @JsonProperty etc.

Im using Micronaut 1.2.9

alvarosanchez commented 4 years ago

What is the error that you are getting?

sturmm commented 4 years ago

e.g.

com.amazonaws.serverless.exceptions.InvalidRequestEventException: Invalid Request: Illegal character in path at index 13: https://null/{proxy+}
at io.micronaut.function.aws.proxy.MicronautRequestReader.readRequest(MicronautRequestReader.java:123)
at io.micronaut.function.aws.proxy.MicronautRequestReader.readRequest(MicronautRequestReader.java:48)
at io.micronaut.function.aws.proxy.AbstractLambdaContainerHandler.proxy(AbstractLambdaContainerHandler.java:204)
at io.micronaut.function.aws.runtime.MicronautLambdaRuntime.startRuntimeApiEventLoop(MicronautLambdaRuntime.java:131)
at io.micronaut.function.aws.runtime.MicronautLambdaRuntime.main(MicronautLambdaRuntime.java:77)
Caused by: java.lang.IllegalArgumentException: Illegal character in path at index 13: https://null/{proxy+}
at java.net.URI.create(URI.java:852)
at io.micronaut.function.aws.proxy.MicronautAwsProxyRequest.getUri(MicronautAwsProxyRequest.java:193)
at io.micronaut.http.HttpRequest.getPath(HttpRequest.java:85)
at io.micronaut.function.aws.proxy.MicronautRequestReader.readRequest(MicronautRequestReader.java:79)
Caused by: java.net.URISyntaxException: Illegal character in path at index 13: https://null/{proxy+}
at java.net.URI$Parser.fail(URI.java:2848)
at java.net.URI$Parser.checkChars(URI.java:3021)
at java.net.URI$Parser.parseHierarchical(URI.java:3105)
at java.net.URI$Parser.parse(URI.java:3053)
at java.net.URI.<init>(URI.java:588)
at java.net.URI.create(URI.java:850)
... 7 more

After I got an idea what happend I tried the some test events in the AWS Lambda console which lead me to NullPointerExceptions of properties that should not be null e.g. the AwsRequestContext of AwsProxyRequest where my test event was:

{
  "resource": "/env",
  "path": "/env",
  "httpMethod": "GET",
  "requestContext": {
    "resource": "/env",
    "path": "/env"
  }
}

ThEn I replaced camelCase named properties with snake_case named (e.g. requestContext with request_context) and came a step further in the code.

But just from reading the code (with very basic knowledge of Micronaut) it seems, that the global ObjectMapper is used for parsing JSON into AwsProxyRequest which then lead to errors when I change the jackson config in application.yml.

mayurtanna commented 3 years ago

@alvarosanchez - I am facing something similar issue for response where I am trying to override ObjectMapper configuration to return null value keys in the response. Here is the bug link: https://github.com/micronaut-projects/micronaut-aws/issues/1077. Can you please help ?

alvarosanchez commented 3 years ago

@mayurtanna sorry but I'm no longer actively working on Micronaut. Someone else from @micronaut-projects/core-developers should be able to help.

mayurtanna commented 3 years ago

@alvarosanchez okay, no worries. Thank you.

@sdelamo - Hi, would you be able to help please ?