Java 类io.dropwizard.jersey.setup.JerseyContainerHolder 实例源码

项目:jobson    文件:CustomAuthenticatorConfigTest.java   
private static AuthenticationBootstrap createTypicalAuthBootstrap() {
    final UserDAO userDAO = mock(UserDAO.class);
    final Server s = new Server(0);
    final Servlet se = new ServletContainer();
    final JerseyEnvironment env = new JerseyEnvironment(new JerseyContainerHolder(se), new DropwizardResourceConfig());

    return new AuthenticationBootstrap(env, userDAO);
}
项目:soabase    文件:SoaBundle.java   
private void initJerseyAdmin(SoaConfiguration configuration, SoaFeaturesImpl features, Ports ports, final Environment environment, AbstractBinder binder)
{
    if ( (configuration.getAdminJerseyPath() == null) || !ports.adminPort.hasPort() )
    {
        return;
    }

    String jerseyRootPath = configuration.getAdminJerseyPath();
    if ( !jerseyRootPath.endsWith("/*") )
    {
        if ( jerseyRootPath.endsWith("/") )
        {
            jerseyRootPath += "*";
        }
        else
        {
            jerseyRootPath += "/*";
        }
    }

    DropwizardResourceConfig jerseyConfig = new DropwizardResourceConfig(environment.metrics());
    jerseyConfig.setUrlPattern(jerseyRootPath);

    JerseyContainerHolder jerseyServletContainer = new JerseyContainerHolder(new ServletContainer(jerseyConfig));
    environment.admin().addServlet("soa-admin-jersey", jerseyServletContainer.getContainer()).addMapping(jerseyRootPath);

    JerseyEnvironment jerseyEnvironment = new JerseyEnvironment(jerseyServletContainer, jerseyConfig);
    features.putNamed(jerseyEnvironment, JerseyEnvironment.class, SoaFeatures.ADMIN_NAME);
    jerseyEnvironment.register(SoaApis.class);
    jerseyEnvironment.register(DiscoveryApis.class);
    jerseyEnvironment.register(DynamicAttributeApis.class);
    jerseyEnvironment.register(LoggingApis.class);
    jerseyEnvironment.register(binder);
    jerseyEnvironment.setUrlPattern(jerseyConfig.getUrlPattern());
    jerseyEnvironment.register(new JacksonMessageBodyProvider(environment.getObjectMapper()));

    checkCorsFilter(configuration, environment.admin());
    checkAdminGuiceFeature(environment, jerseyEnvironment);
}
项目:open-data-service    文件:OdsApplication.java   
@Override
@Context
public void run(OdsConfig configuration, Environment environment) {
    Injector injector = Guice.createInjector(
            new MonitoringModule(environment.metrics()),
            new ConfigModule(configuration),
            new ProcessorModule(),
            new DbModule(configuration.getCouchDb()),
            new NotificationsModule(),
            new DataModule(),
            new AuthModule(configuration.getAuth()));

    // start data grabbing
    environment.lifecycle().manage(injector.getInstance(DataSourceManager.class));
    environment.jersey().getResourceConfig().register(MultiPartFeature.class);
    environment.jersey().getResourceConfig().register(injector.getInstance(AuthBinder.class));
    environment.jersey().register(injector.getInstance(DataSourceApi.class));
    environment.jersey().register(injector.getInstance(DataApi.class));
    environment.jersey().register(injector.getInstance(ProcessorChainApi.class));
    environment.jersey().register(injector.getInstance(DataViewApi.class));
    environment.jersey().register(injector.getInstance(NotificationApi.class));
    environment.jersey().register(injector.getInstance(PluginApi.class));
    environment.jersey().register(injector.getInstance(ProcessorSpecificationApi.class));
    environment.jersey().register(injector.getInstance(VersionApi.class));
    environment.jersey().register(injector.getInstance(UserApi.class));
    environment.jersey().register(PropertyFilteringMessageBodyWriter.class);
    environment.jersey().register(new DbExceptionMapper());
    environment.jersey().register(new JsonExceptionMapper());
    environment.jersey().register(new UnauthorizedExceptionMapper());
    environment.jersey().register(new NotFoundExceptionMapper());

    // setup users
    setupDefaultUsers(injector.getInstance(UserManager.class), configuration.getAuth().getUsers());

    // setup health checks
    environment.healthChecks().register(DbHealthCheck.class.getSimpleName(), injector.getInstance(DbHealthCheck.class));
    environment.healthChecks().register(PegelOnlineHealthCheck.class.getSimpleName(), injector.getInstance(PegelOnlineHealthCheck.class));
    environment.healthChecks().register(DataSourceHealthCheck.class.getSimpleName(), injector.getInstance(DataSourceHealthCheck.class));
    environment.healthChecks().register(FilterChainHealthCheck.class.getSimpleName(), injector.getInstance(FilterChainHealthCheck.class));
    environment.healthChecks().register(DataHealthCheck.class.getSimpleName(), injector.getInstance(DataHealthCheck.class));
    environment.healthChecks().register(CepsClientHealthCheck.class.getSimpleName(), injector.getInstance(CepsClientHealthCheck.class));

    // configure administration
    DropwizardResourceConfig jerseyConfig = new DropwizardResourceConfig(environment.metrics());
    JerseyContainerHolder jerseyContainerHolder = new JerseyContainerHolder(new ServletContainer(jerseyConfig));
    jerseyConfig.register(injector.getInstance(AdminFilterChainApi.class));
    environment.admin().addServlet("admin resources", jerseyContainerHolder.getContainer()).addMapping("/admin/*");

    // setup validation for external classes
    HibernateValidatorConfiguration validatorContext = Validation.byProvider(HibernateValidator.class).configure();
    ConstraintMapping mapping = validatorContext.createConstraintMapping();
    mapping.type(ProcessorReferenceChainDescription.class).constraint(new GenericConstraintDef<>(ValidChainReference.class));

    // setup Guice DI for hibernate validator
    environment.setValidator(validatorContext.addMapping(mapping)
            .constraintValidatorFactory(new GuiceConstraintValidatorFactory(injector))
            .buildValidatorFactory()
            .getValidator());
}