Search in sources :

Example 6 with Environment

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

the class DefaultServerFactoryTest method doesNotDefaultExceptionMappers.

@Test
public void doesNotDefaultExceptionMappers() throws Exception {
    http.setRegisterDefaultExceptionMappers(false);
    assertThat(http.getRegisterDefaultExceptionMappers()).isFalse();
    Environment environment = new Environment("test", Jackson.newObjectMapper(), Validators.newValidator(), new MetricRegistry(), ClassLoader.getSystemClassLoader());
    http.build(environment);
    assertThat(environment.jersey().getResourceConfig().getSingletons()).filteredOn(x -> x instanceof ExceptionMapperBinder).isEmpty();
}
Also used : ConsoleAppenderFactory(io.dropwizard.logging.ConsoleAppenderFactory) AbstractNetworkConnector(org.eclipse.jetty.server.AbstractNetworkConnector) ScheduledFuture(java.util.concurrent.ScheduledFuture) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) Validators(io.dropwizard.jersey.validation.Validators) URL(java.net.URL) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Path(javax.ws.rs.Path) SyslogAppenderFactory(io.dropwizard.logging.SyslogAppenderFactory) Future(java.util.concurrent.Future) CharStreams(com.google.common.io.CharStreams) URLConnection(java.net.URLConnection) HttpConnectorFactory(io.dropwizard.jetty.HttpConnectorFactory) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Jackson(io.dropwizard.jackson.Jackson) YamlConfigurationFactory(io.dropwizard.configuration.YamlConfigurationFactory) BaseValidator(io.dropwizard.validation.BaseValidator) Server(org.eclipse.jetty.server.Server) Before(org.junit.Before) Environment(io.dropwizard.setup.Environment) MetricRegistry(com.codahale.metrics.MetricRegistry) ServerPushFilterFactory(io.dropwizard.jetty.ServerPushFilterFactory) Resources(com.google.common.io.Resources) ExceptionMapperBinder(io.dropwizard.setup.ExceptionMapperBinder) NetworkConnector(org.eclipse.jetty.server.NetworkConnector) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DiscoverableSubtypeResolver(io.dropwizard.jackson.DiscoverableSubtypeResolver) Test(org.junit.Test) FileAppenderFactory(io.dropwizard.logging.FileAppenderFactory) InputStreamReader(java.io.InputStreamReader) File(java.io.File) StandardCharsets(java.nio.charset.StandardCharsets) Executors(java.util.concurrent.Executors) TimeUnit(java.util.concurrent.TimeUnit) CountDownLatch(java.util.concurrent.CountDownLatch) Connector(org.eclipse.jetty.server.Connector) Assert.assertEquals(org.junit.Assert.assertEquals) ExceptionMapperBinder(io.dropwizard.setup.ExceptionMapperBinder) MetricRegistry(com.codahale.metrics.MetricRegistry) Environment(io.dropwizard.setup.Environment) Test(org.junit.Test)

Example 7 with Environment

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

the class EnvironmentCommand method run.

@Override
protected void run(Bootstrap<T> bootstrap, Namespace namespace, T configuration) throws Exception {
    final Environment environment = new Environment(bootstrap.getApplication().getName(), bootstrap.getObjectMapper(), bootstrap.getValidatorFactory().getValidator(), bootstrap.getMetricRegistry(), bootstrap.getClassLoader(), bootstrap.getHealthCheckRegistry());
    configuration.getMetricsFactory().configure(environment.lifecycle(), bootstrap.getMetricRegistry());
    configuration.getServerFactory().configure(environment);
    bootstrap.run(configuration, environment);
    application.run(configuration, environment);
    run(environment, namespace, configuration);
}
Also used : Environment(io.dropwizard.setup.Environment)

Example 8 with Environment

use of io.dropwizard.setup.Environment in project keywhiz by square.

the class ServiceModule method configure.

