io.dropwizard.setup.Bootstrap Java Examples

The following examples show how to use io.dropwizard.setup.Bootstrap. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LotteryApplication.java    From keycloak-dropwizard-integration with Apache License 2.0 6 votes vote down vote up
@Override
public void initialize(Bootstrap<LotteryConfiguration> bootstrap) {

    // set up folders for static content
    bootstrap.addBundle(new AssetsBundle("/assets/ajax", "/ajax", null, "ajax"));

    // tag::keycloak[]
    bootstrap.addBundle(new KeycloakBundle<LotteryConfiguration>() {
        @Override
        protected KeycloakConfiguration getKeycloakConfiguration(LotteryConfiguration configuration) {
            return configuration.getKeycloakConfiguration();
        }
        /* OPTIONAL: override getUserClass(), createAuthorizer() and createAuthenticator() if you want to use
         * a class other than de.ahus1.keycloak.dropwizard.User to be injected by @Auth */
    });
    // end::keycloak[]
}
 
Example #2
Source File: PublicApi.java    From pay-publicapi with MIT License 6 votes vote down vote up
@Override
public void initialize(Bootstrap<PublicApiConfig> bootstrap) {
    bootstrap.setConfigurationSourceProvider(
            new SubstitutingSourceProvider(
                    bootstrap.getConfigurationSourceProvider(),
                    new EnvironmentVariableSubstitutor(false)
            )
    );
    bootstrap.addBundle(new JedisBundle<PublicApiConfig>() {
        @Override
        public JedisFactory getJedisFactory(PublicApiConfig configuration) {
            return configuration.getJedisFactory();
        }
    });
    bootstrap.getObjectMapper().getSubtypeResolver().registerSubtypes(LogstashConsoleAppenderFactory.class);
    bootstrap.getObjectMapper().getSubtypeResolver().registerSubtypes(GovUkPayDropwizardRequestJsonLogLayoutFactory.class);
}
 
Example #3
Source File: RobeApplication.java    From robe with GNU Lesser General Public License v3.0 6 votes vote down vote up
protected T loadConfiguration(Bootstrap bootstrap) {
    if (config == null) {
        try {

            config = (T) bootstrap.getConfigurationFactoryFactory().create(
                    bootstrap.getApplication().getConfigurationClass(),
                    bootstrap.getValidatorFactory().getValidator(),
                    bootstrap.getObjectMapper(), "")
                    .build(new File(configurationPath));
        } catch (Exception e) {
            throw new RobeRuntimeException("Can't load configuration :" + configurationPath, e);
        }
    }
    return config;

}
 
Example #4
Source File: ValidateSpecCommand.java    From jobson with Apache License 2.0 6 votes vote down vote up
@Override
protected void run(Bootstrap<ApplicationConfig> bootstrap, Namespace namespace, ApplicationConfig applicationConfig) throws Exception {
    final Path jobSpecsDir = Paths.get(applicationConfig.getJobSpecConfiguration().getDir());

    final ArrayList<String> specIds = namespace.get(JOB_SPEC_IDS_ARGNAME);

    final Map<JobSpecId, List<String>> allErrors =
            specIds.stream()
                    .map(specId -> getSpecErrors(jobSpecsDir, specId))
                    .filter(entry -> entry.getValue().size() > 0)
                    .collect(toMap(e -> e.getKey(), e -> e.getValue()));

    if (allErrors.size() > 0) {
        allErrors.forEach(this::printErrors);
        System.exit(1);
    } else System.exit(0);
}
 
Example #5
Source File: GuiceBundle.java    From dropwizard-guicey with MIT License 6 votes vote down vote up
@Override
public void initialize(final Bootstrap bootstrap) {
    // perform classpath scan if required, register dropwizard bundles
    final GuiceyInitializer starter = new GuiceyInitializer(bootstrap, context);

    // resolve and init all guicey bundles
    starter.initializeBundles(bundleLookup);
    // scan for commands (if enabled)
    starter.findCommands();
    // scan for installers (if scan enabled) and installers initialization
    starter.resolveInstallers();
    // scan for extensions (if scan enabled) and validation of all registered extensions
    starter.resolveExtensions();

    starter.initFinished();
}
 
