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

Multipart upload in subresource fails in quarkus-rest. #44922

Open
bjornpalmqvist opened this issue Dec 4, 2024 · 12 comments
Open

Multipart upload in subresource fails in quarkus-rest. #44922

bjornpalmqvist opened this issue Dec 4, 2024 · 12 comments
Labels
area/rest kind/bug Something isn't working

Comments

@bjornpalmqvist
Copy link

Describe the bug

When using subresources multipart upload fails with 415, Unsupported Media Type, as http error code.

Expected behavior

File upload works as expected.

Actual behavior

Getting 415, Unsupported Media Type, http status.

How to Reproduce?

Make a main resource and have it expose a subresource that consumes multipart/form-data.

See code-with-quarkus.zip example that reproduces the problem.

Output of uname -a or ver

Linux LAPTOP-2P262G2R 5.15.167.4-microsoft-standard-WSL2 #1 SMP Tue Nov 5 00:21:55 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux

Output of java -version

openjdk 21.0.5 2024-10-15 LTS OpenJDK Runtime Environment Temurin-21.0.5+11 (build 21.0.5+11-LTS) OpenJDK 64-Bit Server VM Temurin-21.0.5+11 (build 21.0.5+11-LTS, mixed mode, sharing)

Quarkus version or git rev

3.17.2

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

Apache Maven 3.9.8 (36645f6c9b5079805ea5009217e36f2cffd34256) Maven home: /home/zipper/.m2/wrapper/dists/apache-maven-3.9.8-bin/337e6d14/apache-maven-3.9.8 Java version: 21.0.5, vendor: Eclipse Adoptium, runtime: /home/zipper/.sdkman/candidates/java/21.0.5-tem Default locale: en, platform encoding: UTF-8 OS name: "linux", version: "5.15.167.4-microsoft-standard-wsl2", arch: "amd64", family: "unix"

Additional information

The bug is also present in earlier versions.

@bjornpalmqvist bjornpalmqvist added the kind/bug Something isn't working label Dec 4, 2024
Copy link

quarkus-bot bot commented Dec 5, 2024

/cc @FroMage (rest), @stuartwdouglas (rest)

@geoand
Copy link
Contributor

geoand commented Dec 5, 2024

I would be surprised if this is a bug to be honest, as I am pretty sure that @Consumes needs to be on SubtestResource and not on MultipartResource.

@FroMage do you remember if @Produces and @Consumes should be placed on the subresource or the original resource?

@geoand geoand added kind/question Further information is requested and removed kind/bug Something isn't working labels Dec 5, 2024
@bjornpalmqvist
Copy link
Author

With legacy rest framework that implementaion work, but when I uppgraded to the new rest implementation it stopped working.

@FroMage
Copy link
Member

FroMage commented Dec 5, 2024

As I suspected, it's due to the @Consumes(JSON) on the intermediate endpoint. That will cause the multipart payload to be rejected.

If I remove it, the test passes.

Now, I'd have to check the spec to see whether @Consumes should be ignored on sub-resource locators.

@FroMage
Copy link
Member

FroMage commented Dec 5, 2024

According to https://jakarta.ee/specifications/restful-ws/4.0/jakarta-restful-ws-spec-4.0#request_matching we should do the matching first based on path to find the candidate methods.

Once we have all the methods (and this will have invoked the locator method to obtain the locator instance on which to find the end method), we then check that the method accepts the right HTTP method, and content types.

This implies that we first find the endpoint method (through every matching locator) and only at the end do we check for that method's content types.

From what I understand of this, only the method @Produces/Consumes annotations of the end method, and if missing, its containing class should be considered.

In this case, the @Consumes(JSON) of SubtestResource should be completely ignored and only the one defined on MultipartResource should be considered.

Sorry :(

@geoand geoand closed this as completed Dec 5, 2024
@FroMage
Copy link
Member

FroMage commented Dec 5, 2024

Mmm, completed by what?

I meant that our implementation should be fixed to ignore the @Consumes annotation on the SubtestResource and only respect the one from MultipartResource, sorry if I wasn't clear. This sounds like a bug :(

@geoand
Copy link
Contributor

geoand commented Dec 5, 2024

I read your comments the exact opposite way.

Reopening

@geoand geoand reopened this Dec 5, 2024
@geoand geoand added kind/bug Something isn't working and removed kind/question Further information is requested labels Dec 5, 2024
@geoand
Copy link
Contributor

geoand commented Dec 6, 2024

@FroMage do you have a fix in mind?

@FroMage
Copy link
Member

FroMage commented Dec 6, 2024

I read your comments the exact opposite way.

Sorry I should have been clearer, obviously :(

Do you have a fix in mind?

I don't remember how we handle locators, but I suppose that in the case of locator matches we have to move the content-type check steps further down the chain.

@geoand
Copy link
Contributor

geoand commented Dec 6, 2024

I don't remember how we handle locators

I don't think I ever knew 😆

@FroMage
Copy link
Member

FroMage commented Dec 6, 2024

Honestly, I'm still surprised anytime someone uses them.

@geoand
Copy link
Contributor

geoand commented Dec 6, 2024

Same :)

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

No branches or pull requests

3 participants