Search in sources :

Example 11 with ExceptionMapper

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());
}
Also used : Response(jakarta.ws.rs.core.Response) GenericType(jakarta.ws.rs.core.GenericType) Type(java.lang.reflect.Type) ExceptionMapperMarshalMyCustomExceptionMapper(org.jboss.resteasy.test.providers.jackson2.resource.ExceptionMapperMarshalMyCustomExceptionMapper) ExceptionMapperMarshalMyCustomExceptionMapper(org.jboss.resteasy.test.providers.jackson2.resource.ExceptionMapperMarshalMyCustomExceptionMapper) ExceptionMapperIOExceptionMapper(org.jboss.resteasy.test.providers.jackson2.resource.ExceptionMapperIOExceptionMapper) ExceptionMapper(jakarta.ws.rs.ext.ExceptionMapper) ExceptionMapperMarshalErrorMessage(org.jboss.resteasy.test.providers.jackson2.resource.ExceptionMapperMarshalErrorMessage) List(java.util.List) Test(org.junit.Test)

Example 12 with ExceptionMapper

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();
    }
}
Also used : ExceptionMapper(jakarta.ws.rs.ext.ExceptionMapper) AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 13 with ExceptionMapper

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);
}
Also used : ExceptionMapper(jakarta.ws.rs.ext.ExceptionMapper) Config(io.helidon.config.Config) AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch) URI(java.net.URI) ForbiddenException(jakarta.ws.rs.ForbiddenException) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 14 with ExceptionMapper

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);
}
Also used : ExceptionMapper(jakarta.ws.rs.ext.ExceptionMapper) Config(io.helidon.config.Config) AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch) URI(java.net.URI) IOException(java.io.IOException) ForbiddenException(jakarta.ws.rs.ForbiddenException) BeforeAll(org.junit.jupiter.api.BeforeAll)

Aggregations

ExceptionMapper (jakarta.ws.rs.ext.ExceptionMapper)14 Response (jakarta.ws.rs.core.Response)6 Type (java.lang.reflect.Type)4 CountDownLatch (java.util.concurrent.CountDownLatch)4 AtomicReference (java.util.concurrent.atomic.AtomicReference)4 Config (io.helidon.config.Config)3 Test (org.junit.Test)3 BeforeAll (org.junit.jupiter.api.BeforeAll)3 ForbiddenException (jakarta.ws.rs.ForbiddenException)2 ParameterizedType (java.lang.reflect.ParameterizedType)2 URI (java.net.URI)2 Security (io.helidon.security.Security)1 EJBAccessException (jakarta.ejb.EJBAccessException)1 EJBException (jakarta.ejb.EJBException)1 RuntimeType (jakarta.ws.rs.RuntimeType)1 GenericType (jakarta.ws.rs.core.GenericType)1 IOException (java.io.IOException)1 List (java.util.List)1 AbstractMapperMyCustom (org.jboss.resteasy.test.exception.resource.AbstractMapperMyCustom)1 ExceptionMapperAbstractExceptionMapper (org.jboss.resteasy.test.exception.resource.ExceptionMapperAbstractExceptionMapper)1