Example #6
Source File: TodoListApplication.java    From dropwizard-experiment with MIT License 6 votes vote down vote up
@Override
public void initialize(Bootstrap<TodoListConfiguration> bootstrap) {
    ebeanBundle = new EbeanBundle();
    //rabbitMqBundle = new RabbitMQBundle();

    // This outputs xDateTimes as ISO strings rather than an array of numbers in JSON.
    bootstrap.getObjectMapper().disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);

    bootstrap.addBundle(new Java8Bundle());
    bootstrap.addBundle(ebeanBundle);
    //bootstrap.addBundle(rabbitMqBundle);
    bootstrap.addBundle(new OAuth2Bundle(ebeanBundle));
    bootstrap.addBundle(new TodoClientBundle());
    bootstrap.addBundle(new MigrationsBundle<TodoListConfiguration>() {
        @Override
        public DataSourceFactory getDataSourceFactory(TodoListConfiguration configuration) {
            return configuration.getDatabaseConfig();
        }
    });

    // The anonymous subclass seems to be needed for the config type to be picked up correctly.
    bootstrap.addCommand(new WorkersCommand<TodoListConfiguration>(TodoListApplication.this) {});
    bootstrap.addCommand(new DbDiffCommand<TodoListConfiguration>() {});
}
 
Example #7
Source File: NiPingMonitorApplication.java    From SAPNetworkMonitor with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void initialize(Bootstrap<ServerConfiguration> bootstrap) {

    bootstrap.addBundle(new MigrationsBundle<ServerConfiguration>() {
        @Override
        public DataSourceFactory getDataSourceFactory(ServerConfiguration configuration) {
            return configuration.getDataSourceFactory();
        }
    });

    bootstrap.addBundle(new AssetsBundle("/com/cloudwise/sap/niping/view/static", "/static", null, "static"));
    bootstrap.addBundle(new AssetsBundle("/com/cloudwise/sap/niping/view/vendor", "/vendor", null, "vendor"));
    bootstrap.addBundle(new ViewBundle<ServerConfiguration>());
}
 
Example #8
Source File: TrellisApplication.java    From trellis with Apache License 2.0 5 votes vote down vote up
@Override
public void initialize(final Bootstrap<AppConfiguration> bootstrap) {
    super.initialize(bootstrap);
    bootstrap.addBundle(new MigrationsBundle<AppConfiguration>() {
        @Override
        public DataSourceFactory getDataSourceFactory(final AppConfiguration config) {
            return config.getDataSourceFactory();
        }
        @Override
        public String getMigrationsFileName() {
            return "org/trellisldp/jdbc/migrations.yml";
        }
    });
}
 
Example #9
Source File: AddUserCommand.java    From keywhiz with Apache License 2.0 5 votes vote down vote up
@Override protected void run(Bootstrap<KeywhizConfig> bootstrap, Namespace namespace,
                             KeywhizConfig config) throws Exception {
  DataSource dataSource = config.getDataSourceFactory()
    .build(new MetricRegistry(), "add-user-datasource");

  Console console = System.console();
  System.out.format("New username:");
  String user = console.readLine();
  System.out.format("password for '%s': ", user);
  char[] password = console.readPassword();
  DSLContext dslContext = DSLContexts.databaseAgnostic(dataSource);
  new UserDAO(dslContext).createUser(user, new String(password));
}
 
