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 - mapping MULTIPART_FORM_DATA to request body don't work #28782

Closed
michalvavrik opened this issue Oct 24, 2022 · 26 comments · Fixed by #28856
Closed

RESTEasy Reactive - mapping MULTIPART_FORM_DATA to request body don't work #28782

michalvavrik opened this issue Oct 24, 2022 · 26 comments · Fixed by #28856
Labels
area/rest kind/bug Something isn't working
Milestone

Comments

@michalvavrik
Copy link
Member

michalvavrik commented Oct 24, 2022

Describe the bug

with #27526 in place, my multiplart form data request body is always null. My endpoint looks like:

    // resource method
    @POST
    @Path("/echo")
    @Consumes(MediaType.MULTIPART_FORM_DATA)
    @Produces(MediaType.TEXT_PLAIN)
    public String echo(String requestBody) {
        return requestBody;
    }

same situation is for wrapper

    // resource method
    @POST
    @Consumes(MediaType.MULTIPART_FORM_DATA)
    @Produces(MediaType.TEXT_PLAIN)
    @Path("/upload-multipart")
    @Blocking
    public String uploadMultipart(FileWrapper body) {
        deathRow.add(body.file);
        return utils.getSum(body.file.getAbsoluteFile().toPath());
    }
...
    @RegisterForReflection
    public class FileWrapper {
        @RestForm("file")
        @PartType(MediaType.APPLICATION_OCTET_STREAM)
        public File file;
    
        @RestForm("name")
        @PartType(MediaType.TEXT_PLAIN)
        public String name;
    }

Expected behavior

  • Provide a way how I can map the request to the String (ideally OOTB).
  • Make docs dummy proof (customize docs for me).

Actual behavior

requestBody is always null. body is not null but its fields are null.

How to Reproduce?

Reproducer:

Steps to reproduce the behavior:

  1. git clone https://github.com/quarkus-qe/quarkus-test-suite.git
  2. cases
  • cd quarkus-test-suite/http/jaxrs-reactive && mvn clean verify -Dit.test=MultipartClientIT
  • cd quarkus-test-suite/http/rest-client-reactive && mvn clean verify -Dit.test=LargeFileHandlingIT#uploadMultipart

Output of uname -a or ver

No response

Output of java -version

No response

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)

No response

Additional information

No response

@michalvavrik michalvavrik added the kind/bug Something isn't working label Oct 24, 2022
@quarkus-bot
Copy link

quarkus-bot bot commented Oct 24, 2022

/cc @FroMage, @geoand, @stuartwdouglas

@michalvavrik michalvavrik changed the title RESTEasy Reactive - can't map RESTEasy Reactive - can't map MULTIPART_FORM_DATA to String body Oct 24, 2022
@michalvavrik michalvavrik changed the title RESTEasy Reactive - can't map MULTIPART_FORM_DATA to String body RESTEasy Reactive - mapping MULTIPART_FORM_DATA to request body don't work Oct 24, 2022
@michalvavrik
Copy link
Member Author

michalvavrik commented Oct 24, 2022

@FroMage @geoand updated issue desc. as I found another issue and they are pretty similar

@geoand
Copy link
Contributor

geoand commented Oct 24, 2022

Thanks!

@FroMage can you please take a look at this? It would be great to have this fixed for the first CR if possible

@FroMage
Copy link
Member

FroMage commented Oct 24, 2022

Yes, this must be related to the multipart change. I'll look.

@FroMage
Copy link
Member

FroMage commented Oct 24, 2022

OK, so the first good news is that if I add these tests to the RESTEasy Reactive test suite, they pass.

@FroMage
Copy link
Member

FroMage commented Oct 24, 2022

Perhaps it's a client issue then, because I see that's involved.

@FroMage
Copy link
Member

FroMage commented Oct 24, 2022

