@Override protected void initialize(UniversityFooConfiguration configuration, Environment environment) throws ClassNotFoundException { environment .addProvider(new OAuthProvider<AuthenticatedPrincipal>(new OAuthAuthenticator(configuration), "protected-resources")); environment.addResource(new UniversityResource()); }
@Override public void run(Configuration config, Environment environment) { // Suppress the "THIS SERVICE HAS NO HEALTHCHECKS" warning. // A real service would have proper health checks. environment.addHealthCheck(new FakeHealthCheck()); // Suppress the "ResourceConfig instance does not contain any root resource classes" error. // A real service would probably provide a Jersey resource or two. environment.addResource(EmptyResource.class); // Here's the interesting part: // Mount the Rack application defined in the config.ru file on the classpath at /rack. environment.addServlet(createRackServlet(), "/rack/*"); }
@Override public void run(HVDFConfiguration config, Environment environment) throws Exception { // Get the configured default MongoDB URI MongoClientURI default_uri = config.mongodb.default_database_uri; // Initialize the services as per configuration ServiceManager services = new ServiceManager(config.services, default_uri); environment.manage(services); // Register the custom ExceptionMapper to handle ServiceExceptions environment.addProvider(new ServiceExceptionMapper()); environment.addResource( new FeedResource( services.getChannelService()) ); } }
@Override public void run(Configuration configuration, Environment environment) throws Exception { environment.addResource(new PizzaResource()); environment.addHealthCheck(new PizzaHealthCheck()); environment.addProvider(new HmacAuthProvider<>(new DefaultRequestHandler<>(new PizzaAuthenticator()))); } }
@Override public void run(Reader30Configuration configuration, Environment environment) throws Exception { Mongo mongo = new Mongo(configuration.mongohost, configuration.mongoport); DB db = mongo.getDB(configuration.mongodb); JacksonDBCollection<Blog, String> blogs = JacksonDBCollection.wrap(db.getCollection("blogs"), Blog.class, String.class); MongoManaged mongoManaged = new MongoManaged(mongo); environment.manage(mongoManaged); environment.addHealthCheck(new MongoHealthCheck(mongo)); environment.addResource(new BlogResource(blogs)); environment.addResource(new IndexResource(blogs)); }
@Override public void run(OpenIDDemoConfiguration openIDDemoConfiguration, Environment environment) throws Exception { // Configure authenticator OpenIDAuthenticator authenticator = new OpenIDAuthenticator(); // Configure environment environment.scanPackagesForResourcesAndProviders(PublicHomeResource.class); // Health checks environment.addHealthCheck(new uk.co.froot.demo.openid.health.OpenIdDemoHealthCheck()); // Providers environment.addProvider(new ViewMessageBodyWriter()); environment.addProvider(new OpenIDRestrictedToProvider<User>(authenticator, "OpenID")); // Session handler environment.setSessionHandler(new SessionHandler()); } }
@Override public void run(LeaderBoardServerConfiguration configuration, Environment environment) { GitHubApiFacade apiFacade = getApiFacade(configuration); LeaderBoardStore store = getStore(apiFacade); environment.addHealthCheck(new GitHubCredentialsHealthCheck(apiFacade, configuration.getOrganization())); environment.addResource(new LeaderBoardResource(store, apiFacade.getOrg(configuration.getOrganization()))); createScheduledFetcher(configuration, environment, apiFacade, store); }
@Override protected void initialize(TodoServiceConfiguration configuration, Environment environment) throws Exception { final DatabaseFactory factory = new DatabaseFactory(environment); Database database = factory.build(configuration.getDatabase(), "todo"); final TodoDao dao = database.onDemand(TodoDao.class); dao.createTableIfNotExists(); environment.addResource(new TodoResource(dao)); environment.addResource(new HtmlPageResource()); } }
@Override public void run(Environment environment) { environment.addProvider(ViewMessageBodyWriter.class); } }
private void initializeExceptionMappers(MultiBitExchangeApiConfiguration configuration, Environment environment) { ResourceConfig jerseyResourceConfig = environment.getJerseyResourceConfig(); Set<Object> singletons = jerseyResourceConfig.getSingletons(); List<Object> toRemove = Lists.newArrayList(); for (Object singleton : singletons) { if (ExceptionMapper.class.isAssignableFrom(singleton.getClass())) { if (singleton.getClass().getName().startsWith("com.yammer.dropwizard.jersey")) { toRemove.add(singleton); } } } for (Object exceptionMapper : toRemove) { jerseyResourceConfig.getSingletons().remove(exceptionMapper); } environment.addProvider(new MultiBitExchangeExceptionMapper()); }
@Test public void runMethodWiresHealthCheck() throws Exception { service.run(configuration, environment); verify(environment).addHealthCheck(any(GitHubCredentialsHealthCheck.class)); }
private void initializeAtmosphere(MultiBitExchangeApiConfiguration configuration, Environment environment) { FilterBuilder fconfig = environment.addFilter(CrossOriginFilter.class, "/stream"); fconfig.setInitParam(CrossOriginFilter.ALLOWED_ORIGINS_PARAM, "*"); AtmosphereServlet atmosphereServlet = new AtmosphereServlet(); atmosphereServlet.framework().addInitParameter("com.sun.jersey.config.property.packages", ATMOSPHERE_RESOURCE_BASE_PACKAGE); atmosphereServlet.framework().addInitParameter("org.atmosphere.websocket.messageContentType", "application/json"); atmosphereServlet.framework().addInitParameter("com.sun.jersey.config.feature.DisableWADL", "true"); atmosphereServlet.framework().addInitParameter("org.atmosphere.cpr.AtmosphereInterceptor.disableDefaults", "true"); atmosphereServlet.framework().addInitParameter("org.atmosphere.cpr.broadcasterCacheClass", "org.atmosphere.cache.UUIDBroadcasterCache"); atmosphereServlet.framework().addInitParameter("org.atmosphere.cpr.sessionSupport", "true"); atmosphereServlet.framework().addInitParameter("org.atmosphere.cpr.AtmosphereResource.uniqueUUID", "true"); atmosphereServlet.framework().addInitParameter(ApplicationConfig.class.getName() + ".scanClassPath", "false"); environment.addServlet(atmosphereServlet, "/stream/*"); } }
@Override public void run(Environment environment) { environment.addServlet(createServlet(), uriPath + '*'); }
@Before public void setUp() throws Exception { initMocks(this); when(credentials.getUsername()).thenReturn("user1"); when(credentials.getPassword()).thenReturn("pass1"); when(configuration.getGitHubCredentials()).thenReturn(credentials); when(environment.managedScheduledExecutorService(anyString(), anyInt())).thenReturn(executorService); this.service = new LeaderBoardService() { @Override protected GitHubApiFacade getApiFacade(LeaderBoardServerConfiguration configuration) { return apiFacade; } }; }
/** * Log all the resources. */ private void logResources() { final ImmutableSet.Builder<String> builder = ImmutableSet.builder(); for (Class<?> klass : super.getJerseyResourceConfig().getClasses()) { if (klass.isAnnotationPresent(Path.class)) { builder.add(klass.getCanonicalName()); } } for (Object o : super.getJerseyResourceConfig().getSingletons()) { if (o.getClass().isAnnotationPresent(Path.class)) { builder.add(o.getClass().getCanonicalName()); } } logger.debug("resources = {}", builder.build()); }
@Override public void run(SocialiteConfiguration config, Environment environment) throws Exception { // Get the configured default MongoDB URI MongoClientURI default_uri = config.mongodb.default_database_uri; // Initialize the services as per configuration ServiceManager services = new ServiceManager(config.services, default_uri); environment.manage(services); // Register the custom ExceptionMapper to handle ServiceExceptions environment.addProvider(new ServiceExceptionMapper()); environment.addResource( new UserResource( services.getContentService(), services.getFeedService(), services.getUserGraphService() ) ); } }
@Test public void runMethodWiresResource() throws Exception { service.run(configuration, environment); verify(environment).addResource(any(LeaderBoardResource.class)); }
@Override public void run(Environment environment) { environment.addProvider(new ScalaCollectionsQueryParamInjectableProvider()); } }
private void createScheduledFetcher(LeaderBoardServerConfiguration configuration, Environment environment, GitHubApiFacade apiFacade, LeaderBoardStore store) { ScheduledExecutorService executorService = environment.managedScheduledExecutorService("comment-fetcher", 1); final CommentFetcher fetcher = new CommentFetcher(apiFacade, configuration.getOrganization(), Period.getLongest().getDaysBack()); executorService.scheduleAtFixedRate(new FetcherRunnable(store, fetcher), 0, configuration.getRefreshRateMinutes(), TimeUnit.MINUTES); }
for (Object o : super.getJerseyResourceConfig().getSingletons()) { if (o.getClass().isAnnotationPresent(Path.class)) { builder.add(o.getClass()); for (Class<?> klass : super.getJerseyResourceConfig().getClasses()) { if (klass.isAnnotationPresent(Path.class)) { builder.add(klass);