Example #10
Source File: NewCommand.java    From jobson with Apache License 2.0 5 votes vote down vote up
@Override
public void run(Bootstrap<?> bootstrap, Namespace namespace) throws Exception {
    try {
        final Path configPath = Paths.get(WORKSPACE_CONFIG_FILENAME);
        tryWriteFile(configPath, openResourceFile("config-template.yml"));

        final Path usersPath = Paths.get(WORKSPACE_USER_FILENAME);
        tryWriteFile(usersPath, toInputStream("", Charset.forName("UTF-8")));

        final Path specDir = Paths.get(WORKSPACE_SPECS_DIRNAME);
        tryCreateDir(specDir);

        if (namespace.getBoolean(DEMO_ARG_NAME)) {
            tryWriteDemoSpec(specDir);
        }

        final Path jobsDir = Paths.get(WORKSPACE_JOBS_DIRNAME);
        tryCreateDir(jobsDir);

        final Path wdsDir = Paths.get(WORKSPACE_WDS_DIRNAME);
        tryCreateDir(wdsDir);

        System.out.println("Deployment created. Remember to add users (`user add`, `user passwd`), specs (`generate spec`), and boot the server (`serve`)");
        System.exit(0);
    } catch (IOException ex) {
        System.err.println(ex.toString());
        System.err.println(
                "Error creating jobson files/directories. Do you have file permissions? " +
                "Could some of the files already exist (this app won't overwrite files)?");
        System.exit(1);
    }
}
 
Example #11
Source File: SundialBundleITBase.java    From dropwizard-sundial with Apache License 2.0 5 votes vote down vote up
@Override
public void initialize(Bootstrap<TestConfiguration> bootstrap) {
    super.initialize(bootstrap);
    bootstrap.addBundle(new SundialBundle<TestConfiguration>() {
        @Override
        public SundialConfiguration getSundialConfiguration(TestConfiguration configuration) {
            return configuration.sundial;
        }
    });
}
 
Example #12
Source File: LotteryApplication.java    From keycloak-dropwizard-integration with Apache License 2.0 5 votes vote down vote up
@Override
public void initialize(Bootstrap<LotteryConfiguration> bootstrap) {

    // set up folders for static content
    bootstrap.addBundle(new AssetsBundle("/assets/css", "/css", null, "css"));
    bootstrap.addBundle(new AssetsBundle("/assets/js", "/js", null, "js"));
    bootstrap.addBundle(new AssetsBundle("/assets/fonts", "/fonts", null, "fonts"));
    bootstrap.addBundle(new AssetsBundle("/assets/html", "/html", null, "html"));

    // setup Freemarker views.
    bootstrap.addBundle(new ViewBundle());

}
 
Example #13
Source File: ThirdEyeDashboardApplication.java    From incubator-pinot with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public void initialize(Bootstrap<ThirdEyeDashboardConfiguration> bootstrap) {
  bootstrap.addBundle(new ViewBundle());
  bootstrap.addBundle(new HelperBundle());
  bootstrap.addBundle(new RedirectBundle(new PathRedirect("/", "/app/#/home")));
  bootstrap.addBundle(new AssetsBundle("/app/", "/app", "index.html", "app"));
  bootstrap.addBundle(new AssetsBundle("/assets", "/assets", null, "assets"));
  bootstrap.addBundle(new AssetsBundle("/assets/css", "/assets/css", null, "css"));
  bootstrap.addBundle(new AssetsBundle("/assets/js", "/assets/js", null, "js"));
  bootstrap.addBundle(new AssetsBundle("/assets/lib", "/assets/lib", null, "lib"));
  bootstrap.addBundle(new AssetsBundle("/assets/img", "/assets/img", null, "img"));
  bootstrap.addBundle(new AssetsBundle("/assets/data", "/assets/data", null, "data"));
  bootstrap.addBundle(new ThirdEyeSwaggerBundle());
}
 
Example #14
Source File: UseraddCommand.java    From jobson with Apache License 2.0 5 votes vote down vote up
@Override
protected void run(Bootstrap<ApplicationConfig> bootstrap, Namespace namespace, ApplicationConfig applicationConfig) throws Exception {
    final UserId login = new UserId(namespace.get(LOGIN_ARG));
    final File userFile = new File(applicationConfig.getUsersConfiguration().getFile());
    final FilesystemUserDAO dao = new FilesystemUserDAO(userFile);

    final boolean userExists = dao.getUserCredentialsById(login).isPresent();

    if (!userExists) {
        addNewUser(namespace, dao, login);
    } else {
        System.err.println(format("user '%s' already exists, you can set this user's password with `passwd`.", login));
        System.exit(1);
    }
}
 
