io.dropwizard.server.AbstractServerFactory Java Examples

The following examples show how to use io.dropwizard.server.AbstractServerFactory. 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: StreamlineApplication.java    From streamline with Apache License 2.0 6 votes vote down vote up
@Override
public void run(StreamlineConfiguration configuration, Environment environment) throws Exception {
    AbstractServerFactory sf = (AbstractServerFactory) configuration.getServerFactory();
    // disable all default exception mappers
    sf.setRegisterDefaultExceptionMappers(false);

    environment.jersey().register(GenericExceptionMapper.class);

    registerResources(configuration, environment, getSubjectFromLoginImpl(configuration));

    if (configuration.isEnableCors()) {
        List<String> urlPatterns = configuration.getCorsUrlPatterns();
        if (urlPatterns != null && !urlPatterns.isEmpty()) {
            enableCORS(environment, urlPatterns);
        }
    }

    setupCustomTrustStore(configuration);

    addSecurityHeaders(environment);

    addServletFilters(configuration, environment);

}
 
Example #2
Source File: FoxtrotServer.java    From foxtrot with Apache License 2.0 6 votes vote down vote up
@Override
public void run(FoxtrotServerConfiguration configuration, Environment environment) throws Exception {
    // Enable CORS headers
    final FilterRegistration.Dynamic cors = environment.servlets()
            .addFilter("CORS", CrossOriginFilter.class);

    // Configure CORS parameters
    cors.setInitParameter("allowedOrigins", "*");
    cors.setInitParameter("allowedHeaders", "X-Requested-With,Content-Type,Accept,Origin");
    cors.setInitParameter("allowedMethods", "OPTIONS,GET,PUT,POST,DELETE,HEAD");

    // Add URL mapping
    cors.addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), true, "/*");

    ((AbstractServerFactory)configuration.getServerFactory()).setJerseyRootPath("/foxtrot");

    MetricUtil.setup(environment.metrics());
    ElasticsearchUtils.setTableNamePrefix(configuration.getElasticsearch());

}
 
Example #3
Source File: TenacityConfiguredBundle.java    From tenacity with Apache License 2.0 5 votes vote down vote up
protected void configureHystrix(T configuration, Environment environment) {
    final ServerFactory serverFactory = configuration.getServerFactory();
    final Duration shutdownGracePeriod =
            (serverFactory instanceof AbstractServerFactory)
            ? ((AbstractServerFactory) serverFactory).getShutdownGracePeriod()
            : Duration.seconds(30L);
    environment.lifecycle().manage(new ManagedHystrix(shutdownGracePeriod));
}