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.
Allow overriding query parameters from a ContainerRequestFilter
Fixes: quarkusio#28555
- Loading branch information
Showing
4 changed files
with
96 additions
and
1 deletion.
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
66 changes: 66 additions & 0 deletions
66
...boss/resteasy/reactive/server/vertx/test/resource/basic/RequestFilterQueryParamsTest.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,66 @@ | ||
package org.jboss.resteasy.reactive.server.vertx.test.resource.basic; | ||
|
||
import static io.restassured.RestAssured.get; | ||
|
||
import java.io.IOException; | ||
import java.net.URI; | ||
|
||
import javax.ws.rs.DefaultValue; | ||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.Produces; | ||
import javax.ws.rs.QueryParam; | ||
import javax.ws.rs.container.ContainerRequestContext; | ||
import javax.ws.rs.container.ContainerRequestFilter; | ||
import javax.ws.rs.container.PreMatching; | ||
import javax.ws.rs.core.MediaType; | ||
import javax.ws.rs.core.UriBuilder; | ||
import javax.ws.rs.ext.Provider; | ||
|
||
import org.hamcrest.Matchers; | ||
import org.jboss.resteasy.reactive.server.vertx.test.framework.ResteasyReactiveUnitTest; | ||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
public class RequestFilterQueryParamsTest { | ||
|
||
@RegisterExtension | ||
static ResteasyReactiveUnitTest test = new ResteasyReactiveUnitTest() | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) | ||
.addClasses(BlockingHelloResource.class, ReplacePathAndQueryParamsFilter.class)); | ||
|
||
@Test | ||
public void test() { | ||
get("/dummy") | ||
.then() | ||
.statusCode(200) | ||
.body(Matchers.equalTo("Hello filter")); | ||
} | ||
|
||
@Path("hello") | ||
public static class BlockingHelloResource { | ||
|
||
@GET | ||
@Produces(MediaType.TEXT_PLAIN) | ||
public String hello(@QueryParam("name") @DefaultValue("world") String name) { | ||
return "Hello " + name; | ||
} | ||
} | ||
|
||
@Provider | ||
@PreMatching | ||
public static class ReplacePathAndQueryParamsFilter implements ContainerRequestFilter { | ||
|
||
@Override | ||
public void filter(ContainerRequestContext requestContext) | ||
throws IOException { | ||
UriBuilder builder = requestContext.getUriInfo().getRequestUriBuilder(); | ||
builder.replacePath("/hello"); | ||
builder.replaceQueryParam("name", "filter"); | ||
URI uri = builder.build(); | ||
requestContext.setRequestUri(uri); | ||
} | ||
} | ||
} |