use of jakarta.ws.rs.ext.ExceptionMapper in project resteasy by resteasy.
the class ExceptionMapperMarshalTest method testCustomUsed.
/**
* @tpTestDetails Tests usage of custom ExceptionMapper producing json response
* @tpPassCrit The resource returns Success response
* @tpSince RESTEasy 3.0.16
*/
@Test
public void testCustomUsed() {
Type exceptionType = Types.getActualTypeArgumentsOfAnInterface(ExceptionMapperMarshalMyCustomExceptionMapper.class, ExceptionMapper.class)[0];
Assert.assertEquals(ExceptionMapperMarshalMyCustomException.class, exceptionType);
Response response = client.target(generateURL("/resource/custom")).request().get();
Assert.assertEquals(response.getStatus(), HttpResponseCodes.SC_OK);
List<ExceptionMapperMarshalErrorMessage> errors = response.readEntity(new GenericType<List<ExceptionMapperMarshalErrorMessage>>() {
});
Assert.assertEquals("The response has unexpected content", "error", errors.get(0).getError());
}
use of jakarta.ws.rs.ext.ExceptionMapper in project helidon by oracle.
the class HttpAuthProviderConfigTest method startServer.
private static void startServer(Security security) throws Throwable {
server = Routing.builder().register(JerseySupport.builder().register(TestResource.class).register(SecurityFeature.builder(security).authorizeAnnotatedOnly(true).build()).register(new ExceptionMapper<Exception>() {
@Override
public Response toResponse(Exception exception) {
exception.printStackTrace();
return Response.serverError().build();
}
}).build()).build().createServer();
CountDownLatch cdl = new CountDownLatch(1);
AtomicReference<Throwable> th = new AtomicReference<>();
server.start().whenComplete((webServer, throwable) -> {
th.set(throwable);
cdl.countDown();
});
cdl.await();
if (th.get() != null) {
throw th.get();
}
}
use of jakarta.ws.rs.ext.ExceptionMapper in project helidon by oracle.
the class PreMatchingBindingTest method initClass.
@BeforeAll
public static void initClass() throws Throwable {
Config config = Config.builder().sources(ConfigSources.classpath("pre-matching.yaml")).build();
server = Routing.builder().register(JerseySupport.builder().register(MyResource.class).register(new SecurityFeature(Security.create(config.get("security")))).register(new ExceptionMapper<Exception>() {
@Override
public Response toResponse(Exception exception) {
exception.printStackTrace();
return Response.serverError().build();
}
}).build()).build().createServer();
CountDownLatch cdl = new CountDownLatch(1);
AtomicReference<Throwable> th = new AtomicReference<>();
server.start().whenComplete((webServer, throwable) -> {
th.set(throwable);
cdl.countDown();
});
cdl.await();
if (th.get() != null) {
throw th.get();
}
client = ClientBuilder.newClient();
URI baseUri = UriBuilder.fromUri("http://localhost/").port(server.port()).build();
baseTarget = client.target(baseUri);
}
use of jakarta.ws.rs.ext.ExceptionMapper in project helidon by oracle.
the class BindingTest method initClass.
@BeforeAll
public static void initClass() throws Throwable {
Config config = Config.builder().sources(ConfigSources.classpath("bind.yaml")).build();
server = Routing.builder().register(JerseySupport.builder().register(MyResource.class).register(TestResource1.class).register(new TestResource2()).register(new SecurityFeature(Security.create(config.get("security")))).register(new ExceptionMapper<Exception>() {
@Override
public Response toResponse(Exception exception) {
exception.printStackTrace();
return Response.serverError().build();
}
}).build()).build().createServer();
CountDownLatch cdl = new CountDownLatch(1);
AtomicReference<Throwable> th = new AtomicReference<>();
server.start().whenComplete((webServer, throwable) -> {
th.set(throwable);
cdl.countDown();
});
cdl.await();
if (th.get() != null) {
throw th.get();
}
client = ClientBuilder.newClient();
URI baseUri = UriBuilder.fromUri("http://localhost/").port(server.port()).build();
baseTarget = client.target(baseUri);
}
Aggregations