public void disable() { holder.setContainer(null); }
@Nullable public Servlet getJerseyServletContainer() { return jerseyServletContainer.getContainer(); }
@Override public void run(Configuration configuration, Environment environment) { environment.jersey().register(MultiPartFeature.class); } }
private UnitOfWorkApplicationListener registerUnitOfWorkListenerIfAbsent(Environment environment) { for (Object singleton : environment.jersey().getResourceConfig().getSingletons()) { if (singleton instanceof UnitOfWorkApplicationListener) { return (UnitOfWorkApplicationListener) singleton; } } final UnitOfWorkApplicationListener listener = new UnitOfWorkApplicationListener(); environment.jersey().register(listener); return listener; }
protected Handler createAppServlet(Server server, JerseyEnvironment jersey, ObjectMapper objectMapper, Validator validator, MutableServletContextHandler handler, @Nullable Servlet jerseyContainer, MetricRegistry metricRegistry) { configureSessionsAndSecurity(handler, server); final String allowedMethodsParam = allowedMethods.stream() .collect(Collectors.joining(",")); handler.addFilter(AllowedMethodsFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST)) .setInitParameter(AllowedMethodsFilter.ALLOWED_METHODS_PARAM, allowedMethodsParam); if (enableThreadNameFilter) { handler.addFilter(ThreadNameFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST)); } serverPush.addFilter(handler); if (jerseyContainer != null) { jerseyRootPath.ifPresent(jersey::setUrlPattern); jersey.register(new JacksonFeature(objectMapper)); jersey.register(new HibernateValidationBinder(validator)); if (registerDefaultExceptionMappers == null || registerDefaultExceptionMappers) { jersey.register(new ExceptionMapperBinder(detailedJsonProcessingExceptionMapper)); } handler.addServlet(new NonblockingServletHolder(jerseyContainer), jersey.getUrlPattern()); } final InstrumentedHandler instrumented = new InstrumentedHandler(metricRegistry); instrumented.setServer(server); instrumented.setHandler(handler); return instrumented; }
jerseyConfig.setContextPath(servletContext.getContextPath()); this.jerseyServletContainer = new JerseyContainerHolder(new JerseyServletContainer(jerseyConfig)); this.jerseyEnvironment = new JerseyEnvironment(jerseyServletContainer, jerseyConfig);
/** * Creates an environment and enables injecting validator feature. */ public Environment(String name, ObjectMapper objectMapper, ValidatorFactory validatorFactory, MetricRegistry metricRegistry, @Nullable ClassLoader classLoader, HealthCheckRegistry healthCheckRegistry) { this(name, objectMapper, validatorFactory.getValidator(), metricRegistry, classLoader, healthCheckRegistry); this.jerseyEnvironment.register(new InjectValidatorFeature(validatorFactory)); }
@Nullable public Servlet getJerseyServletContainer() { return jerseyServletContainer.getContainer(); }
public void replace(Function<ResourceConfig, Servlet> replace) { holder.setContainer(replace.apply(config)); }
@Override public void run(Nd4jInstrumentationConfiguration nd4jInstrumentationConfiguration, Environment environment) throws Exception { environment.jersey().register(new InstrumentationResource()); this.env = environment; }
@Override public void run(T configuration, Environment environment) throws Exception { final Map<String, Map<String, String>> options = getViewConfiguration(configuration); for (ViewRenderer viewRenderer : viewRenderers) { final Map<String, String> viewOptions = options.get(viewRenderer.getConfigurationKey()); viewRenderer.configure(viewOptions == null ? Collections.emptyMap() : viewOptions); } environment.jersey().register(new ViewMessageBodyWriter(environment.metrics(), viewRenderers)); } }
private void runRegularGraphHopper(CmdArgs configuration, Environment environment) { final GraphHopperManaged graphHopperManaged = new GraphHopperManaged(configuration, environment.getObjectMapper()); environment.lifecycle().manage(graphHopperManaged); environment.jersey().register(new AbstractBinder() { @Override protected void configure() { bind(configuration).to(CmdArgs.class); bind(graphHopperManaged).to(GraphHopperManaged.class); bind(graphHopperManaged.getGraphHopper()).to(GraphHopper.class); bind(graphHopperManaged.getGraphHopper()).to(GraphHopperAPI.class); bindFactory(HasElevation.class).to(Boolean.class).named("hasElevation"); bindFactory(LocationIndexFactory.class).to(LocationIndex.class); bindFactory(TranslationMapFactory.class).to(TranslationMap.class); bindFactory(EncodingManagerFactory.class).to(EncodingManager.class); bindFactory(GraphHopperStorageFactory.class).to(GraphHopperStorage.class); bindFactory(RasterHullBuilderFactory.class).to(DelaunayTriangulationIsolineBuilder.class); } }); if (configuration.getBool("web.change_graph.enabled", false)) { environment.jersey().register(ChangeGraphResource.class); } environment.jersey().register(NearestResource.class); environment.jersey().register(RouteResource.class); environment.jersey().register(IsochroneResource.class); environment.jersey().register(I18NResource.class); environment.jersey().register(InfoResource.class); environment.healthChecks().register("graphhopper", new GraphHopperHealthCheck(graphHopperManaged.getGraphHopper())); }
@Override public void run(Configuration configuration, Environment environment) { final SimpleServerFactory serverConfig = new SimpleServerFactory(); configuration.setServerFactory(serverConfig); final HttpConnectorFactory connectorConfig = (HttpConnectorFactory) serverConfig.getConnector(); connectorConfig.setPort(0); environment.healthChecks().register("dummy", new DummyHealthCheck()); for (Object resource : resources) { if (resource instanceof Class<?>) { environment.jersey().register((Class<?>) resource); } else { environment.jersey().register(resource); } } } }
@Override public void run(GraphHopperBundleConfiguration configuration, Environment environment) { configuration.getGraphHopperConfiguration().merge(CmdArgs.readFromSystemProperties()); // If the "?type=gpx" parameter is present, sets a corresponding media type header environment.jersey().register(new TypeGPXFilter()); // Together, these two take care that MultiExceptions thrown from RouteResource // come out as JSON or GPX, depending on the media type environment.jersey().register(new MultiExceptionMapper()); environment.jersey().register(new MultiExceptionGPXMessageBodyWriter()); environment.jersey().register(new IllegalArgumentExceptionMapper()); environment.jersey().register(new GHPointConverterProvider()); if (configuration.getGraphHopperConfiguration().has("gtfs.file")) { // switch to different API implementation when using Pt runPtGraphHopper(configuration.getGraphHopperConfiguration(), environment); } else { runRegularGraphHopper(configuration.getGraphHopperConfiguration(), environment); } }
@Override public void run(GraphHopperServerConfiguration configuration, Environment environment) { environment.jersey().register(new RootResource()); environment.servlets().addFilter("cors", CORSFilter.class).addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), false, "*"); environment.servlets().addFilter("ipfilter", new IPFilter(configuration.getGraphHopperConfiguration().get("jetty.whiteips", ""), configuration.getGraphHopperConfiguration().get("jetty.blackips", ""))).addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), false, "*"); } }
@Override public void run(HelloWorldConfiguration configuration, Environment environment) { final PersonDAO dao = new PersonDAO(hibernateBundle.getSessionFactory()); final Template template = configuration.buildTemplate(); environment.healthChecks().register("template", new TemplateHealthCheck(template)); environment.admin().addTask(new EchoTask()); environment.jersey().register(DateRequiredFeature.class); environment.jersey().register(new AuthDynamicFeature(new BasicCredentialAuthFilter.Builder<User>() .setAuthenticator(new ExampleAuthenticator()) .setAuthorizer(new ExampleAuthorizer()) .setRealm("SUPER SECRET STUFF") .buildAuthFilter())); environment.jersey().register(new AuthValueFactoryProvider.Binder<>(User.class)); environment.jersey().register(RolesAllowedDynamicFeature.class); environment.jersey().register(new HelloWorldResource(template)); environment.jersey().register(new ViewResource()); environment.jersey().register(new ProtectedResource()); environment.jersey().register(new PeopleResource(dao)); environment.jersey().register(new PersonResource(dao)); environment.jersey().register(new FilteredResource()); } }
final LocationIndex locationIndex = GraphHopperGtfs.createOrLoadIndex(ghDirectory, graphHopperStorage); final GraphHopperAPI graphHopper = new GraphHopperGtfs(ptFlagEncoder, translationMap, graphHopperStorage, locationIndex, gtfsStorage, RealtimeFeed.empty(gtfsStorage)); environment.jersey().register(new AbstractBinder() { @Override protected void configure() { environment.jersey().register(NearestResource.class); environment.jersey().register(RouteResource.class); environment.jersey().register(new PtIsochroneResource(gtfsStorage, encodingManager, graphHopperStorage, locationIndex)); environment.jersey().register(I18NResource.class); environment.jersey().register(InfoResource.class); environment.jersey().register((WriterInterceptor) context -> { if (context.getEntity() instanceof InfoResource.Info) { InfoResource.Info info = (InfoResource.Info) context.getEntity();
@Override public void run(BithubServerConfiguration config, Environment environment) throws Exception { String githubUser = config.getGithubConfiguration().getUser(); String githubToken = config.getGithubConfiguration().getToken(); String githubWebhookUser = config.getGithubConfiguration().getWebhookConfiguration().getUsername(); String githubWebhookPwd = config.getGithubConfiguration().getWebhookConfiguration().getPassword(); List<RepositoryConfiguration> githubRepositories = config.getGithubConfiguration().getRepositories(); BigDecimal payoutRate = config.getBithubConfiguration().getPayoutRate(); String organizationName = config.getOrganizationConfiguration().getName(); String donationUrl = config.getOrganizationConfiguration().getDonationUrl().toExternalForm(); String coinbaseApiKey = config.getCoinbaseConfiguration().getApiKey(); String coinbaseApiSecret = config.getCoinbaseConfiguration().getApiSecret(); GithubClient githubClient = new GithubClient(githubUser, githubToken); CoinbaseClient coinbaseClient = new CoinbaseClient(coinbaseApiKey, coinbaseApiSecret); CacheManager cacheManager = new CacheManager(coinbaseClient, githubClient, githubRepositories, payoutRate); environment.servlets().addFilter("CORS", CrossOriginFilter.class) .addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), true, "/*"); environment.lifecycle().manage(cacheManager); environment.jersey().register(new GithubController(githubRepositories, githubClient, coinbaseClient, payoutRate)); environment.jersey().register(new StatusController(cacheManager, githubRepositories)); environment.jersey().register(new DashboardController(organizationName, donationUrl, cacheManager)); environment.jersey().register(new IOExceptionMapper()); environment.jersey().register(new UnauthorizedHookExceptionMapper()); environment.jersey().register(new BasicAuthProvider<>(new GithubWebhookAuthenticator(githubWebhookUser, githubWebhookPwd), GithubWebhookAuthenticator.REALM)); }