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

REST Client @RestForm does not convert for List<T> #39996

Closed
krnhotwings opened this issue Apr 10, 2024 · 5 comments · Fixed by #40011
Closed

REST Client @RestForm does not convert for List<T> #39996

krnhotwings opened this issue Apr 10, 2024 · 5 comments · Fixed by #40011
Labels
area/rest-client kind/bug Something isn't working
Milestone

Comments

@krnhotwings
Copy link

Describe the bug

(Apologies for any incorrect terminology.) Normally when creating REST resources in quarkus, one can attach @RestForm or @FormParam to List<T> to indicate a repeated URL encoded form parameter, and this conversion will work as expected. For example:

@POST
public String test(@RestForm List<String> param) {
    // Do stuff with `param`

    return "Success"
}

However, the same does not appear to work when describing a REST Client method in the same manner. Invoking the client method will throw an exception (see below.) Additionally, @RestQuery seems to work on List<T> where @RestForm/@FormParam does not.

Expected behavior

I would think that the annotations should behave the same between RESTEasy and REST Client. This page states that the two share the same infrastructure, which I would think includes parameter converters unless I'm misunderstanding something.

There's also this page that describes how to use@RestForm in REST Clients, but I'm not sure if this snippet of examples indicates "here are some, but not a complete set of, examples that can be done with @RestForm" or if it means "these are the only types that @RestForm supports in REST Clients"

Actual behavior

Invoking the API throws an exception:

@RestClient EchoClient api;

public void test() {
    api.post(List.of("abc", "123"));
}
java.lang.IllegalStateException: Form element 'org.acme.EchoClient.post' could not be converted to 'String' for REST Client interface 'org.acme.EchoClient'. A proper implementation of 'jakarta.ws.rs.ext.ParamConverter' needs to be returned by a 'jakarta.ws.rs.ext.ParamConverterProvider' that is registered with the client via the @RegisterProvider annotation on the REST Client interface.
        at org.acme.EchoClient$$QuarkusRestClientInterface.post(Unknown Source)
        at org.acme.EchoClient$$CDIWrapper.post(Unknown Source)
        at org.acme.EchoClient$$CDIWrapper_ClientProxy.post(Unknown Source)
        at org.acme.GreetingResource.postTest(GreetingResource.java:27)
        at org.acme.GreetingResource$quarkusrestinvoker$postTest_1a7b3ae538024acc32395521f5fafc87a70ba54b.invoke(Unknown Source)
        at org.jboss.resteasy.reactive.server.handlers.InvocationHandler.handle(InvocationHandler.java:29)
        at io.quarkus.resteasy.reactive.server.runtime.QuarkusResteasyReactiveRequestContext.invokeHandler(QuarkusResteasyReactiveRequestContext.java:141)
        at org.jboss.resteasy.reactive.common.core.AbstractResteasyReactiveContext.run(AbstractResteasyReactiveContext.java:147)
        at io.quarkus.vertx.core.runtime.VertxCoreRecorder$14.runWith(VertxCoreRecorder.java:599)
        at org.jboss.threads.EnhancedQueueExecutor$Task.doRunWith(EnhancedQueueExecutor.java:2516)
        at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2495)
        at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1521)
        at org.jboss.threads.DelegatingRunnable.run(DelegatingRunnable.java:11)
        at org.jboss.threads.ThreadLocalResettingRunnable.run(ThreadLocalResettingRunnable.java:11)
        at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
        at java.base/java.lang.Thread.run(Thread.java:1583)

How to Reproduce?

Demo repo here:
https://github.com/krnhotwings/rest-client-test

  1. Follow README to start http echo server: podman run --rm -d -p 8001:8080 mendhak/http-https-echo:latest
  2. Startup quarkus server: quarkus dev
  3. curl "http://localhost:8080/hello/post Exception is thrown
  4. curl "http://localhost:8080/hello/get Works.

Exception is thrown here:
https://github.com/krnhotwings/rest-client-test/blob/main/src/main/java/org/acme/EchoClient.java#L19-L20

List<T> works with @RestQuery:
https://github.com/krnhotwings/rest-client-test/blob/main/src/main/java/org/acme/EchoClient.java#L16-L17

Where the client is being invoked:
https://github.com/krnhotwings/rest-client-test/blob/main/src/main/java/org/acme/GreetingResource.java#L20-L28

Output of uname -a or ver

Linux 6.8.4-200.fc39.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Apr 4 20:45:21 UTC 2024 x86_64 GNU/Linux

Output of java -version

openjdk version "21.0.2" 2024-01-16 OpenJDK Runtime Environment GraalVM CE 21.0.2+13.1 (build 21.0.2+13-jvmci-23.1-b30) OpenJDK 64-Bit Server VM GraalVM CE 21.0.2+13.1 (build 21.0.2+13-jvmci-23.1-b30, mixed mode, sharing)

Quarkus version or git rev

3.9.1

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

Gradle 8.6 rev d55c486870a0dc6f6278f53d21381396d0741c6e

Additional information

No response

@krnhotwings krnhotwings added the kind/bug Something isn't working label Apr 10, 2024
Copy link

quarkus-bot bot commented Apr 10, 2024

/cc @cescoffier (rest-client), @geoand (rest-client)

geoand added a commit to geoand/quarkus that referenced this issue Apr 11, 2024
cescoffier added a commit that referenced this issue Apr 12, 2024
Support using List for sending multiple form values in REST Client
@quarkus-bot quarkus-bot bot added this to the 3.10 - main milestone Apr 12, 2024
@krnhotwings
Copy link
Author

@geoand Hi Georgios, I tested this just now on 3.10.0.CR1 and while the fix works for @RestForm/@FormParam method params (thank you,) the exception is still thrown when using a List inside a @BeanParam bean class. In hindsight, I should've tested for this scenario...

I assume this is still a bug related to the above changes? Do you need anything from me to test for this?

@geoand
Copy link
Contributor

geoand commented Apr 26, 2024

I assume this is still a bug related to the above changes? Do you need anything from me to test for this?

Yeah, definitely a bug, do you mind opening a new issue for it?

Thanks

@david-cabillic
Copy link

I tried @FormParam("files") List<File> files with 3.13.0 and I got the same issue : "could not be converted to 'String' for REST Client interface "

@Roland42
Copy link

Roland42 commented Oct 8, 2024

I still have the problem with @FormParam List with 3.15.1 : "could not be converted to 'String' for REST Client interface "

This issue does not seem to be fixed

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

Successfully merging a pull request may close this issue.

4 participants