Skip to content

Commit

Permalink
Merge pull request #33918 from kahowell/resteasy-classic-pathparam-bu…
Browse files Browse the repository at this point in the history
…gfix

Fix parameter validation issue in classic rest-client
  • Loading branch information
Sgitario authored Jun 22, 2023
2 parents afbb315 + 8c0e055 commit 4e30b33
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class ClassicRestClientBuilderFactoryTest {
@RegisterExtension
static final QuarkusUnitTest TEST = new QuarkusUnitTest()
.withApplicationRoot((jar) -> jar.addClasses(EchoClientWithoutAnnotation.class, EchoClientWithConfigKey.class,
EchoResource.class))
EchoClientWithEmptyPath.class, EchoResource.class))
.withConfigurationResource("factory-test-application.properties");

@Test
Expand All @@ -33,4 +33,13 @@ public void testNotAnnotatedClientClass() {

assertThat(restClient.echo("Hello")).contains("Hello");
}

@Test
public void testEmptyPathAnnotationOnClass() {
RestClientBuilder restClientBuilder = RestClientBuilderFactory.getInstance()
.newBuilder(EchoClientWithEmptyPath.class);
EchoClientWithEmptyPath restClient = restClientBuilder.build(EchoClientWithEmptyPath.class);

assertThat(restClient.echo("echo", "Hello")).contains("Hello");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package io.quarkus.restclient.configuration;

import jakarta.ws.rs.Consumes;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.PathParam;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.QueryParam;
import jakarta.ws.rs.core.MediaType;

import org.eclipse.microprofile.rest.client.inject.RegisterRestClient;

@Path("")
@RegisterRestClient(configKey = "echo-client")
public interface EchoClientWithEmptyPath {

@GET
@Produces(MediaType.TEXT_PLAIN)
@Consumes(MediaType.TEXT_PLAIN)
@Path("/{id}")
String echo(@PathParam("id") String id, @QueryParam("message") String message);

}
Original file line number Diff line number Diff line change
Expand Up @@ -588,11 +588,12 @@ private <T> void verifyInterface(Class<T> typeDef) {
for (Method method : methods) {
Path methodPathAnno = method.getAnnotation(Path.class);
if (methodPathAnno != null) {
template = classPathAnno == null ? (ResteasyUriBuilder) new ResteasyUriBuilderImpl().uri(methodPathAnno.value())
template = classPathAnno == null
? (ResteasyUriBuilder) new ResteasyUriBuilderImpl().path(methodPathAnno.value())
: (ResteasyUriBuilder) new ResteasyUriBuilderImpl()
.uri(classPathAnno.value() + "/" + methodPathAnno.value());
.path(classPathAnno.value() + "/" + methodPathAnno.value());
} else if (classPathAnno != null) {
template = (ResteasyUriBuilder) new ResteasyUriBuilderImpl().uri(classPathAnno.value());
template = (ResteasyUriBuilder) new ResteasyUriBuilderImpl().path(classPathAnno.value());
} else {
template = null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,16 @@ public class ConfigurationTest {

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

@RestClient
HelloClientWithBaseUri client;

@RestClient
EchoClientWithEmptyPath echoClientWithEmptyPath;

@Test
void shouldHaveSingletonScope() {
BeanManager beanManager = Arc.container().beanManager();
Expand Down Expand Up @@ -62,6 +66,11 @@ void checkClientSpecificConfigs() {
verifyClientConfig(clientConfig, false);
}

@Test
void emptyPathAnnotationShouldWork() {
assertThat(echoClientWithEmptyPath.echo("hello", "hello world")).isEqualTo("hello world");
}

private void verifyClientConfig(RestClientConfig clientConfig, boolean checkExtraProperties) {
assertThat(clientConfig.url).isPresent();
assertThat(clientConfig.url.get()).endsWith("/hello");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package io.quarkus.rest.client.reactive;

import jakarta.ws.rs.Consumes;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.PathParam;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.QueryParam;
import jakarta.ws.rs.core.MediaType;

import org.eclipse.microprofile.rest.client.inject.RegisterRestClient;

@Path("")
@RegisterRestClient
public interface EchoClientWithEmptyPath {
@GET
@Produces(MediaType.TEXT_PLAIN)
@Consumes(MediaType.TEXT_PLAIN)
@Path("/{id}")
String echo(@PathParam("id") String id, @QueryParam("message") String message);

}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package io.quarkus.rest.client.reactive.configuration;

import jakarta.ws.rs.Consumes;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.POST;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.QueryParam;
import jakarta.ws.rs.core.Context;
import jakarta.ws.rs.core.HttpHeaders;
import jakarta.ws.rs.core.MediaType;
Expand All @@ -21,4 +23,9 @@ public String echo(String name, @Context Request request, @Context HttpHeaders h
return (message != null ? message : "hello") + (comma != null ? comma : "_") + " " + name
+ (suffix != null ? suffix : "");
}

@GET
public String echoQueryParam(@QueryParam("message") String message) {
return message;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ quarkus.rest-client."io.quarkus.rest.client.reactive.HelloClientWithBaseUri".kee
quarkus.rest-client."io.quarkus.rest.client.reactive.HelloClientWithBaseUri".max-redirects=5
quarkus.rest-client."io.quarkus.rest.client.reactive.HelloClientWithBaseUri".headers.message=hi
quarkus.rest-client."io.quarkus.rest.client.reactive.HelloClientWithBaseUri".headers.suffix=!
quarkus.rest-client."io.quarkus.rest.client.reactive.EchoClientWithEmptyPath".url=http://localhost:${quarkus.http.test-port:8081}/

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

0 comments on commit 4e30b33

Please sign in to comment.