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 - inject throwable for a failure handler
- resolves quarkusio#12249
- Loading branch information
Showing
9 changed files
with
387 additions
and
98 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
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
299 changes: 207 additions & 92 deletions
299
...vertx-web/deployment/src/main/java/io/quarkus/vertx/web/deployment/VertxWebProcessor.java
Large diffs are not rendered by default.
Oops, something went wrong.
53 changes: 53 additions & 0 deletions
53
...s/vertx-web/deployment/src/test/java/io/quarkus/vertx/web/failure/FailureHandlerTest.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,53 @@ | ||
package io.quarkus.vertx.web.failure; | ||
|
||
import static io.quarkus.vertx.web.Route.HandlerType.FAILURE; | ||
import static io.restassured.RestAssured.get; | ||
import static org.hamcrest.Matchers.is; | ||
|
||
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.Param; | ||
import io.quarkus.vertx.web.Route; | ||
import io.vertx.core.http.HttpServerResponse; | ||
|
||
public class FailureHandlerTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) | ||
.addClasses(Routes.class)); | ||
|
||
@Test | ||
public void test() { | ||
get("/fail?type=unsupported").then().statusCode(501).body(is("Unsupported!")); | ||
get("/fail").then().statusCode(500).body(is("Unknown!")); | ||
} | ||
|
||
public static class Routes { | ||
|
||
@Route | ||
void fail(@Param String type) { | ||
if ("unsupported".equals(type)) { | ||
throw new UnsupportedOperationException("Unsupported!"); | ||
} else { | ||
throw new RuntimeException("Unknown!"); | ||
} | ||
} | ||
|
||
@Route(path = "/fail", type = FAILURE, order = 1) | ||
void uoe(UnsupportedOperationException e, HttpServerResponse response) { | ||
response.setStatusCode(501).end(e.getMessage()); | ||
} | ||
|
||
@Route(path = "/*", type = FAILURE, order = 2) | ||
void re(RuntimeException e, HttpServerResponse response) { | ||
response.setStatusCode(500).end(e.getMessage()); | ||
} | ||
|
||
} | ||
|
||
} |
37 changes: 37 additions & 0 deletions
37
...src/test/java/io/quarkus/vertx/web/failure/MultipleThrowableParamsFailureHandlerTest.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,37 @@ | ||
package io.quarkus.vertx.web.failure; | ||
|
||
import static org.junit.jupiter.api.Assertions.fail; | ||
|
||
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.Param; | ||
import io.quarkus.vertx.web.Route; | ||
import io.quarkus.vertx.web.Route.HandlerType; | ||
|
||
public class MultipleThrowableParamsFailureHandlerTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) | ||
.addClasses(Routes.class)) | ||
.setExpectedException(IllegalStateException.class); | ||
|
||
@Test | ||
public void testValidationFailed() { | ||
fail(); | ||
} | ||
|
||
public static class Routes { | ||
|
||
@Route(type = HandlerType.FAILURE) | ||
void fail(UnsupportedOperationException e1, @Param String type, RuntimeException e2) { | ||
throw new RuntimeException("Unknown!"); | ||
} | ||
|
||
} | ||
|
||
} |
36 changes: 36 additions & 0 deletions
36
...eployment/src/test/java/io/quarkus/vertx/web/failure/ThrowableParamNormalHandlerTest.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,36 @@ | ||
package io.quarkus.vertx.web.failure; | ||
|
||
import static org.junit.jupiter.api.Assertions.fail; | ||
|
||
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.Param; | ||
import io.quarkus.vertx.web.Route; | ||
|
||
public class ThrowableParamNormalHandlerTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) | ||
.addClasses(Routes.class)) | ||
.setExpectedException(IllegalStateException.class); | ||
|
||
@Test | ||
public void testValidationFailed() { | ||
fail(); | ||
} | ||
|
||
public static class Routes { | ||
|
||
@Route | ||
void fail(UnsupportedOperationException e, @Param String type) { | ||
throw new RuntimeException("Unknown!"); | ||
} | ||
|
||
} | ||
|
||
} |
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