Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RESTEasy Reactive @Context is empty or not mapping correctly #31147

Closed
JakubWylezek opened this issue Feb 14, 2023 · 5 comments
Closed

RESTEasy Reactive @Context is empty or not mapping correctly #31147

JakubWylezek opened this issue Feb 14, 2023 · 5 comments
Labels
area/kotlin area/rest env/windows Impacts Windows machines kind/bug Something isn't working triage/invalid This doesn't seem right

Comments

@JakubWylezek
Copy link

Describe the bug

I'm trying to receive context using @context AwsProxyRequestContext or @context AwsProxyRequest.
Thanks to 2.16.2 Final release, resteasy reactive no longer produce 404.
However now context data is missing.

This is my app code:

@GET
@Path("/hello1")
public String hello(@Context AwsProxyRequestContext context) {
    Gson gson = new GsonBuilder().setPrettyPrinting().create();

    log.info("hello1 " + gson.toJson(context));
    return "hello1";
}

@GET
@Path("/hello2")
public String hello2(@Context AwsProxyRequest contex) {
    Gson gson = new GsonBuilder().setPrettyPrinting().create();

    log.info("HEH " + gson.toJson(contex));
    return "hello2";
}

Logs for lambda AWS:
hello1
image

hello2
image

Dependencies I use:

implementation 'io.quarkus:quarkus-resteasy-reactive'
implementation 'io.quarkus:quarkus-arc'
implementation 'io.quarkus:quarkus-amazon-lambda-rest'

implementation 'io.quarkiverse.amazonservices:quarkus-amazon-s3:1.6.1'
implementation 'software.amazon.awssdk:netty-nio-client:2.19.22'

testImplementation 'io.quarkus:quarkus-junit5'
testImplementation 'io.rest-assured:rest-assured'
testImplementation 'io.quarkus:quarkus-junit5'
implementation 'com.google.code.gson:gson:2.9.1'

Expected behavior

After I changed dependency from

implementation 'io.quarkus:quarkus-resteasy-reactive'

to

implementation 'io.quarkus:quarkus-resteasy'

also using 2.16.2 Final release version, without any changes in code, context data is filled correctly

Logs from lambda AWS:
hello1

image

hello2

image

Actual behavior

No response

How to Reproduce?

No response

Output of uname -a or ver

Linux 5.10.16.3-microsoft-standard-WSL2 #1 SMP Fri Apr 2 22:23:49 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

Output of java -version

openjdk version "11.0.17" 2022-10-18 OpenJDK Runtime Environment (build 11.0.17+8-post-Ubuntu-1ubuntu220.04) OpenJDK 64-Bit Server VM (build 11.0.17+8-post-Ubuntu-1ubuntu220.04, mixed mode, sharing)

GraalVM version (if different from Java)

No response

Quarkus version or git rev

No response

Build tool (ie. output of mvnw --version or gradlew --version)

Gradle 7.5.1 ------------------------------------------------------------ Build time: 2022-08-05 21:17:56 UTC Revision: d1daa0cbf1a0103000b71484e1dbfe096e095918 Kotlin: 1.6.21 Groovy: 3.0.10 Ant: Apache Ant(TM) version 1.10.11 compiled on July 10 2021 JVM: 11.0.18 (Azul Systems, Inc. 11.0.18+10-LTS) OS: Windows 10 10.0 amd64

Additional information

No response

@JakubWylezek JakubWylezek added the kind/bug Something isn't working label Feb 14, 2023
@quarkus-bot quarkus-bot bot added area/kotlin area/rest env/windows Impacts Windows machines labels Feb 14, 2023
@quarkus-bot
Copy link

quarkus-bot bot commented Feb 14, 2023

/cc @FroMage (resteasy-reactive), @Sgitario (resteasy-reactive), @evanchooly (kotlin), @geoand (kotlin,resteasy-reactive), @stuartwdouglas (resteasy-reactive)

@geoand
Copy link
Contributor

geoand commented Feb 14, 2023

This should have been fixed in Quarkus 2.16.2.Final by #30776.

Can you attach a sample application that suffers from the problem?

@Sgitario
Copy link
Contributor

I think that the problem here is that the AwsProxyRequestContext instance in Resteasy Reactive is a proxy of the actual instance. So, the fields of this proxy are null, but when you call any getter, then you will get the correct value.

And gson is only using the fields to generate the JSON, that's why you see it empty.

Instead of using gson, you can use ObjectMapper as:

ObjectMapper objectMapper = new ObjectMapper();
String json = objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(ctx);

And I think you should see all the context now.

@geoand
Copy link
Contributor

geoand commented Feb 15, 2023

Thanks for the analysis @Sgitario.

Closing this as it is not a Quarkus issue

@geoand geoand closed this as not planned Won't fix, can't repro, duplicate, stale Feb 15, 2023
@geoand geoand added the triage/invalid This doesn't seem right label Feb 15, 2023
@geoand
Copy link
Contributor

geoand commented Feb 15, 2023

Aside from the correctness issue mentioned by @Sgitario, you probably want to avoid using Gson and instead opt for Jackson because Jackson is already used for deserialization and including another JSON library will do you no favors in terms of runtime footprint.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/kotlin area/rest env/windows Impacts Windows machines kind/bug Something isn't working triage/invalid This doesn't seem right
Projects
None yet
Development

No branches or pull requests

3 participants