I guess the @QuarkusScenario runs things via a different VM, making this hard to debug :(

@FroMage
Copy link
Member

FroMage commented Oct 24, 2022

OK, I can reproduce it outside the QE tests. It appears to be a problem with the client indeed, not sending anything.

@FroMage
Copy link
Member

FroMage commented Oct 24, 2022

Huh. So, that's embarassing… It appears BeanParamParser doesn't support the @Rest* annotations, which means on the client side only the JAX-RS annotations are supported for bean params. How we did not notice that before, I wonder. I'll fix this ASAP.

@michalvavrik
Copy link
Member Author

Thank you

@FroMage
Copy link
Member

FroMage commented Oct 25, 2022

This is the gift issue that keeps on giving.

So apparently, on the header we auto-hyphenate headers, so @RestHeader String fooBar is equivalent to @RestHeader("foo-Bar") String fooBar, which is almost useful, I guess, though the initial letter should be capitalised to be useful, as specified in the original issue: #13665. But this isn't done on the client, so it's not symmetrical.

And, since we designed @RestHeader (and others) for the server, we allowed it for fields and parameters, but not properties (methods). And the client allows and supports the original @HeaderParam on properties as well, which I can notice in @BeanParam tests. Pretty sure the server doesn't support properties. But the client does. What do you think of that @geoand ? Should I file an issue?

@geoand
Copy link
Contributor

geoand commented Oct 25, 2022

Pretty sure the server doesn't support properties

Not sure I am following what you mean here. Can you please elaborate?

@FroMage
Copy link
Member

FroMage commented Oct 25, 2022

Well, given that @RestHeader (and the rest) are not allowed on methods, I don't think the server side supports them being defined on @BeanParam or endpoint properties. Now that I think about it, I'm not even sure we support @HeaderParam on those either, even though these are allowed on methods.

@geoand
Copy link
Contributor

geoand commented Oct 25, 2022

I must be missing something entirely as I don't understand what you mean by @RestHeader (and the rest) are not allowed on methods

@FroMage
Copy link
Member

FroMage commented Oct 25, 2022

You must be as incredulous as I was:

@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.FIELD, ElementType.PARAMETER })
public @interface RestHeader {
    String value() default "";
}

Notice the missing ElementType.METHOD ;)

@FroMage
Copy link
Member

FroMage commented Oct 25, 2022

Amazingly, the spec doesn't really mention if those @*Param annotations should be on the getter or the setter, but it gives one example of them being on the setter. I suppose for the server, this makes sense. Less so for the client. Pffff…

@geoand
Copy link
Contributor

geoand commented Oct 25, 2022

Oh... Now I see...

Yeah, putting them on a method was not something we really envisioned

@FroMage
Copy link
Member

FroMage commented Oct 25, 2022

But apparently people do that, they put them on setters for entity resources, and bean params. For the server. And on the client, they put them on getters I guess, of bean params. And on multipart classes, which are now treated like bean params.

@geoand
Copy link
Contributor

geoand commented Oct 25, 2022

Darn... I guess we need to formally support it then

@FroMage
Copy link
Member

FroMage commented Oct 25, 2022

Well, I will start with filing an issue, then we can wait for people to need that. Seems pretty useless IMO.

@geoand
Copy link
Contributor

geoand commented Oct 25, 2022

I agree

@FroMage
Copy link
Member

FroMage commented Oct 26, 2022

Properties: #28846
And I reopened #13665 for the headers

@geoand
Copy link
Contributor

geoand commented Oct 26, 2022

Great, thanks

FroMage added a commit to FroMage/quarkus that referenced this issue Oct 26, 2022
… client

- Also use hyphenate on `@RestHeader` on client fields on bean params quarkusio#13665
- Added test for client bean param on fields, getters and regular
  parameters for good measure

Fixes quarkusio#28782
@FroMage
Copy link
Member

FroMage commented Oct 26, 2022

OK, done.

@michalvavrik
Copy link
Member Author

Hello @FroMage , thank you for #28851, are there other steps required to fix this issue?

@michalvavrik
Copy link
Member Author

Ah, still not fixed, I get it.

FroMage added a commit to FroMage/quarkus that referenced this issue Oct 27, 2022
… client

- Also use hyphenate on `@RestHeader` on client fields on bean params quarkusio#13665
- Added test for client bean param on fields, getters and regular
  parameters for good measure

Fixes quarkusio#28782
@quarkus-bot quarkus-bot bot added this to the 2.15 - main milestone Oct 28, 2022
@gsmet gsmet modified the milestones: 2.15 - main, 2.14.0.Final Oct 28, 2022
gsmet pushed a commit to gsmet/quarkus that referenced this issue Oct 28, 2022
… client

- Also use hyphenate on `@RestHeader` on client fields on bean params quarkusio#13665
- Added test for client bean param on fields, getters and regular
  parameters for good measure

Fixes quarkusio#28782

(cherry picked from commit 368b496)
gsmet pushed a commit to gsmet/quarkus that referenced this issue Oct 31, 2022
… client

- Also use hyphenate on `@RestHeader` on client fields on bean params quarkusio#13665
- Added test for client bean param on fields, getters and regular
  parameters for good measure

Fixes quarkusio#28782

(cherry picked from commit 368b496)
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.

4 participants