@Override public Application<ServerConfiguration> newApplication() { return new ServerMain("outland.feature.server") { @Override protected List<Module> addModules( ServerConfiguration configuration, Environment environment) { return Lists.newArrayList( new ServerModule(configuration), new HystrixModule(), new RedisModule(configuration.redis), new DynamoDbModule(configuration.aws), new AuthModule(configuration.auth), new TestFeatureServiceModule(), new TestGroupModule() ); } }; }
/** * Renders configuration tree report according to provided config. * By default report padded left with one tab. Subtrees are always padded with empty lines for better * visibility. * * @param config tree rendering config * @return rendered tree */ @Override public String renderReport(final ContextTreeConfig config) { final Set<Class<?>> scopes = service.getActiveScopes(); final TreeNode root = new TreeNode("APPLICATION"); renderScopeContent(config, root, Application.class); renderSpecialScope(config, scopes, root, "BUNDLES LOOKUP", GuiceyBundleLookup.class); renderSpecialScope(config, scopes, root, "DROPWIZARD BUNDLES", Bundle.class); renderSpecialScope(config, scopes, root, "CLASSPATH SCAN", ClasspathScanner.class); final StringBuilder res = new StringBuilder().append(Reporter.NEWLINE).append(Reporter.NEWLINE); root.render(res); return res.toString(); }
/** * Process initially registered and all transitive bundles. * <ul> * <li>Executing initial bundles (registered in {@link ru.vyarus.dropwizard.guice.GuiceBundle} * and by bundle lookup)</li> * <li>During execution bundles may register other bundles (through {@link GuiceyBootstrap})</li> * <li>Execute registered bundles and repeat from previous step until no new bundles registered</li> * </ul> * Bundles duplicates are checked by type: only one bundle instance may be registered. * * @param context bundles context * @param configuration configuration object * @param environment environment object * @param application application instance */ public static void processBundles(final ConfigurationContext context, final Configuration configuration, final Environment environment, final Application application) { final List<GuiceyBundle> bundles = context.getBundles(); final List<Class<? extends GuiceyBundle>> installedBundles = Lists.newArrayList(); final GuiceyBootstrap guiceyBootstrap = new GuiceyBootstrap( context, bundles, configuration, environment, application); // iterating while no new bundles registered while (!bundles.isEmpty()) { final List<GuiceyBundle> processingBundles = Lists.newArrayList(BundleSupport.removeDuplicates(bundles)); bundles.clear(); for (GuiceyBundle bundle : removeTypes(processingBundles, installedBundles)) { final Class<? extends GuiceyBundle> bundleType = bundle.getClass(); Preconditions.checkState(!installedBundles.contains(bundleType), "State error: duplicate bundle '%s' registration", bundleType.getName()); context.setScope(bundleType); bundle.initialize(guiceyBootstrap); installedBundles.add(bundleType); context.closeScope(); } } }
/** * Used internally to register application specific injector. * * @param application application instance * @param injector injector instance * @return managed object, which must be registered to remove injector on application stop */ public static Managed registerInjector(final Application application, final Injector injector) { Preconditions.checkNotNull(application, "Application instance required"); Preconditions.checkArgument(!INJECTORS.containsKey(application), "Injector already registered for application %s", application.getClass().getName()); INJECTORS.put(application, injector); return new Managed() { @Override public void start() throws Exception { // not used } @Override public void stop() throws Exception { INJECTORS.remove(application); } }; }
public void setup( Class<? extends Application<TestConfiguration>> applicationClass, String configPath, ConfigOverride... configOverrides) { dropwizardTestSupport = new DropwizardTestSupport<>(applicationClass, ResourceHelpers.resourceFilePath(configPath), configOverrides); dropwizardTestSupport.before(); }
@SuppressWarnings("unchecked") @Override protected void configure() { bind(environment).to(Environment.class); bind(environment.healthChecks()).to(HealthCheckRegistry.class); bind(environment.lifecycle()).to(LifecycleEnvironment.class); bind(environment.metrics()).to(MetricRegistry.class); bind(environment.getValidator()).to(Validator.class); bind(configuration).to(bootstrap.getApplication().getConfigurationClass()).to(Configuration.class); bind(environment.getObjectMapper()).to(ObjectMapper.class); bind(bootstrap.getApplication()).to((Class) bootstrap.getApplication().getClass()).to(Application.class); }
@Override protected void configure() { bind(application); bind(application).to(Application.class); bind(environment); bind(environment.getObjectMapper()); bind(environment.metrics()); bind(environment.getValidator()); }
public TLSTruststoreTestCommand(Application<T> application) { this( application, "truststoretest", "Runs GET request against HTTPS secured URL with provided truststore" ); }
@Override protected void before() throws Throwable { Application application = applicationClass.newInstance(); Method method = applicationClass.getMethod("main", String[].class); String[] params = null; method.invoke(null, (Object) params); }
DropWizardServer(T builtConfig, Bootstrap<T> bootstrap, Application<T> application, Environment environment, Server jettyServer, MetricRegistry metricRegistry) { this.builtConfig = builtConfig; this.bootstrap = bootstrap; this.application = application; this.environment = environment; this.jettyServer = jettyServer; this.metricRegistry = metricRegistry; }
public GuiceyBootstrap(final ConfigurationContext context, final List<GuiceyBundle> iterationBundles, final Configuration configuration, final Environment environment, final Application application) { this.context = context; this.iterationBundles = iterationBundles; this.configuration = configuration; this.environment = environment; this.application = application; }
public GuiceyAppRule(final Class<? extends Application<C>> applicationClass, @Nullable final String configPath, final ConfigOverride... configOverrides) { this.applicationClass = applicationClass; this.configPath = configPath; for (ConfigOverride configOverride : configOverrides) { configOverride.addToSystemProperties(); } }
protected Application<C> newApplication() { try { return applicationClass.newInstance(); } catch (Exception e) { throw new IllegalStateException("Failed to instantiate application", e); } }
public AbstractAppTest(Class<? extends Application<C>> applicationClass, String configPath, ConfigOverride... configOverrides) { this.applicationClass = applicationClass; this.configPath = configPath; for (ConfigOverride configOverride : configOverrides) { configOverride.addToSystemProperties(); } }
public Application<C> newApplication() { try { return applicationClass.newInstance(); } catch (Exception e) { throw new RuntimeException(e); } }
@Test public void testGetName() { final Application<TrellisConfiguration> app = new TrellisApplication(); assertEquals("Trellis LDP", app.getName()); }
@Test public void testApplicationBound() { assertThat(jerseyLocator.getService(Application.class)).isSameAs(RULE.getApplication()); }
public TestCommand(Application<SamConfiguration> application, Optional<Description> testFilter, Class<?>... testClasses) { super(application, "test", "Runs junit tests"); this.testFilter = testFilter; this.testClasses = testClasses; this.application = application; }
public CreateDatabaseCommand(Application<SamConfiguration> application) { super(application, "dbcreate", "Create or update the db structure"); }
public AddTestdataCommand(Application<SamConfiguration> application) { super(application, "dbtestdata", "Add testdata to the database"); this.application = application; }
private EnvBinder(Application application, Environment environment) { this.application = application; this.environment = environment; }
public CrawlCommand(Application<T> application) { super("crawl", "Crawls a website"); this.application = application; this.configurationClass = application.getConfigurationClass(); }
public PutBench(Application<KTSDConfiguration> application) { super(application, "put-bench", "Benchmark KTSD puts"); }
@Override public Application<ReaperApplicationConfiguration> newApplication() { return new ReaperApplication(this.context); }
public ApplicationRule(Class<? extends Application> applicationClass) { this.applicationClass = applicationClass; }
/** * Creates a Jetty server for an application that can be started / stopped in-process * * @param config An application configuration instance (with properties set) * @param applicationClass The {@link io.dropwizard.Application} implementation class * @param <T> The configuration class * @return A Jetty server */ @SuppressWarnings("unchecked") public static <T extends Configuration> DropWizardServer<T> createServer( T config, Class<? extends Application<T>> applicationClass) throws Exception { // Create application final Application<T> application = applicationClass.getConstructor().newInstance(); // Create bootstrap final ServerCommand<T> serverCommand = new ServerCommand<T>(application); final Bootstrap<T> bootstrap = new Bootstrap<T>(application); bootstrap.addCommand(serverCommand); // Write a temporary config file File tmpConfigFile = new File( System.getProperty("java.io.tmpdir"), config.getClass().getCanonicalName() + "_" + System.currentTimeMillis()); tmpConfigFile.deleteOnExit(); bootstrap.getObjectMapper().writeValue(tmpConfigFile, config); // Parse configuration ConfigurationFactory<T> configurationFactory = bootstrap.getConfigurationFactoryFactory() .create((Class<T>) config.getClass(), bootstrap.getValidatorFactory().getValidator(), bootstrap.getObjectMapper(), "dw"); final T builtConfig = configurationFactory.build( bootstrap.getConfigurationSourceProvider(), tmpConfigFile.getAbsolutePath()); // Configure logging builtConfig.getLoggingFactory() .configure(bootstrap.getMetricRegistry(), bootstrap.getApplication().getName()); // Environment final Environment environment = new Environment(bootstrap.getApplication().getName(), bootstrap.getObjectMapper(), bootstrap.getValidatorFactory().getValidator(), bootstrap.getMetricRegistry(), bootstrap.getClassLoader()); // Initialize environment builtConfig.getMetricsFactory().configure(environment.lifecycle(), bootstrap.getMetricRegistry()); // Server final Server server = builtConfig.getServerFactory().build(environment); server.addLifeCycleListener(new AbstractLifeCycle.AbstractLifeCycleListener() { @Override public void lifeCycleStopped(LifeCycle event) { builtConfig.getLoggingFactory().stop(); } }); return new DropWizardServer(builtConfig, bootstrap, application, environment, server, environment.metrics()); }
/** * Creates a Jetty server for an application that can be started / stopped in-process * * @param config * An application configuration instance (with properties set) * @param applicationClass * The {@link io.dropwizard.Application} implementation class * @param <T> * The configuration class * @return * A Jetty server */ @SuppressWarnings("unchecked") public static <T extends Configuration> DropWizardServer<T> createServer(T config, Class<? extends Application<T>> applicationClass) throws Exception { // Create application final Application<T> application = applicationClass.getConstructor().newInstance(); // Create bootstrap final ServerCommand<T> serverCommand = new ServerCommand<T>(application); final Bootstrap<T> bootstrap = new Bootstrap<T>(application); bootstrap.addCommand(serverCommand); // Write a temporary config file File tmpConfigFile = new File( System.getProperty("java.io.tmpdir"), config.getClass().getCanonicalName() + "_" + System.currentTimeMillis()); tmpConfigFile.deleteOnExit(); bootstrap.getObjectMapper().writeValue(tmpConfigFile, config); // Parse configuration ConfigurationFactory<T> configurationFactory = bootstrap.getConfigurationFactoryFactory() .create((Class<T>) config.getClass(), bootstrap.getValidatorFactory().getValidator(), bootstrap.getObjectMapper(), "dw"); final T builtConfig = configurationFactory.build( bootstrap.getConfigurationSourceProvider(), tmpConfigFile.getAbsolutePath()); // Configure logging builtConfig.getLoggingFactory() .configure(bootstrap.getMetricRegistry(), bootstrap.getApplication().getName()); // Environment final Environment environment = new Environment(bootstrap.getApplication().getName(), bootstrap.getObjectMapper(), bootstrap.getValidatorFactory().getValidator(), bootstrap.getMetricRegistry(), bootstrap.getClassLoader()); // Initialize environment builtConfig.getMetricsFactory().configure(environment.lifecycle(), bootstrap.getMetricRegistry()); // Server final Server server = builtConfig.getServerFactory().build(environment); server.addLifeCycleListener(new AbstractLifeCycle.AbstractLifeCycleListener() { @Override public void lifeCycleStopped(LifeCycle event) { builtConfig.getLoggingFactory().stop(); } }); return new DropWizardServer(builtConfig, bootstrap, application, environment, server, environment.metrics()); }
protected void setup(Class<? extends Application<TestConfiguration>> applicationClass) { dropwizardTestSupport = new DropwizardTestSupport<>(applicationClass, ResourceHelpers.resourceFilePath("integration-test.yaml"), ConfigOverride.config("dataSource.url", "jdbc:hsqldb:mem:DbTest" + System.nanoTime() + "?hsqldb.translate_dti_types=false")); dropwizardTestSupport.before(); }
public InitializeCommand(Application<T> service, String name, String description) { super(service, name, description); }
public InitializeCommand(Application<T> service, RobeHibernateBundle hibernateBundle) { this(service, "initialize", "Runs Hibernate and initialize required columns", hibernateBundle); }
public InitializeCommand(Application<T> service, String name, String description, RobeHibernateBundle hibernateBundle) { super(service, name, description); setHibernateBundle(hibernateBundle); }
@Override public boolean isRegisteredDirectly() { return getRegisteredBy().contains(Application.class); }
private void report(final Application app) { final DiagnosticReporter reporter = new DiagnosticReporter(); InjectorLookup.getInjector(app).get().injectMembers(reporter); reporter.report(statsConfig, optionsConfig, config, treeConfig); }
private Class<?> getScope() { return currentScope == null ? Application.class : currentScope; }
public Jersey2Module(final Application application, final Environment environment, final ConfigurationContext context) { this.application = application; this.environment = environment; this.context = context; }