Example #15
Source File: CreateSelfSignedCertificate.java    From java-certificate-authority with Apache License 2.0 5 votes vote down vote up
@Override
public void run(final Bootstrap<?> bootstrap, final Namespace namespace) throws Exception {
  final String subject = namespace.getString("subject");
  final String out = namespace.getString("out");
  final String password = namespace.getString("password");
  final String cert = namespace.getString("cert");

  final DistinguishedName dn = dn().setCn(subject).build();
  final RootCertificate root = createSelfSignedCertificate(dn).build();
  root.exportPkcs12(out, password.toCharArray(), subject);
  root.save(cert);
  System.out.format("KeyStore %s created with certificate %s.", out, subject);
}
 
Example #16
Source File: MainDc.java    From SeaCloudsPlatform with Apache License 2.0 5 votes vote down vote up
@Override
public void initialize(Bootstrap<DCConfiguration> bootstrap) {
    
    bootstrap.setConfigurationSourceProvider(
            new SubstitutingSourceProvider(bootstrap.getConfigurationSourceProvider(),
                    new EnvironmentVariableSubstitutor(false)
            )
    );
    
}
 
Example #17
Source File: TranslationService.java    From talk-kafka-zipkin with MIT License 5 votes vote down vote up
@Override
public void initialize(Bootstrap<TranslationServiceConfiguration> bootstrap) {
	// Enable variable substitution with environment variables
	bootstrap.setConfigurationSourceProvider(
			new SubstitutingSourceProvider(bootstrap.getConfigurationSourceProvider(),
					new EnvironmentVariableSubstitutor(false)));
}
 
Example #18
Source File: TestApplication.java    From dropwizard-guicier with Apache License 2.0 5 votes vote down vote up
@Override
public void initialize(final Bootstrap<Configuration> bootstrap) {
    final GuiceBundle<Configuration> jersey2GuiceBundle = GuiceBundle.defaultBuilder(Configuration.class)
        .modules(new TestModule())
        .build();
    bootstrap.addBundle(jersey2GuiceBundle);
}
 
Example #19
Source File: HealthCheckCommand.java    From dropwizard-experiment with MIT License 5 votes vote down vote up
@Override
public void run(Bootstrap<?> bootstrap, Namespace namespace) throws Exception {
    String url = namespace.getString("url");

    boolean healthy = new HealthChecker(url, namespace.getLong("duration")).check();

    if (!healthy) {
        System.exit(-1);
    }
    Unirest.shutdown();
}
 
Example #20
Source File: Main.java    From dcos-cassandra-service with Apache License 2.0 5 votes vote down vote up
@Override
public void initialize(Bootstrap<MutableSchedulerConfiguration> bootstrap) {
  super.initialize(bootstrap);

  StrSubstitutor strSubstitutor = new StrSubstitutor(new EnvironmentVariableLookup(false));
  strSubstitutor.setEnableSubstitutionInVariables(true);

  bootstrap.addBundle(new Java8Bundle());
  bootstrap.setConfigurationSourceProvider(
    new SubstitutingSourceProvider(
      bootstrap.getConfigurationSourceProvider(),
      strSubstitutor));
}
 
Example #21
Source File: Main.java    From dcos-cassandra-service with Apache License 2.0 5 votes vote down vote up
@Override
public void initialize(Bootstrap<CassandraExecutorConfiguration> bootstrap) {
    super.initialize(bootstrap);

    bootstrap.addBundle(new Java8Bundle());
    bootstrap.setConfigurationSourceProvider(
            new SubstitutingSourceProvider(
                    bootstrap.getConfigurationSourceProvider(),
                    new StrSubstitutor(
                            new EnvironmentVariableLookup(false))));
}
 
