-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow request filters to be run after the input has been read
Resolves: #22209
- Loading branch information
Showing
11 changed files
with
180 additions
and
11 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
80 changes: 80 additions & 0 deletions
80
...a/io/quarkus/resteasy/reactive/server/test/customproviders/ReadBodyRequestFilterTest.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,80 @@ | ||
package io.quarkus.resteasy.reactive.server.test.customproviders; | ||
|
||
import java.util.function.Supplier; | ||
|
||
import javax.ws.rs.GET; | ||
import javax.ws.rs.POST; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.core.HttpHeaders; | ||
|
||
import org.hamcrest.Matchers; | ||
import org.jboss.resteasy.reactive.RestForm; | ||
import org.jboss.resteasy.reactive.RestQuery; | ||
import org.jboss.resteasy.reactive.server.ServerRequestFilter; | ||
import org.jboss.resteasy.reactive.server.core.ResteasyReactiveRequestContext; | ||
import org.jboss.resteasy.reactive.server.spi.ResteasyReactiveContainerRequestContext; | ||
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; | ||
|
||
import io.quarkus.test.QuarkusUnitTest; | ||
import io.restassured.RestAssured; | ||
|
||
public class ReadBodyRequestFilterTest { | ||
|
||
@RegisterExtension | ||
static QuarkusUnitTest test = new QuarkusUnitTest() | ||
.setArchiveProducer(new Supplier<>() { | ||
@Override | ||
public JavaArchive get() { | ||
return ShrinkWrap.create(JavaArchive.class) | ||
.addClasses(HelloResource.class); | ||
} | ||
}); | ||
|
||
@Test | ||
public void testMethodWithBody() { | ||
RestAssured.with() | ||
.formParam("name", "Quarkus") | ||
.post("/hello") | ||
.then().body(Matchers.equalTo("hello Quarkus!!!!!!!")); | ||
} | ||
|
||
@Test | ||
public void testMethodWithoutBody() { | ||
RestAssured.with() | ||
.queryParam("name", "Quarkus") | ||
.get("/hello") | ||
.then().body(Matchers.equalTo("hello Quarkus!")); | ||
} | ||
|
||
@Path("hello") | ||
public static class HelloResource { | ||
|
||
@POST | ||
public String helloPost(@RestForm String name, HttpHeaders headers) { | ||
return "hello " + name + headers.getHeaderString("suffix"); | ||
} | ||
|
||
@GET | ||
public String helloGet(@RestQuery String name, HttpHeaders headers) { | ||
return "hello " + name + headers.getHeaderString("suffix"); | ||
} | ||
} | ||
|
||
public static class Filters { | ||
|
||
@ServerRequestFilter(readBody = true) | ||
public void addSuffix(ResteasyReactiveContainerRequestContext containerRequestContext) { | ||
ResteasyReactiveRequestContext rrContext = (ResteasyReactiveRequestContext) containerRequestContext | ||
.getServerRequestContext(); | ||
if (containerRequestContext.getMethod().equals("POST")) { | ||
String nameFormParam = (String) rrContext.getFormParameter("name", true, false); | ||
containerRequestContext.getHeaders().putSingle("suffix", "!".repeat(nameFormParam.length())); | ||
} else { | ||
containerRequestContext.getHeaders().putSingle("suffix", "!"); | ||
} | ||
} | ||
} | ||
} |
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
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.