Java Code Examples for com.squarespace.jersey2.guice.JerseyGuiceUtils

The following examples show how to use com.squarespace.jersey2.guice.JerseyGuiceUtils. These examples are extracted from open source projects. 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 Project: Singularity   Source File: SingularityCuratorTestBase.java    License: Apache License 2.0 5 votes vote down vote up
@BeforeAll
public void setup() throws Exception {
  JerseyGuiceUtils.reset();
  singularityTestModule = new SingularityTestModule(useDBTests, customConfigSetup);

  singularityTestModule.getInjector().injectMembers(this);
  singularityTestModule.start();
  leaderCacheCoordinator.activateLeaderCache();
  configuration.setThreadpoolShutdownDelayInSeconds(0);
  if (useDBTests) {
    Handle handle = dbiProvider.get().open();
    handle.getConnection().setAutoCommit(true);

    Database database = DatabaseFactory
      .getInstance()
      .findCorrectDatabaseImplementation(new JdbcConnection(handle.getConnection()));

    Liquibase liquibase = new Liquibase(
      "singularity_test.sql",
      new FileSystemResourceAccessor(),
      database
    );
    liquibase.update((String) null);

    try {
      database.close();
      handle.close();
    } catch (Throwable t) {}
  }
}
 
Example 2
Source Project: dropwizard-guicier   Source File: GuiceBundle.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void run(final T configuration, final Environment environment) throws Exception {
  for (DropwizardAwareModule<T> dropwizardAwareModule : dropwizardAwareModules) {
    dropwizardAwareModule.setBootstrap(bootstrap);
    dropwizardAwareModule.setConfiguration(configuration);
    dropwizardAwareModule.setEnvironment(environment);
  }

  final DropwizardModule dropwizardModule = new DropwizardModule(environment);
  // We assume that the next service locator will be the main application one
  final String serviceLocatorName = getNextServiceLocatorName();
  ImmutableSet.Builder<Module> modulesBuilder =
      ImmutableSet.<Module>builder()
          .addAll(guiceModules)
          .addAll(dropwizardAwareModules)
          .add(new ServletModule())
          .add(dropwizardModule)
          .add(new JerseyGuiceModule(serviceLocatorName))
          .add(new JerseyGuicierModule())
          .add(binder -> {
            binder.bind(Environment.class).toInstance(environment);
            binder.bind(configClass).toInstance(configuration);
          });
  if (enableGuiceEnforcer) {
    modulesBuilder.add(new GuiceEnforcerModule());
  }
  this.injector = injectorFactory.create(guiceStage, modulesBuilder.build());

  JerseyGuiceUtils.install((name, parent) -> {
    if (!name.startsWith("__HK2_")) {
      return null;
    } else if (serviceLocatorName.equals(name)) {
      return injector.getInstance(ServiceLocator.class);
    } else {
      LOG.debug("Returning a new ServiceLocator for name '{}'", name);
      return JerseyGuiceUtils.newServiceLocator(name, parent);
    }
  });

  dropwizardModule.register(injector);

  environment.servlets().addFilter("Guice Filter", GuiceFilter.class).addMappingForUrlPatterns(null, false, "/*");
  environment.servlets().addServletListeners(new GuiceServletContextListener() {

    @Override
    protected Injector getInjector() {
      return injector;
    }
  });
}
 
Example 3
Source Project: dropwizard-guicier   Source File: HK2LinkerTest.java    License: Apache License 2.0 4 votes vote down vote up
@AfterClass
public static void tearDown() {
    JerseyGuiceUtils.reset();
}
 
Example 4
Source Project: dropwizard-guicier   Source File: GuiceBundleTest.java    License: Apache License 2.0 4 votes vote down vote up
@After
public void tearDown() {
    JerseyGuiceUtils.reset();
}
 
Example 5
@AfterClass
public static void tearDown() {
    JerseyGuiceUtils.reset();
}
 
Example 6
Source Project: Baragon   Source File: BaragonServiceTestBase.java    License: Apache License 2.0 4 votes vote down vote up
@BeforeAll
public void setup() throws Exception {
  JerseyGuiceUtils.reset();
  new BaragonServiceTestModule().getInjector().injectMembers(this);
}