Example #22
Source File: FoxtrotServer.java    From foxtrot with Apache License 2.0 5 votes vote down vote up
@Override
public void initialize(Bootstrap<FoxtrotServerConfiguration> bootstrap) {
    bootstrap.setConfigurationSourceProvider(
            new SubstitutingSourceProvider(bootstrap.getConfigurationSourceProvider(), new EnvironmentVariableSubstitutor(false)));
    bootstrap.addBundle(new AssetsBundle("/console/echo/", "/", "browse-events.htm", "console"));
    bootstrap.addBundle(new OorBundle<FoxtrotServerConfiguration>() {
        public boolean withOor() {
            return false;
        }
    });

    final SwaggerBundleConfiguration swaggerBundleConfiguration = getSwaggerBundleConfiguration();

    bootstrap.addBundle(new SwaggerBundle<FoxtrotServerConfiguration>() {
        @Override
        protected SwaggerBundleConfiguration getSwaggerBundleConfiguration(FoxtrotServerConfiguration configuration) {
            return swaggerBundleConfiguration;
        }
    });

    bootstrap.addBundle(GuiceBundle.<FoxtrotServerConfiguration>builder()
                                .enableAutoConfig("com.flipkart.foxtrot")
                                .modules(
                                        new FoxtrotModule())
                                .useWebInstallers()
                                .printDiagnosticInfo()
                                .build(Stage.PRODUCTION));
    bootstrap.addCommand(new InitializerCommand());
    configureObjectMapper(bootstrap.getObjectMapper());
}
 
Example #23
Source File: DashboardApplication.java    From SeaCloudsPlatform with Apache License 2.0 5 votes vote down vote up
@Override
public void initialize(Bootstrap<DashboardConfiguration> bootstrap) {

    // Setting configuration from env variables
    bootstrap.setConfigurationSourceProvider(
            new SubstitutingSourceProvider(bootstrap.getConfigurationSourceProvider(),
                    new EnvironmentVariableSubstitutor(false)
            )
    );

    // Routing static assets files
    bootstrap.addBundle(new AssetsBundle("/webapp", "/", "index.html"));

    // Routing API documentation
    bootstrap.addBundle(new SwaggerBundle<DashboardConfiguration>() {
        @Override
        protected SwaggerBundleConfiguration getSwaggerBundleConfiguration(DashboardConfiguration configuration) {
            SwaggerBundleConfiguration swaggerBundleConfiguration = configuration.getSwaggerBundleConfiguration();
            swaggerBundleConfiguration.setTitle("SeaClouds REST API");
            swaggerBundleConfiguration.setDescription("This API allows to manage all the project functionality");
            swaggerBundleConfiguration.setResourcePackage("eu.seaclouds.platform.dashboard.rest");
            swaggerBundleConfiguration.setContact("[email protected]");
            swaggerBundleConfiguration.setLicense("Apache 2.0");
            swaggerBundleConfiguration.setLicenseUrl("http://www.apache.org/licenses/LICENSE-2.0");
            return swaggerBundleConfiguration;
        }
    });
}
 
Example #24
Source File: HelloWorldApplication.java    From dropwizard-consul with Apache License 2.0 5 votes vote down vote up
@Override
public void initialize(Bootstrap<HelloWorldConfiguration> bootstrap) {

  bootstrap.setConfigurationSourceProvider(
      new SubstitutingSourceProvider(
          bootstrap.getConfigurationSourceProvider(), new EnvironmentVariableSubstitutor(false)));

  bootstrap.addBundle(
      new ConsulBundle<HelloWorldConfiguration>(getName(), false, true) {
        @Override
        public ConsulFactory getConsulFactory(HelloWorldConfiguration configuration) {
          return configuration.getConsulFactory();
        }
      });
}
 
