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

Unexpected content-type can cause two different exceptions depending on the jax-rs resource #36798

Closed
fin-steenbjerg-jyskebank-dk opened this issue Oct 31, 2023 · 5 comments · Fixed by #36910
Labels
area/rest kind/bug Something isn't working
Milestone

Comments

@fin-steenbjerg-jyskebank-dk

Describe the bug

I have been implementing a jax-rs resource in Quarkus which needs to use media type versioning. Unfortunately, Quarkus doesn't seem to be consistent wrt. which exceptions are thrown.

If somebody tries to access the jax-rs resource with an unexpected content-type, two different exceptions are thrown depending on the number of methods implemented inside the REST resource. If the resource only has a single method, the thrown exception is a jakarta.ws.rs.NotSupportedException but when the resource has more than one method an jakarta.ws.rs.WebApplicationException is thrown.

It is not really the biggest problem in the world, but my exception mappers got confused and I ended up spending quite some time debugging my application.

See my post at stackoverflow.

Expected behavior

It should throw jakarta.ws.rs.NotSupportedException in all cases.

Actual behavior

Throws jakarta.ws.rs.NotSupportedException when the jax-rs resource only contains a single method and jakarta.ws.rs.WebApplicationException if the jax-rs resource contains more than one method.

How to Reproduce?

I have added a small application to github illustrating the problem test-reactive-jaxrs. The application is created by https://code.quarkus.io/ and it only uses the extention quarkus-resteasy-reactive-jsonb (and arc). The jax-rs resource is this GreetingResource. If it contains one method then one exception is thrown, if it contains two methods another exception is thrown. The tests are executed by running the test-run.sh script.

If the none-reactive version of the extension (quarkus-resteasy-jsonb) is used, then jakarta.ws.rs.NotSupportedException is thrown in all cases.

Output of uname -a or ver

Linux 6.2.0-36-generic #37~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Mon Oct 9 15:34:04 UTC 2 x86_64 x86_64 x86_64 GNU/Linux

Output of java -version

openjdk version "17.0.8" 2023-07-18

Quarkus version or git rev

3.4.3 (or 3.5.0)

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

Gradle 8.1.1

Additional information

No response

Copy link

quarkus-bot bot commented Nov 2, 2023

/cc @FroMage (resteasy-reactive), @stuartwdouglas (resteasy-reactive)

@geoand
Copy link
Contributor

geoand commented Nov 2, 2023

I will have a look sometime next week

@geoand
Copy link
Contributor

geoand commented Nov 6, 2023

Unfortunately there is not much we can do here as this behavior is tested by the TCK

@geoand geoand closed this as not planned Won't fix, can't repro, duplicate, stale Nov 6, 2023
@geoand geoand added the triage/wontfix This will not be worked on label Nov 6, 2023
@fin-steenbjerg-jyskebank-dk
Copy link
Author

fin-steenbjerg-jyskebank-dk commented Nov 6, 2023

Really, the behaviour of jax-rs changes if you switch to quarkus-resteasy-reactive instead of quarkus-resteasy. In my opinon, jax-rs should always behave the same. Also, I don't think I have ever seen resteasy throw jakarta.ws.rs.WebApplicationException server side but I might be wrong.

@geoand
Copy link
Contributor

geoand commented Nov 6, 2023

That's odd... I'll have another look tomorrow to see what RESTEasy Classic is doing

@geoand geoand removed the triage/wontfix This will not be worked on label Nov 7, 2023
@geoand geoand reopened this Nov 7, 2023
geoand added a commit to geoand/quarkus that referenced this issue Nov 7, 2023
This is not only how RESTEasy Classic behaves,
but also the exception that RESTEasy Reactive
itself uses in other places where media type
mapping fails

Fixes: quarkusio#36798
geoand added a commit that referenced this issue Nov 7, 2023
Use proper exception when media type handling is incorrect
@quarkus-bot quarkus-bot bot added this to the 3.6 - main milestone Nov 7, 2023
DavideD pushed a commit to DavideD/quarkus that referenced this issue Nov 27, 2023
This is not only how RESTEasy Classic behaves,
but also the exception that RESTEasy Reactive
itself uses in other places where media type
mapping fails

Fixes: quarkusio#36798
holly-cummins pushed a commit to holly-cummins/quarkus that referenced this issue Feb 8, 2024
This is not only how RESTEasy Classic behaves,
but also the exception that RESTEasy Reactive
itself uses in other places where media type
mapping fails

Fixes: quarkusio#36798
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/rest kind/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants