Skip to content

Commit 4e30b33

Browse files
authored
Merge pull request #33918 from kahowell/resteasy-classic-pathparam-bugfix
Fix parameter validation issue in classic rest-client
2 parents afbb315 + 8c0e055 commit 4e30b33

File tree

7 files changed

+77
-5
lines changed

7 files changed

+77
-5
lines changed

extensions/resteasy-classic/rest-client/deployment/src/test/java/io/quarkus/restclient/configuration/ClassicRestClientBuilderFactoryTest.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class ClassicRestClientBuilderFactoryTest {
1414
@RegisterExtension
1515
static final QuarkusUnitTest TEST = new QuarkusUnitTest()
1616
.withApplicationRoot((jar) -> jar.addClasses(EchoClientWithoutAnnotation.class, EchoClientWithConfigKey.class,
17-
EchoResource.class))
17+
EchoClientWithEmptyPath.class, EchoResource.class))
1818
.withConfigurationResource("factory-test-application.properties");
1919

2020
@Test
@@ -33,4 +33,13 @@ public void testNotAnnotatedClientClass() {
3333

3434
assertThat(restClient.echo("Hello")).contains("Hello");
3535
}
36+
37+
@Test
38+
public void testEmptyPathAnnotationOnClass() {
39+
RestClientBuilder restClientBuilder = RestClientBuilderFactory.getInstance()
40+
.newBuilder(EchoClientWithEmptyPath.class);
41+
EchoClientWithEmptyPath restClient = restClientBuilder.build(EchoClientWithEmptyPath.class);
42+
43+
assertThat(restClient.echo("echo", "Hello")).contains("Hello");
44+
}
3645
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package io.quarkus.restclient.configuration;
2+
3+
import jakarta.ws.rs.Consumes;
4+
import jakarta.ws.rs.GET;
5+
import jakarta.ws.rs.Path;
6+
import jakarta.ws.rs.PathParam;
7+
import jakarta.ws.rs.Produces;
8+
import jakarta.ws.rs.QueryParam;
9+
import jakarta.ws.rs.core.MediaType;
10+
11+
import org.eclipse.microprofile.rest.client.inject.RegisterRestClient;
12+
13+
@Path("")
14+
@RegisterRestClient(configKey = "echo-client")
15+
public interface EchoClientWithEmptyPath {
16+
17+
@GET
18+
@Produces(MediaType.TEXT_PLAIN)
19+
@Consumes(MediaType.TEXT_PLAIN)
20+
@Path("/{id}")
21+
String echo(@PathParam("id") String id, @QueryParam("message") String message);
22+
23+
}

extensions/resteasy-classic/rest-client/runtime/src/main/java/io/quarkus/restclient/runtime/QuarkusRestClientBuilder.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -588,11 +588,12 @@ private <T> void verifyInterface(Class<T> typeDef) {
588588
for (Method method : methods) {
589589
Path methodPathAnno = method.getAnnotation(Path.class);
590590
if (methodPathAnno != null) {
591-
template = classPathAnno == null ? (ResteasyUriBuilder) new ResteasyUriBuilderImpl().uri(methodPathAnno.value())
591+
template = classPathAnno == null
592+
? (ResteasyUriBuilder) new ResteasyUriBuilderImpl().path(methodPathAnno.value())
592593
: (ResteasyUriBuilder) new ResteasyUriBuilderImpl()
593-
.uri(classPathAnno.value() + "/" + methodPathAnno.value());
594+
.path(classPathAnno.value() + "/" + methodPathAnno.value());
594595
} else if (classPathAnno != null) {
595-
template = (ResteasyUriBuilder) new ResteasyUriBuilderImpl().uri(classPathAnno.value());
596+
template = (ResteasyUriBuilder) new ResteasyUriBuilderImpl().path(classPathAnno.value());
596597
} else {
597598
template = null;
598599
}

extensions/resteasy-reactive/rest-client-reactive/deployment/src/test/java/io/quarkus/rest/client/reactive/ConfigurationTest.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,16 @@ public class ConfigurationTest {
2323

2424
@RegisterExtension
2525
static final QuarkusUnitTest TEST = new QuarkusUnitTest()
26-
.withApplicationRoot(jar -> jar.addClasses(HelloClientWithBaseUri.class, EchoResource.class))
26+
.withApplicationRoot(
27+
jar -> jar.addClasses(HelloClientWithBaseUri.class, EchoResource.class, EchoClientWithEmptyPath.class))
2728
.withConfigurationResource("configuration-test-application.properties");
2829

2930
@RestClient
3031
HelloClientWithBaseUri client;
3132

33+
@RestClient
34+
EchoClientWithEmptyPath echoClientWithEmptyPath;
35+
3236
@Test
3337
void shouldHaveSingletonScope() {
3438
BeanManager beanManager = Arc.container().beanManager();
@@ -62,6 +66,11 @@ void checkClientSpecificConfigs() {
6266
verifyClientConfig(clientConfig, false);
6367
}
6468

69+
@Test
70+
void emptyPathAnnotationShouldWork() {
71+
assertThat(echoClientWithEmptyPath.echo("hello", "hello world")).isEqualTo("hello world");
72+
}
73+
6574
private void verifyClientConfig(RestClientConfig clientConfig, boolean checkExtraProperties) {
6675
assertThat(clientConfig.url).isPresent();
6776
assertThat(clientConfig.url.get()).endsWith("/hello");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package io.quarkus.rest.client.reactive;
2+
3+
import jakarta.ws.rs.Consumes;
4+
import jakarta.ws.rs.GET;
5+
import jakarta.ws.rs.Path;
6+
import jakarta.ws.rs.PathParam;
7+
import jakarta.ws.rs.Produces;
8+
import jakarta.ws.rs.QueryParam;
9+
import jakarta.ws.rs.core.MediaType;
10+
11+
import org.eclipse.microprofile.rest.client.inject.RegisterRestClient;
12+
13+
@Path("")
14+
@RegisterRestClient
15+
public interface EchoClientWithEmptyPath {
16+
@GET
17+
@Produces(MediaType.TEXT_PLAIN)
18+
@Consumes(MediaType.TEXT_PLAIN)
19+
@Path("/{id}")
20+
String echo(@PathParam("id") String id, @QueryParam("message") String message);
21+
22+
}

extensions/resteasy-reactive/rest-client-reactive/deployment/src/test/java/io/quarkus/rest/client/reactive/configuration/EchoResource.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package io.quarkus.rest.client.reactive.configuration;
22

33
import jakarta.ws.rs.Consumes;
4+
import jakarta.ws.rs.GET;
45
import jakarta.ws.rs.POST;
56
import jakarta.ws.rs.Path;
67
import jakarta.ws.rs.Produces;
8+
import jakarta.ws.rs.QueryParam;
79
import jakarta.ws.rs.core.Context;
810
import jakarta.ws.rs.core.HttpHeaders;
911
import jakarta.ws.rs.core.MediaType;
@@ -21,4 +23,9 @@ public String echo(String name, @Context Request request, @Context HttpHeaders h
2123
return (message != null ? message : "hello") + (comma != null ? comma : "_") + " " + name
2224
+ (suffix != null ? suffix : "");
2325
}
26+
27+
@GET
28+
public String echoQueryParam(@QueryParam("message") String message) {
29+
return message;
30+
}
2431
}

extensions/resteasy-reactive/rest-client-reactive/deployment/src/test/resources/configuration-test-application.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ quarkus.rest-client."io.quarkus.rest.client.reactive.HelloClientWithBaseUri".kee
1818
quarkus.rest-client."io.quarkus.rest.client.reactive.HelloClientWithBaseUri".max-redirects=5
1919
quarkus.rest-client."io.quarkus.rest.client.reactive.HelloClientWithBaseUri".headers.message=hi
2020
quarkus.rest-client."io.quarkus.rest.client.reactive.HelloClientWithBaseUri".headers.suffix=!
21+
quarkus.rest-client."io.quarkus.rest.client.reactive.EchoClientWithEmptyPath".url=http://localhost:${quarkus.http.test-port:8081}/
2122

2223
# client identified by a configKey
2324
quarkus.rest-client.client-prefix.url=http://localhost:${quarkus.http.test-port:8081}/hello

0 commit comments

Comments
 (0)