forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
REST Server/Client allows configuring the removal of trailing slashs
Before these changes, the REST server and client extensions were removing the trailing slashes that were set by users in the `@Path` annotations. For example, when creating a resource like: ```java @path("/a/") @produces(MediaType.TEXT_PLAIN) public class HelloResource { @get public String echo() { // ... } } ``` The effective path was `/a` instead of `/a/`. Note that it does not matter whether we place the `@Path` annotation at method level because the behaviour will be the same. At the client side, when having the following client: ``` @RegisterRestClient(configKey = "test") @path("/a/") <1> public interface HelloClient { @get @produces(MediaType.TEXT_PLAIN) @path("/b/") <2> String echo(); } ``` In this case, the trailing slash will be removed from <1> but not from <2>. After these changes, we are adding the following properties: - `quarkus.rest.removes-trailing-slash` To configure the server extension to not remove any trailing slash from the `@Path` annotations. - `quarkus.rest-client.removes-trailing-slash` To configure the client extension to not remove any traling slash from the `@Path` annotations used at interface level. The annotations set at method level will behave the same. Note that this does not introduce any change in behaviour, so everything should keep working as before unless users use the new properties.
- Loading branch information
Showing
12 changed files
with
266 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
...rkus/jaxrs/client/reactive/deployment/RestClientDisableRemovalTrailingSlashBuildItem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package io.quarkus.jaxrs.client.reactive.deployment; | ||
|
||
import java.util.List; | ||
|
||
import org.jboss.jandex.DotName; | ||
|
||
import io.quarkus.builder.item.MultiBuildItem; | ||
|
||
/** | ||
* This build item disables the removal of trailing slashes from the paths. | ||
*/ | ||
public final class RestClientDisableRemovalTrailingSlashBuildItem extends MultiBuildItem { | ||
private final List<DotName> clients; | ||
|
||
public RestClientDisableRemovalTrailingSlashBuildItem(List<DotName> clients) { | ||
this.clients = clients; | ||
} | ||
|
||
public List<DotName> getClients() { | ||
return clients; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
127 changes: 127 additions & 0 deletions
127
...ent/deployment/src/test/java/io/quarkus/rest/client/reactive/SlashPathRestClientTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
package io.quarkus.rest.client.reactive; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import jakarta.ws.rs.GET; | ||
import jakarta.ws.rs.Path; | ||
import jakarta.ws.rs.Produces; | ||
import jakarta.ws.rs.core.Context; | ||
import jakarta.ws.rs.core.MediaType; | ||
import jakarta.ws.rs.core.UriInfo; | ||
|
||
import org.eclipse.microprofile.rest.client.inject.RegisterRestClient; | ||
import org.eclipse.microprofile.rest.client.inject.RestClient; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class SlashPathRestClientTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest TEST = new QuarkusUnitTest() | ||
.withApplicationRoot((jar) -> jar | ||
.addClasses(HelloClientRemovingSlashes.class, | ||
HelloClientUsingConfigKey.class, | ||
HelloClientUsingSimpleName.class, | ||
HelloClientUsingClassName.class, | ||
HelloResource.class)) | ||
// disable the removal of trailing slash at client side | ||
.overrideConfigKey("quarkus.rest-client.test.removes-trailing-slash", "false") | ||
.overrideConfigKey("quarkus.rest-client.HelloClientUsingSimpleName.removes-trailing-slash", "false") | ||
.overrideConfigKey( | ||
"quarkus.rest-client.\"io.quarkus.rest.client.reactive.SlashPathRestClientTest$HelloClientUsingClassName\".removes-trailing-slash", | ||
"false") | ||
// disable the removal of trailing slash at server side | ||
.overrideConfigKey("quarkus.rest.removes-trailing-slash", "false") | ||
.overrideRuntimeConfigKey("quarkus.rest-client.test.url", | ||
"http://localhost:${quarkus.http.test-port:8081}") | ||
.overrideRuntimeConfigKey("quarkus.rest-client.default.url", | ||
"http://localhost:${quarkus.http.test-port:8081}") | ||
.overrideRuntimeConfigKey("quarkus.rest-client.HelloClientUsingSimpleName.url", | ||
"http://localhost:${quarkus.http.test-port:8081}") | ||
.overrideRuntimeConfigKey( | ||
"quarkus.rest-client.\"io.quarkus.rest.client.reactive.SlashPathRestClientTest$HelloClientUsingClassName\".url", | ||
"http://localhost:${quarkus.http.test-port:8081}"); | ||
|
||
@RestClient | ||
HelloClientRemovingSlashes clientUsingDefaultBehaviour; | ||
|
||
@RestClient | ||
HelloClientUsingConfigKey clientUsingConfigKey; | ||
|
||
@RestClient | ||
HelloClientUsingSimpleName clientUsingSimpleName; | ||
|
||
@RestClient | ||
HelloClientUsingClassName clientUsingClassName; | ||
|
||
@Test | ||
void shouldRemoveTrailingSlashByDefault() { | ||
assertThat(clientUsingDefaultBehaviour.echo()).isEqualTo("/slash/without"); | ||
} | ||
|
||
@Test | ||
void shouldRemoveTrailingSlashUsingConfigKey() { | ||
assertThat(clientUsingConfigKey.echo()).isEqualTo("/slash/with/"); | ||
} | ||
|
||
@Test | ||
void shouldRemoveTrailingSlashUsingSimpleName() { | ||
assertThat(clientUsingSimpleName.echo()).isEqualTo("/slash/with/"); | ||
} | ||
|
||
@Test | ||
void shouldRemoveTrailingSlashUsingClassName() { | ||
assertThat(clientUsingClassName.echo()).isEqualTo("/slash/with/"); | ||
} | ||
|
||
@RegisterRestClient(configKey = "default") | ||
@Path("/slash/without/") | ||
public interface HelloClientRemovingSlashes { | ||
@GET | ||
@Produces(MediaType.TEXT_PLAIN) | ||
String echo(); | ||
} | ||
|
||
@RegisterRestClient(configKey = "test") | ||
@Path("/slash/with/") | ||
public interface HelloClientUsingConfigKey { | ||
@GET | ||
@Produces(MediaType.TEXT_PLAIN) | ||
String echo(); | ||
} | ||
|
||
@RegisterRestClient | ||
@Path("/slash/with/") | ||
public interface HelloClientUsingSimpleName { | ||
@GET | ||
@Produces(MediaType.TEXT_PLAIN) | ||
String echo(); | ||
} | ||
|
||
@RegisterRestClient | ||
@Path("/slash/with/") | ||
public interface HelloClientUsingClassName { | ||
@GET | ||
@Produces(MediaType.TEXT_PLAIN) | ||
String echo(); | ||
} | ||
|
||
@Path("/slash") | ||
@Produces(MediaType.TEXT_PLAIN) | ||
public static class HelloResource { | ||
|
||
@GET | ||
@Path("/without") | ||
public String withoutSlash(@Context UriInfo uriInfo) { | ||
return uriInfo.getPath(); | ||
} | ||
|
||
@GET | ||
@Path("/with/") | ||
public String usingSlash(@Context UriInfo uriInfo) { | ||
return uriInfo.getPath(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.