forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sanitize the behavior of provided ExceptionMapper classes in dev-mode
User provided ExceptionMapper classes now takes precedence over the Quarkus provided NotFoundExceptionMapper. This is done in a way that does not change anything but this specific behavior, everything else concerning exception handling continues to work as before. Note also that this does not change the spec compliance in any way Fixes: quarkusio#7883
- Loading branch information
Showing
4 changed files
with
162 additions
and
5 deletions.
There are no files selected for viewing
64 changes: 64 additions & 0 deletions
64
...io/quarkus/resteasy/reactive/server/test/devmode/QuarkusDefaultExceptionHandlingTest.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,64 @@ | ||
package io.quarkus.resteasy.reactive.server.test.devmode; | ||
|
||
import static org.hamcrest.CoreMatchers.containsString; | ||
|
||
import java.util.function.Supplier; | ||
|
||
import jakarta.ws.rs.Consumes; | ||
import jakarta.ws.rs.GET; | ||
import jakarta.ws.rs.Path; | ||
import jakarta.ws.rs.Produces; | ||
import jakarta.ws.rs.core.MediaType; | ||
|
||
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.QuarkusDevModeTest; | ||
import io.restassured.RestAssured; | ||
|
||
public class QuarkusDefaultExceptionHandlingTest { | ||
|
||
@RegisterExtension | ||
static QuarkusDevModeTest TEST = new QuarkusDevModeTest() | ||
.setArchiveProducer(new Supplier<>() { | ||
@Override | ||
public JavaArchive get() { | ||
return ShrinkWrap.create(JavaArchive.class) | ||
.addClasses(Resource.class); | ||
} | ||
|
||
}); | ||
|
||
@Test | ||
public void testDefaultErrorHandler() { | ||
RestAssured.given().accept("text/html") | ||
.get("/test/exception") | ||
.then() | ||
.statusCode(500) | ||
.body(containsString("Internal Server Error"), containsString("dummy exception")); | ||
} | ||
|
||
@Test | ||
public void testNotFoundErrorHandler() { | ||
RestAssured.given().accept("text/html") | ||
.get("/test/exception2") | ||
.then() | ||
.statusCode(404) | ||
.body(containsString("404 - Resource Not Found")); | ||
} | ||
|
||
@Path("test") | ||
@Produces(MediaType.TEXT_PLAIN) | ||
@Consumes(MediaType.TEXT_PLAIN) | ||
public static class Resource { | ||
|
||
@Path("exception") | ||
@GET | ||
@Produces("text/html") | ||
public String exception() { | ||
throw new RuntimeException("dummy exception"); | ||
} | ||
} | ||
} |
72 changes: 72 additions & 0 deletions
72
...a/io/quarkus/resteasy/reactive/server/test/devmode/UserProvidedExceptionHandlingTest.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,72 @@ | ||
package io.quarkus.resteasy.reactive.server.test.devmode; | ||
|
||
import java.util.function.Supplier; | ||
|
||
import jakarta.ws.rs.Consumes; | ||
import jakarta.ws.rs.GET; | ||
import jakarta.ws.rs.Path; | ||
import jakarta.ws.rs.Produces; | ||
import jakarta.ws.rs.core.MediaType; | ||
import jakarta.ws.rs.core.Response; | ||
import jakarta.ws.rs.ext.ExceptionMapper; | ||
import jakarta.ws.rs.ext.Provider; | ||
|
||
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.QuarkusDevModeTest; | ||
import io.restassured.RestAssured; | ||
|
||
public class UserProvidedExceptionHandlingTest { | ||
|
||
@RegisterExtension | ||
static QuarkusDevModeTest TEST = new QuarkusDevModeTest() | ||
.setArchiveProducer(new Supplier<>() { | ||
@Override | ||
public JavaArchive get() { | ||
return ShrinkWrap.create(JavaArchive.class) | ||
.addClasses(Resource.class, CustomExceptionMapper.class); | ||
} | ||
|
||
}); | ||
|
||
@Test | ||
public void testDefaultErrorHandler() { | ||
RestAssured.given().accept("text/html") | ||
.get("/test/exception") | ||
.then() | ||
.statusCode(999); | ||
} | ||
|
||
@Test | ||
public void testNotFoundErrorHandler() { | ||
RestAssured.given().accept("text/html") | ||
.get("/test/exception2") | ||
.then() | ||
.statusCode(999); | ||
} | ||
|
||
@Path("test") | ||
@Produces(MediaType.TEXT_PLAIN) | ||
@Consumes(MediaType.TEXT_PLAIN) | ||
public static class Resource { | ||
|
||
@Path("exception") | ||
@GET | ||
@Produces("text/html") | ||
public String exception() { | ||
throw new RuntimeException("dummy exception"); | ||
} | ||
} | ||
|
||
@Provider | ||
public static class CustomExceptionMapper implements ExceptionMapper<Exception> { | ||
@Override | ||
public Response toResponse(Exception exception) { | ||
return Response.status(999).build(); | ||
} | ||
} | ||
|
||
} |
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