io.dropwizard.jersey.setup.JerseyEnvironment Java Examples
The following examples show how to use
io.dropwizard.jersey.setup.JerseyEnvironment.
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: ExampleApplication.java From okta-auth-java with Apache License 2.0 | 6 votes |
private void configureJersey(JerseyEnvironment jersey) { // Load any resource in the resources package String baseResourcePackage = getClass().getPackage().getName() + ".resources"; jersey.packages(baseResourcePackage); AuthenticationClient client = AuthenticationClients.builder() .build(); // use @Inject to bind the DAOs jersey.register(new AbstractBinder() { @Override protected void configure() { bind(new DefaultStormtrooperDao()).to(StormtrooperDao.class); bind(new DefaultTieCraftDao()).to(TieCraftDao.class); bind(client).to(AuthenticationClient.class); } }); }
Example #2
Source File: PublicApi.java From pay-publicapi with MIT License | 6 votes |
private void attachExceptionMappersTo(JerseyEnvironment jersey) { jersey.register(ViolationExceptionMapper.class); jersey.register(CreateChargeExceptionMapper.class); jersey.register(GetChargeExceptionMapper.class); jersey.register(GetEventsExceptionMapper.class); jersey.register(SearchChargesExceptionMapper.class); jersey.register(SearchRefundsExceptionMapper.class); jersey.register(CancelChargeExceptionMapper.class); jersey.register(PaymentValidationExceptionMapper.class); jersey.register(RefundsValidationExceptionMapper.class); jersey.register(BadRefundsRequestExceptionMapper.class); jersey.register(BadRequestExceptionMapper.class); jersey.register(CreateRefundExceptionMapper.class); jersey.register(GetRefundExceptionMapper.class); jersey.register(GetRefundsExceptionMapper.class); jersey.register(CreateAgreementExceptionMapper.class); jersey.register(GetAgreementExceptionMapper.class); jersey.register(CaptureChargeExceptionMapper.class); jersey.register(JsonProcessingExceptionMapper.class); }
Example #3
Source File: SoaBundle.java From soabase with Apache License 2.0 | 6 votes |
private void checkAdminGuiceFeature(final Environment environment, final JerseyEnvironment jerseyEnvironment) { try { Feature feature = new Feature() { @Override public boolean configure(FeatureContext context) { for ( Object obj : environment.jersey().getResourceConfig().getSingletons() ) { if ( obj instanceof InternalFeatureRegistrations ) { ((InternalFeatureRegistrations)obj).apply(context); } } return true; } }; jerseyEnvironment.register(feature); } catch ( Exception ignore ) { // ignore - GuiceBundle not added } }
Example #4
Source File: GoodbyeApp.java From soabase with Apache License 2.0 | 6 votes |
@Override protected void internalRun(Configuration configuration, Environment environment) { Metric metric = new Gauge<Integer>() { final Random random = new Random(); @Override public Integer getValue() { return random.nextInt(100); } }; environment.metrics().register("goodbye-random", metric); environment.jersey().register(GoodbyeResource.class); JerseyEnvironment adminJerseyEnvironment = SoaBundle.getFeatures(environment).getNamedRequired(JerseyEnvironment.class, SoaFeatures.ADMIN_NAME); adminJerseyEnvironment.register(GoodbyeAdminResource.class); }
Example #5
Source File: ArmeriaServerFactory.java From armeria with Apache License 2.0 | 6 votes |
@Override public Server build(Environment environment) { Objects.requireNonNull(environment, "environment"); printBanner(environment.getName()); final MetricRegistry metrics = environment.metrics(); final ThreadPool threadPool = createThreadPool(metrics); final Server server = buildServer(environment.lifecycle(), threadPool); final JerseyEnvironment jersey = environment.jersey(); if (!isJerseyEnabled()) { jersey.disable(); } addDefaultHandlers(server, environment, metrics); serverBuilder = buildServerBuilder(server, metrics); return server; }
Example #6
Source File: ArmeriaServerFactory.java From armeria with Apache License 2.0 | 6 votes |
private void addDefaultHandlers(Server server, Environment environment, MetricRegistry metrics) { final JerseyEnvironment jersey = environment.jersey(); final Handler applicationHandler = createAppServlet( server, jersey, environment.getObjectMapper(), environment.getValidator(), environment.getApplicationContext(), environment.getJerseyServletContainer(), metrics); final Handler adminHandler = createAdminServlet(server, environment.getAdminContext(), metrics, environment.healthChecks()); final ContextRoutingHandler routingHandler = new ContextRoutingHandler( ImmutableMap.of(applicationContextPath, applicationHandler, adminContextPath, adminHandler)); final Handler gzipHandler = buildGzipHandler(routingHandler); server.setHandler(addStatsHandler(addRequestLog(server, gzipHandler, environment.getName()))); }
Example #7
Source File: JerseyUtil.java From robe with GNU Lesser General Public License v3.0 | 6 votes |
/** * Registers any Guice-bound providers or root resources. */ public static void registerGuiceBound(Injector injector, final JerseyEnvironment environment) { while (injector != null) { for (Key<?> key : injector.getBindings().keySet()) { Type type = key.getTypeLiteral().getType(); if (type instanceof Class) { Class<?> c = (Class) type; if (isProviderClass(c)) { logger.info("Registering {} as a provider class", c.getName()); environment.register(c); } else if (isRootResourceClass(c)) { // Jersey rejects resources that it doesn't think are acceptable // Including abstract classes and interfaces, even if there is a valid Guice binding. if (Resource.isAcceptable(c)) { logger.info("Registering {} as a root resource class", c.getName()); environment.register(c); } else { logger.warn("Class {} was not registered as a resource. Bind a concrete implementation instead.", c.getName()); } } } } injector = injector.getParent(); } }
Example #8
Source File: AuthenticationBootstrap.java From jobson with Apache License 2.0 | 5 votes |
public AuthenticationBootstrap(JerseyEnvironment environment, UserDAO userDAO) { requireNonNull(environment); requireNonNull(environment); this.environment = environment; this.userDAO = userDAO; }
Example #9
Source File: TestHelpers.java From jobson with Apache License 2.0 | 5 votes |
public 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); }
Example #10
Source File: RxJerseyBundle.java From rx-jersey with MIT License | 5 votes |
@Override public void run(T configuration, Environment environment) throws Exception { JerseyEnvironment jersey = environment.jersey(); JerseyClientConfiguration clientConfiguration = clientConfigurationProvider.apply(configuration); Client client = getClient(environment, clientConfiguration); rxJerseyClientFeature.setClient(client); jersey.register(rxJerseyServerFeature); jersey.register(rxJerseyClientFeature); }
Example #11
Source File: SoaBundle.java From soabase with Apache License 2.0 | 5 votes |
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); }
Example #12
Source File: MainApplication.java From SciGraph with Apache License 2.0 | 5 votes |
void addWriters(JerseyEnvironment environment) throws Exception { for (ClassInfo classInfo: ClassPath.from(getClass().getClassLoader()).getTopLevelClasses("io.scigraph.services.jersey.writers")) { if (!Modifier.isAbstract(classInfo.load().getModifiers())) { environment.register(factory.getInjector().getInstance(classInfo.load())); } } }
Example #13
Source File: AuthenticationBootstrap.java From jobson with Apache License 2.0 | 4 votes |
public JerseyEnvironment getEnvironment() { return environment; }
Example #14
Source File: KeywhizService.java From keywhiz with Apache License 2.0 | 4 votes |
@SuppressWarnings("unchecked") @Override public void run(KeywhizConfig config, Environment environment) throws Exception { if (injector == null) { logger.debug("No existing guice injector; creating new one"); injector = Guice.createInjector(new ServiceModule(config, environment)); } JerseyEnvironment jersey = environment.jersey(); logger.debug("Registering resource filters"); jersey.register(injector.getInstance(ClientCertificateFilter.class)); logger.debug("Registering servlet filters"); environment.servlets().addFilter("security-headers-filter", injector.getInstance(SecurityHeadersFilter.class)) .addMappingForUrlPatterns(null, /* Default is for requests */ false /* Can be after other filters */, "/*" /* Every request */); jersey.register(injector.getInstance(CookieRenewingFilter.class)); logger.debug("Registering providers"); jersey.register(new AuthResolver.Binder(injector.getInstance(ClientAuthFactory.class), injector.getInstance(AutomationClientAuthFactory.class), injector.getInstance(UserAuthFactory.class))); logger.debug("Registering resources"); jersey.register(injector.getInstance(BackfillRowHmacResource.class)); jersey.register(injector.getInstance(ClientResource.class)); jersey.register(injector.getInstance(ClientsResource.class)); jersey.register(injector.getInstance(GroupResource.class)); jersey.register(injector.getInstance(GroupsResource.class)); jersey.register(injector.getInstance(MembershipResource.class)); jersey.register(injector.getInstance(SecretsDeliveryResource.class)); jersey.register(injector.getInstance(SecretResource.class)); jersey.register(injector.getInstance(SecretsResource.class)); jersey.register(injector.getInstance(SecretDeliveryResource.class)); jersey.register(injector.getInstance(SessionLoginResource.class)); jersey.register(injector.getInstance(SessionLogoutResource.class)); jersey.register(injector.getInstance(SessionMeResource.class)); jersey.register(injector.getInstance(AutomationClientResource.class)); jersey.register(injector.getInstance(AutomationGroupResource.class)); jersey.register(injector.getInstance(AutomationSecretResource.class)); jersey.register(injector.getInstance(AutomationEnrollClientGroupResource.class)); jersey.register(injector.getInstance(AutomationSecretAccessResource.class)); jersey.register(injector.getInstance(StatusResource.class)); jersey.register(injector.getInstance(BackupResource.class)); ManualStatusHealthCheck mshc = new ManualStatusHealthCheck(); environment.healthChecks().register("manualStatus", mshc); environment.admin().addServlet("manualStatus", new ManualStatusServlet(mshc)).addMapping("/status/*"); validateDatabase(config); logger.debug("Keywhiz configuration complete"); }