Search in sources :

Example 1 with ExceptionMapperBinder

use of io.dropwizard.setup.ExceptionMapperBinder in project dropwizard by dropwizard.

the class DefaultServerFactoryTest method doesNotDefaultExceptionMappers.

@Test
void doesNotDefaultExceptionMappers() {
    http.setRegisterDefaultExceptionMappers(false);
    assertThat(http.getRegisterDefaultExceptionMappers()).isFalse();
    Environment environment = new Environment("test");
    http.build(environment);
    assertThat(environment.jersey().getResourceConfig().getSingletons()).filteredOn(x -> x instanceof ExceptionMapperBinder).isEmpty();
}
Also used : ConsoleAppenderFactory(io.dropwizard.logging.ConsoleAppenderFactory) BeforeEach(org.junit.jupiter.api.BeforeEach) AbstractNetworkConnector(org.eclipse.jetty.server.AbstractNetworkConnector) ScheduledFuture(java.util.concurrent.ScheduledFuture) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) URL(java.net.URL) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Path(javax.ws.rs.Path) ConfigurationException(io.dropwizard.configuration.ConfigurationException) SyslogAppenderFactory(io.dropwizard.logging.SyslogAppenderFactory) Future(java.util.concurrent.Future) URLConnection(java.net.URLConnection) HttpConnectorFactory(io.dropwizard.jetty.HttpConnectorFactory) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Jackson(io.dropwizard.jackson.Jackson) PropertyAccessor(com.fasterxml.jackson.annotation.PropertyAccessor) YamlConfigurationFactory(io.dropwizard.configuration.YamlConfigurationFactory) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) BaseValidator(io.dropwizard.validation.BaseValidator) Server(org.eclipse.jetty.server.Server) Environment(io.dropwizard.setup.Environment) ByteStreams(io.dropwizard.util.ByteStreams) ServerPushFilterFactory(io.dropwizard.jetty.ServerPushFilterFactory) ExceptionMapperBinder(io.dropwizard.setup.ExceptionMapperBinder) NetworkConnector(org.eclipse.jetty.server.NetworkConnector) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DiscoverableSubtypeResolver(io.dropwizard.jackson.DiscoverableSubtypeResolver) ResourceConfigurationSourceProvider(io.dropwizard.configuration.ResourceConfigurationSourceProvider) IOException(java.io.IOException) JsonAutoDetect(com.fasterxml.jackson.annotation.JsonAutoDetect) FileAppenderFactory(io.dropwizard.logging.FileAppenderFactory) StandardCharsets(java.nio.charset.StandardCharsets) Executors(java.util.concurrent.Executors) Test(org.junit.jupiter.api.Test) TimeUnit(java.util.concurrent.TimeUnit) CountDownLatch(java.util.concurrent.CountDownLatch) Connector(org.eclipse.jetty.server.Connector) InputStream(java.io.InputStream) ExceptionMapperBinder(io.dropwizard.setup.ExceptionMapperBinder) Environment(io.dropwizard.setup.Environment) Test(org.junit.jupiter.api.Test)

Example 2 with ExceptionMapperBinder

use of io.dropwizard.setup.ExceptionMapperBinder in project dropwizard by dropwizard.

the class AbstractServerFactory method createAppServlet.

protected Handler createAppServlet(Server server, JerseyEnvironment jersey, ObjectMapper objectMapper, Validator validator, MutableServletContextHandler handler, @Nullable Servlet jerseyContainer, MetricRegistry metricRegistry) {
    configureSessionsAndSecurity(handler, server);
    final String allowedMethodsParam = String.join(",", allowedMethods);
    handler.addFilter(AllowedMethodsFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST)).setInitParameter(AllowedMethodsFilter.ALLOWED_METHODS_PARAM, allowedMethodsParam);
    if (enableThreadNameFilter) {
        handler.addFilter(ThreadNameFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST));
    }
    serverPush.addFilter(handler);
    if (jerseyContainer != null) {
        jerseyRootPath.ifPresent(jersey::setUrlPattern);
        jersey.register(new JacksonFeature(objectMapper));
        jersey.register(new HibernateValidationBinder(validator));
        if (registerDefaultExceptionMappers == null || registerDefaultExceptionMappers) {
            jersey.register(new ExceptionMapperBinder(detailedJsonProcessingExceptionMapper));
        }
        handler.addServlet(new ServletHolder("jersey", jerseyContainer), jersey.getUrlPattern());
    }
    final InstrumentedHandler instrumented = new InstrumentedHandler(metricRegistry);
    instrumented.setServer(server);
    instrumented.setHandler(handler);
    return instrumented;
}
Also used : InstrumentedHandler(com.codahale.metrics.jetty9.InstrumentedHandler) JacksonFeature(io.dropwizard.jersey.jackson.JacksonFeature) ExceptionMapperBinder(io.dropwizard.setup.ExceptionMapperBinder) HibernateValidationBinder(io.dropwizard.jersey.validation.HibernateValidationBinder) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) AllowedMethodsFilter(io.dropwizard.jersey.filter.AllowedMethodsFilter)

Aggregations

ExceptionMapperBinder (io.dropwizard.setup.ExceptionMapperBinder)2 InstrumentedHandler (com.codahale.metrics.jetty9.InstrumentedHandler)1 JsonAutoDetect (com.fasterxml.jackson.annotation.JsonAutoDetect)1 PropertyAccessor (com.fasterxml.jackson.annotation.PropertyAccessor)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ConfigurationException (io.dropwizard.configuration.ConfigurationException)1 ResourceConfigurationSourceProvider (io.dropwizard.configuration.ResourceConfigurationSourceProvider)1 YamlConfigurationFactory (io.dropwizard.configuration.YamlConfigurationFactory)1 DiscoverableSubtypeResolver (io.dropwizard.jackson.DiscoverableSubtypeResolver)1 Jackson (io.dropwizard.jackson.Jackson)1 AllowedMethodsFilter (io.dropwizard.jersey.filter.AllowedMethodsFilter)1 JacksonFeature (io.dropwizard.jersey.jackson.JacksonFeature)1 HibernateValidationBinder (io.dropwizard.jersey.validation.HibernateValidationBinder)1 HttpConnectorFactory (io.dropwizard.jetty.HttpConnectorFactory)1 ServerPushFilterFactory (io.dropwizard.jetty.ServerPushFilterFactory)1 ConsoleAppenderFactory (io.dropwizard.logging.ConsoleAppenderFactory)1 FileAppenderFactory (io.dropwizard.logging.FileAppenderFactory)1 SyslogAppenderFactory (io.dropwizard.logging.SyslogAppenderFactory)1 Environment (io.dropwizard.setup.Environment)1 ByteStreams (io.dropwizard.util.ByteStreams)1