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.
Reactive routes - fix request context propagation
If there is a route filter and the request can have body (POST, PUT, etc.) then the route method is invoked asynchronously (once all data are read). However, the request context is activated by the filter and so we need to make sure the same context is then used in the route method. - resolves quarkusio#13073
- Loading branch information
Showing
2 changed files
with
93 additions
and
14 deletions.
There are no files selected for viewing
67 changes: 67 additions & 0 deletions
67
...nt/src/test/java/io/quarkus/vertx/web/filter/UserFilterRequestContextPropagationTest.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,67 @@ | ||
package io.quarkus.vertx.web.filter; | ||
|
||
import static org.hamcrest.Matchers.is; | ||
|
||
import java.util.concurrent.atomic.AtomicInteger; | ||
|
||
import javax.enterprise.context.RequestScoped; | ||
import javax.inject.Inject; | ||
|
||
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.quarkus.vertx.web.Route; | ||
import io.quarkus.vertx.web.RouteFilter; | ||
import io.restassured.RestAssured; | ||
import io.vertx.ext.web.RoutingContext; | ||
|
||
public class UserFilterRequestContextPropagationTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) | ||
.addClasses(FilterAndRoute.class, RequestFoo.class)); | ||
|
||
@Test | ||
public void test() { | ||
RestAssured.post("/hello").then().statusCode(200) | ||
.body(is("11")); | ||
} | ||
|
||
public static class FilterAndRoute { | ||
|
||
@Inject | ||
RequestFoo foo; | ||
|
||
@RouteFilter | ||
void filter1(RoutingContext rc) { | ||
foo.setState(11); | ||
rc.next(); | ||
} | ||
|
||
@Route(path = "hello") | ||
void hello(RoutingContext ctx) { | ||
ctx.response().end("" + foo.getState()); | ||
} | ||
|
||
} | ||
|
||
@RequestScoped | ||
static class RequestFoo { | ||
|
||
private AtomicInteger state = new AtomicInteger(-1); | ||
|
||
void setState(int value) { | ||
this.state.set(value); | ||
} | ||
|
||
public int getState() { | ||
return state.get(); | ||
} | ||
|
||
} | ||
|
||
} |
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