-
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.
Add a named producer for the current HttpServerRequest
- i.e. make it accesible from qute templates - resolves #17353
- Loading branch information
Showing
6 changed files
with
106 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
32 changes: 32 additions & 0 deletions
32
...t/src/test/java/io/quarkus/qute/deployment/currentrequest/CurrentRequestDisabledTest.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,32 @@ | ||
package io.quarkus.qute.deployment.currentrequest; | ||
|
||
import static org.junit.jupiter.api.Assertions.fail; | ||
|
||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.asset.StringAsset; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.qute.TemplateException; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class CurrentRequestDisabledTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) | ||
.addAsResource(new StringAsset( | ||
"quarkus.arc.exclude-types=io.quarkus.vertx.http.runtime.CurrentRequestProducer"), | ||
"application.properties") | ||
.addAsResource(new StringAsset( | ||
"Hello {inject:request.getParam('name')}!"), | ||
"templates/request.txt")) | ||
.setExpectedException(TemplateException.class); | ||
|
||
@Test | ||
public void testCurrentRequest() { | ||
fail(); | ||
} | ||
|
||
} |
44 changes: 44 additions & 0 deletions
44
...eployment/src/test/java/io/quarkus/qute/deployment/currentrequest/CurrentRequestTest.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,44 @@ | ||
package io.quarkus.qute.deployment.currentrequest; | ||
|
||
import static io.restassured.RestAssured.when; | ||
|
||
import javax.inject.Inject; | ||
|
||
import org.hamcrest.Matchers; | ||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.asset.StringAsset; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.qute.Template; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
import io.quarkus.vertx.web.Route; | ||
|
||
public class CurrentRequestTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) | ||
.addClass(MyRoute.class) | ||
.addAsResource(new StringAsset( | ||
"Hello {inject:request.getParam('name')}!"), | ||
"templates/request.txt")); | ||
|
||
@Test | ||
public void testCurrentRequest() { | ||
when().get("/current-request?name=Joe").then().body(Matchers.is("Hello Joe!")); | ||
} | ||
|
||
public static class MyRoute { | ||
|
||
@Inject | ||
Template request; | ||
|
||
@Route | ||
String currentRequest() { | ||
return request.render(); | ||
} | ||
} | ||
|
||
} |
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
25 changes: 25 additions & 0 deletions
25
...ertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/CurrentRequestProducer.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,25 @@ | ||
package io.quarkus.vertx.http.runtime; | ||
|
||
import javax.enterprise.context.RequestScoped; | ||
import javax.enterprise.inject.Produces; | ||
import javax.inject.Named; | ||
import javax.inject.Singleton; | ||
|
||
import io.vertx.core.http.HttpServerRequest; | ||
import io.vertx.ext.web.RoutingContext; | ||
|
||
/** | ||
* Note that we intentionally put the producer in a separate class so that it's possible to exclude the bean if a naming | ||
* conflict exists. | ||
*/ | ||
@Singleton | ||
public class CurrentRequestProducer { | ||
|
||
@Named("request") | ||
@Produces | ||
@RequestScoped | ||
public HttpServerRequest getCurrentRequest(RoutingContext rc) { | ||
return rc.request(); | ||
} | ||
|
||
} |