Search in sources :

Example 1 with YamlConfigurationFactory

use of io.dropwizard.configuration.YamlConfigurationFactory in project dropwizard by dropwizard.

the class DropwizardTestSupport method startIfRequired.

private void startIfRequired() {
    if (jettyServer != null) {
        return;
    }
    try {
        application = newApplication();
        final Bootstrap<C> bootstrap = new Bootstrap<C>(application) {

            @Override
            public void run(C configuration, Environment environment) throws Exception {
                environment.lifecycle().addServerLifecycleListener(server -> jettyServer = server);
                DropwizardTestSupport.this.configuration = configuration;
                DropwizardTestSupport.this.environment = environment;
                super.run(configuration, environment);
                for (ServiceListener<C> listener : listeners) {
                    try {
                        listener.onRun(configuration, environment, DropwizardTestSupport.this);
                    } catch (Exception ex) {
                        throw new RuntimeException("Error running app rule start listener", ex);
                    }
                }
            }
        };
        if (explicitConfig) {
            bootstrap.setConfigurationFactoryFactory((klass, validator, objectMapper, propertyPrefix) -> new POJOConfigurationFactory<>(configuration));
        } else if (customPropertyPrefix.isPresent()) {
            bootstrap.setConfigurationFactoryFactory((klass, validator, objectMapper, propertyPrefix) -> new YamlConfigurationFactory<>(klass, validator, objectMapper, customPropertyPrefix.get()));
        }
        application.initialize(bootstrap);
        final Command command = commandInstantiator.apply(application);
        final ImmutableMap.Builder<String, Object> file = ImmutableMap.builder();
        if (!Strings.isNullOrEmpty(configPath)) {
            file.put("file", configPath);
        }
        final Namespace namespace = new Namespace(file.build());
        command.run(bootstrap, namespace);
    } catch (Exception e) {
        Throwables.throwIfUnchecked(e);
        throw new RuntimeException(e);
    }
}
Also used : Bootstrap(io.dropwizard.setup.Bootstrap) Function(java.util.function.Function) ArrayList(java.util.ArrayList) Strings(com.google.common.base.Strings) Configuration(io.dropwizard.Configuration) Namespace(net.sourceforge.argparse4j.inf.Namespace) Command(io.dropwizard.cli.Command) YamlConfigurationFactory(io.dropwizard.configuration.YamlConfigurationFactory) Server(org.eclipse.jetty.server.Server) Nullable(javax.annotation.Nullable) Environment(io.dropwizard.setup.Environment) Application(io.dropwizard.Application) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Throwables(com.google.common.base.Throwables) Set(java.util.Set) ServerCommand(io.dropwizard.cli.ServerCommand) InvocationTargetException(java.lang.reflect.InvocationTargetException) ServerConnector(org.eclipse.jetty.server.ServerConnector) List(java.util.List) Managed(io.dropwizard.lifecycle.Managed) Optional(java.util.Optional) MoreObjects.firstNonNull(com.google.common.base.MoreObjects.firstNonNull) Connector(org.eclipse.jetty.server.Connector) YamlConfigurationFactory(io.dropwizard.configuration.YamlConfigurationFactory) InvocationTargetException(java.lang.reflect.InvocationTargetException) ImmutableMap(com.google.common.collect.ImmutableMap) Namespace(net.sourceforge.argparse4j.inf.Namespace) Command(io.dropwizard.cli.Command) ServerCommand(io.dropwizard.cli.ServerCommand) Bootstrap(io.dropwizard.setup.Bootstrap) Environment(io.dropwizard.setup.Environment)

Example 2 with YamlConfigurationFactory

use of io.dropwizard.configuration.YamlConfigurationFactory in project dropwizard by dropwizard.

the class RequestLogFactoryTest method setUp.

@Before
public void setUp() throws Exception {
    final ObjectMapper objectMapper = Jackson.newObjectMapper();
    objectMapper.getSubtypeResolver().registerSubtypes(ConsoleAppenderFactory.class, FileAppenderFactory.class, SyslogAppenderFactory.class);
    this.logbackAccessRequestLogFactory = new YamlConfigurationFactory<>(LogbackAccessRequestLogFactory.class, BaseValidator.newValidator(), objectMapper, "dw").build(new File(Resources.getResource("yaml/requestLog.yml").toURI()));
}
Also used : YamlConfigurationFactory(io.dropwizard.configuration.YamlConfigurationFactory) File(java.io.File) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Before(org.junit.Before)

Example 3 with YamlConfigurationFactory

use of io.dropwizard.configuration.YamlConfigurationFactory in project dropwizard by dropwizard.

the class DefaultServerFactoryTest method setUp.

@Before
public void setUp() throws Exception {
    final ObjectMapper objectMapper = Jackson.newObjectMapper();
    objectMapper.getSubtypeResolver().registerSubtypes(ConsoleAppenderFactory.class, FileAppenderFactory.class, SyslogAppenderFactory.class, HttpConnectorFactory.class);
    http = new YamlConfigurationFactory<>(DefaultServerFactory.class, BaseValidator.newValidator(), objectMapper, "dw").build(new File(Resources.getResource("yaml/server.yml").toURI()));
}
Also used : YamlConfigurationFactory(io.dropwizard.configuration.YamlConfigurationFactory) File(java.io.File) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Before(org.junit.Before)

Example 4 with YamlConfigurationFactory

use of io.dropwizard.configuration.YamlConfigurationFactory in project dropwizard by dropwizard.

the class LogbackClassicRequestLogFactoryTest method setUp.

@Before
public void setUp() throws Exception {
    final ObjectMapper objectMapper = Jackson.newObjectMapper();
    objectMapper.getSubtypeResolver().registerSubtypes(ConsoleAppenderFactory.class, FileAppenderFactory.class, SyslogAppenderFactory.class);
    this.requestLog = new YamlConfigurationFactory<>(RequestLogFactory.class, BaseValidator.newValidator(), objectMapper, "dw").build(new File(Resources.getResource("yaml/logbackClassicRequestLog.yml").toURI()));
}
Also used : YamlConfigurationFactory(io.dropwizard.configuration.YamlConfigurationFactory) File(java.io.File) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Before(org.junit.Before)

Aggregations

ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 YamlConfigurationFactory (io.dropwizard.configuration.YamlConfigurationFactory)4 File (java.io.File)3 Before (org.junit.Before)3 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 Application (io.dropwizard.Application)1 Configuration (io.dropwizard.Configuration)1 Command (io.dropwizard.cli.Command)1 ServerCommand (io.dropwizard.cli.ServerCommand)1 Managed (io.dropwizard.lifecycle.Managed)1 Bootstrap (io.dropwizard.setup.Bootstrap)1 Environment (io.dropwizard.setup.Environment)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Optional (java.util.Optional)1