Example #25
Source File: TenacityConfiguredBundle.java    From tenacity with Apache License 2.0 5 votes vote down vote up
@Override
public void initialize(Bootstrap<?> bootstrap) {
    try {
        HystrixPlugins.getInstance().registerMetricsPublisher(new YammerMetricsPublisher(bootstrap.getMetricRegistry()));
    } catch (Exception err) {
        LOGGER.warn("Failed to register YammerMetricsPublisher with HystrixPlugins. This is what MetricsPublisher is currently registered: {}",
                HystrixPlugins.getInstance().getMetricsPublisher().getClass(), err);
    }
    executionHook.ifPresent(HystrixPlugins.getInstance()::registerCommandExecutionHook);
}
 
Example #26
Source File: MacroBaseApplicationTest.java    From macrobase with Apache License 2.0 5 votes vote down vote up
@Test
public void simpleTest() throws Exception {
    MacroBaseApplication server = new MacroBaseApplication();
    server.getName();
    server.initialize(new Bootstrap<>(server));

    Environment env = new Environment("mbenv",
                                      new ObjectMapper(),
                                      Validation.buildDefaultValidatorFactory().getValidator(),
                                      new MetricRegistry(),
                                      MacroBaseApplicationTest.class.getClassLoader());
    server.run(new MacroBaseConf(), env);
}
 
Example #27
Source File: EmoService.java    From emodb with Apache License 2.0 5 votes vote down vote up
@Override
public void initialize(Bootstrap<EmoConfiguration> bootstrap) {
    bootstrap.addCommand(new CreateKeyspacesCommand());
    bootstrap.addCommand(new RegisterCassandraCommand());
    bootstrap.addCommand(new ListCassandraCommand());
    bootstrap.addCommand(new UnregisterCassandraCommand());
    bootstrap.addCommand(new PurgeDatabusEventsCommand());
    bootstrap.addCommand(new AllTablesReportCommand());
    bootstrap.addCommand(new EncryptConfigurationApiKeyCommand());
    EmoServiceObjectMapperFactory.configure(bootstrap.getObjectMapper());

    bootstrap.getMetricRegistry().register("jvm.gc.totals", new EmoGarbageCollectorMetricSet());
}
 
Example #28
Source File: EncryptConfigurationApiKeyCommand.java    From emodb with Apache License 2.0 5 votes vote down vote up
@Override
protected void run(Bootstrap<EmoConfiguration> bootstrap, Namespace namespace, EmoConfiguration configuration)
        throws Exception {
    String apiKey = namespace.getString("api_key");
    String cluster = Objects.firstNonNull(namespace.getString("cluster"), configuration.getCluster());

    ApiKeyEncryption encryption = new ApiKeyEncryption(cluster);
    System.out.println(encryption.encrypt(apiKey));
}
 
Example #29
Source File: KeystoreApplication.java    From dcos-commons with Apache License 2.0 5 votes vote down vote up
@Override
public void initialize(Bootstrap<KeystoreConfiguration> bootstrap) {
    // Enable variable substitution with environment variables
    bootstrap.setConfigurationSourceProvider(
            new SubstitutingSourceProvider(
                    bootstrap.getConfigurationSourceProvider(),
                    new EnvironmentVariableSubstitutor(false)
            )
    );

    bootstrap.addCommand(new TLSTruststoreTestCommand<>(this));
}
 
Example #30
Source File: MainApplication.java    From SciGraph with Apache License 2.0 5 votes vote down vote up
@Override
public void initialize(Bootstrap<ApplicationConfiguration> bootstrap) {
  bootstrap.addBundle(new AssetsBundle("/swagger/", "/docs", "index.html"));
  bootstrap.addBundle(new ViewBundle<ApplicationConfiguration>() {
    @Override
    public Map<String, Map<String, String>> getViewConfiguration(
        ApplicationConfiguration configuration) {
      return new HashMap<>();
    }
  });
  bootstrap.addBundle(GuiceBundle.builder()
      .enableAutoConfig("io.scigraph.services")
      .injectorFactory(factory).modules(new SciGraphApplicationModule()).build());
}