From 7064dc76e59f50d3b4d5391eafdb26fa04797026 Mon Sep 17 00:00:00 2001 From: Georgios Andrianakis Date: Tue, 16 Mar 2021 14:43:07 +0200 Subject: [PATCH] Make per class @ServerExceptionMapper work with Mutiny response types Relates to: #15673 --- .../CustomExceptionMappersTest.java | 16 ++++++++++++++++ .../test/customexceptions/FirstResource.java | 19 +++++++++++++++++++ .../core/AbstractResteasyReactiveContext.java | 5 +++++ .../handlers/PublisherResponseHandler.java | 2 +- .../server/handlers/UniResponseHandler.java | 2 +- 5 files changed, 42 insertions(+), 2 deletions(-) diff --git a/extensions/resteasy-reactive/quarkus-resteasy-reactive/deployment/src/test/java/io/quarkus/resteasy/reactive/server/test/customexceptions/CustomExceptionMappersTest.java b/extensions/resteasy-reactive/quarkus-resteasy-reactive/deployment/src/test/java/io/quarkus/resteasy/reactive/server/test/customexceptions/CustomExceptionMappersTest.java index 65e5b11982e8e..8c99deecc0ff6 100644 --- a/extensions/resteasy-reactive/quarkus-resteasy-reactive/deployment/src/test/java/io/quarkus/resteasy/reactive/server/test/customexceptions/CustomExceptionMappersTest.java +++ b/extensions/resteasy-reactive/quarkus-resteasy-reactive/deployment/src/test/java/io/quarkus/resteasy/reactive/server/test/customexceptions/CustomExceptionMappersTest.java @@ -42,6 +42,22 @@ public void testResourceWithExceptionMapper() { .then().statusCode(500); } + @Test + public void testResourceWithExceptionMapperAndUniResponse() { + RestAssured.get("/first/uni?name=IllegalState") + .then().statusCode(409); + RestAssured.get("/first/uni?name=IllegalArgument") + .then().statusCode(409); + RestAssured.get("/first/uni?name=My") + .then().statusCode(410).body(Matchers.equalTo("/first/uni->uni")); + RestAssured.get("/first/uni?name=MyOther") + .then().statusCode(411); + RestAssured.get("/first/uni?name=Uni") + .then().statusCode(412).body(Matchers.equalTo("/first/uni->uni")); + RestAssured.get("/first/uni?name=Other") + .then().statusCode(500); + } + @Test public void testResourceWithoutExceptionMapper() { RestAssured.get("/second") diff --git a/extensions/resteasy-reactive/quarkus-resteasy-reactive/deployment/src/test/java/io/quarkus/resteasy/reactive/server/test/customexceptions/FirstResource.java b/extensions/resteasy-reactive/quarkus-resteasy-reactive/deployment/src/test/java/io/quarkus/resteasy/reactive/server/test/customexceptions/FirstResource.java index 9a62f4a91bd25..7891cc61979a9 100644 --- a/extensions/resteasy-reactive/quarkus-resteasy-reactive/deployment/src/test/java/io/quarkus/resteasy/reactive/server/test/customexceptions/FirstResource.java +++ b/extensions/resteasy-reactive/quarkus-resteasy-reactive/deployment/src/test/java/io/quarkus/resteasy/reactive/server/test/customexceptions/FirstResource.java @@ -36,6 +36,25 @@ public String throwsVariousExceptions(@RestQuery String name) { throw new RuntimeException(); } + @GET + @Path("uni") + @Produces("text/plain") + public Uni uni(@RestQuery String name) { + Exception e = new RuntimeException(); + if (name.startsWith("IllegalArgument")) { + e = new IllegalArgumentException(); + } else if (name.startsWith("IllegalState")) { + e = new IllegalStateException("IllegalState"); + } else if (name.startsWith("MyOther")) { + e = new MyOtherException(); + } else if (name.startsWith("My")) { + e = new MyException(); + } else if (name.startsWith("Uni")) { + e = new UniException(); + } + return Uni.createFrom().failure(e); + } + @ServerExceptionMapper({ IllegalStateException.class, IllegalArgumentException.class }) public Response handleIllegal() { return Response.status(409).build(); diff --git a/independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/core/AbstractResteasyReactiveContext.java b/independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/core/AbstractResteasyReactiveContext.java index 5aa1ad3c8aab2..7626d1a03dc88 100644 --- a/independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/core/AbstractResteasyReactiveContext.java +++ b/independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/core/AbstractResteasyReactiveContext.java @@ -51,6 +51,11 @@ public synchronized void resume(Throwable throwable) { resume((Executor) null); } + public synchronized void resume(Throwable throwable, boolean keepTarget) { + handleException(throwable, keepTarget); + resume((Executor) null); + } + public synchronized void resume(Executor executor) { if (running) { this.executor = executor; diff --git a/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/handlers/PublisherResponseHandler.java b/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/handlers/PublisherResponseHandler.java index 374f741afab26..0b30d2e271469 100644 --- a/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/handlers/PublisherResponseHandler.java +++ b/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/handlers/PublisherResponseHandler.java @@ -155,7 +155,7 @@ protected void handleException(ResteasyReactiveRequestContext requestContext, Th log.error("Exception in SSE server handling, impossible to send it to client", t); } else { // we can go through the abort chain - requestContext.resume(t); + requestContext.resume(t, true); } } } diff --git a/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/handlers/UniResponseHandler.java b/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/handlers/UniResponseHandler.java index af680a4a53294..b4e720adbc52a 100644 --- a/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/handlers/UniResponseHandler.java +++ b/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/handlers/UniResponseHandler.java @@ -23,7 +23,7 @@ public void accept(Object v) { }, new Consumer() { @Override public void accept(Throwable t) { - requestContext.resume(t); + requestContext.resume(t, true); } }); }