@Override
protected void configure() {
    // Initialize the BouncyCastle security provider for cryptography support.
    BouncyCastle.require();
    bind(Clock.class).toInstance(Clock.systemUTC());
    install(new CookieModule(config.getCookieKey()));
    install(new CryptoModule(config.getDerivationProviderClass(), config.getContentKeyStore()));
    bind(CookieConfig.class).annotatedWith(SessionCookie.class).toInstance(config.getSessionCookieConfig());
    bind(CookieConfig.class).annotatedWith(Xsrf.class).toInstance(config.getXsrfCookieConfig());
    // TODO(justin): Consider https://github.com/HubSpot/dropwizard-guice.
    bind(Environment.class).toInstance(environment);
    bind(Configuration.class).toInstance(config);
    bind(KeywhizConfig.class).toInstance(config);
}
Also used : CryptoModule(keywhiz.service.crypto.CryptoModule) Configuration(io.dropwizard.Configuration) Xsrf(keywhiz.auth.xsrf.Xsrf) Environment(io.dropwizard.setup.Environment) CookieModule(keywhiz.auth.cookie.CookieModule) SessionCookie(keywhiz.auth.cookie.SessionCookie) Clock(java.time.Clock)

Example 9 with Environment

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

the class DBIExceptionsBundleTest method test.

@Test
public void test() {
    Environment environment = mock(Environment.class);
    JerseyEnvironment jerseyEnvironment = mock(JerseyEnvironment.class);
    when(environment.jersey()).thenReturn(jerseyEnvironment);
    new DBIExceptionsBundle().run(environment);
    verify(jerseyEnvironment, times(1)).register(isA(LoggingSQLExceptionMapper.class));
    verify(jerseyEnvironment, times(1)).register(isA(LoggingDBIExceptionMapper.class));
}
Also used : JerseyEnvironment(io.dropwizard.jersey.setup.JerseyEnvironment) LoggingDBIExceptionMapper(io.dropwizard.jdbi.jersey.LoggingDBIExceptionMapper) LoggingSQLExceptionMapper(io.dropwizard.jdbi.jersey.LoggingSQLExceptionMapper) Environment(io.dropwizard.setup.Environment) JerseyEnvironment(io.dropwizard.jersey.setup.JerseyEnvironment) Test(org.junit.Test)

Example 10 with Environment

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

the class DBIClient method before.

@Override
protected void before() throws Throwable {
    final Environment environment = new Environment("test", Jackson.newObjectMapper(), Validators.newValidator(), new MetricRegistry(), getClass().getClassLoader());
    final DataSourceFactory dataSourceFactory = new DataSourceFactory();
    dataSourceFactory.setDriverClass("org.h2.Driver");
    dataSourceFactory.setUrl("jdbc:h2:tcp://localhost/fldb");
    dataSourceFactory.setUser("sa");
    dataSourceFactory.setPassword("");
    // Set the time zone of the database
    final DBIFactory dbiFactory = new DBIFactory() {

        @Override
        protected Optional<TimeZone> databaseTimeZone() {
            return Optional.of(dbTimeZone);
        }
    };
    dbi = dbiFactory.build(environment, dataSourceFactory, "test-jdbi-time-zones");
    // Start the DB pool
    managedObjects = environment.lifecycle().getManagedObjects();
    for (LifeCycle managedObject : managedObjects) {
        managedObject.start();
    }
}
Also used : LifeCycle(org.eclipse.jetty.util.component.LifeCycle) TimeZone(java.util.TimeZone) DataSourceFactory(io.dropwizard.db.DataSourceFactory) MetricRegistry(com.codahale.metrics.MetricRegistry) Environment(io.dropwizard.setup.Environment) DBIFactory(io.dropwizard.jdbi.DBIFactory)

Aggregations

Environment (io.dropwizard.setup.Environment)14 MetricRegistry (com.codahale.metrics.MetricRegistry)7 Test (org.junit.Test)6 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 DataSourceFactory (io.dropwizard.db.DataSourceFactory)3 LifecycleEnvironment (io.dropwizard.lifecycle.setup.LifecycleEnvironment)3 Before (org.junit.Before)3 Configuration (io.dropwizard.Configuration)2 YamlConfigurationFactory (io.dropwizard.configuration.YamlConfigurationFactory)2 Managed (io.dropwizard.lifecycle.Managed)2 Bootstrap (io.dropwizard.setup.Bootstrap)2 File (java.io.File)2 Connector (org.eclipse.jetty.server.Connector)2 Server (org.eclipse.jetty.server.Server)2 MoreObjects.firstNonNull (com.google.common.base.MoreObjects.firstNonNull)1 Strings (com.google.common.base.Strings)1 Throwables (com.google.common.base.Throwables)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 CharStreams (com.google.common.io.CharStreams)1