@Test public void testIt() throws Exception { Module module = new AbstractModule() { @Override protected void configure() { bind(MockGuiceInjected.class).asEagerSingleton(); } }; final MockApplication mockApplication = new MockApplication(module); Callable callable = new Callable() { @Override public Object call() throws Exception { String[] args = {"server"}; mockApplication.run(args); return null; } }; Future future = Executors.newSingleThreadExecutor().submit(callable); try { Assert.assertTrue(mockApplication.getStartedLatch().await(5, TimeUnit.SECONDS)); URI uri = new URI("http: String str = CharStreams.toString(new InputStreamReader(uri.toURL().openStream())); Assert.assertEquals("guice - hk2", str); } finally { future.cancel(true); ShutdownThread.getInstance().run(); } }
@Override public void run(final T configuration, final Environment environment) throws Exception { Feature feature = new GuiceBundleFeature() { private final AtomicBoolean firstTime = new AtomicBoolean(true); @Override public boolean configure(FeatureContext context) { internalApply(context); return true; } private void internalApply(FeatureContext context) { ServiceLocator serviceLocator = ServiceLocatorProvider.getServiceLocator(context); GuiceBridge.getGuiceBridge().initializeGuiceBridge(serviceLocator); GuiceIntoHK2Bridge guiceBridge = serviceLocator.getService(GuiceIntoHK2Bridge.class); AbstractModule additionalModule = new AbstractModule() { @Override protected void configure() { try { Class.forName("io.soabase.core.SoaFeatures"); log.info("Installing SoaIntegrationModule"); Module soaIntegrationModule = (Module)Class.forName("io.soabase.guice.SoaIntegrationModule").getConstructor(Environment.class).newInstance(environment); install(soaIntegrationModule); } catch ( ClassNotFoundException ignore ) { log.info("SoaFeatures not available"); } catch ( Exception e ) { log.error("Could not instantiate SoaIntegrationModule", e); } } }; Injector localInjector = getInjector(configuration, environment, additionalModule); guiceBridge.bridgeGuiceInjector(localInjector); if ( firstTime.compareAndSet(true, false) ) { registerBoundJerseyComponents(localInjector, context, environment); } } }; environment.jersey().register(feature); ApplicationEventListener listener = new ApplicationEventListener() { @Override public void onEvent(ApplicationEvent event) { if ( event.getType() == ApplicationEvent.Type.INITIALIZATION_APP_FINISHED ) { loggingConfig.logComponents(); } } @Override public RequestEventListener onRequest(RequestEvent requestEvent) { return null; } }; environment.jersey().register(listener); }
GuiceBundle implements ConfiguredBundle<T> { @Override public void run(final T configuration, final Environment environment) throws Exception { Feature feature = new GuiceBundleFeature() { private final AtomicBoolean firstTime = new AtomicBoolean(true); @Override public boolean configure(FeatureContext context) { internalApply(context); return true; } private void internalApply(FeatureContext context) { ServiceLocator serviceLocator = ServiceLocatorProvider.getServiceLocator(context); GuiceBridge.getGuiceBridge().initializeGuiceBridge(serviceLocator); GuiceIntoHK2Bridge guiceBridge = serviceLocator.getService(GuiceIntoHK2Bridge.class); AbstractModule additionalModule = new AbstractModule() { @Override protected void configure() { try { Class.forName("io.soabase.core.SoaFeatures"); log.info("Installing SoaIntegrationModule"); Module soaIntegrationModule = (Module)Class.forName("io.soabase.guice.SoaIntegrationModule").getConstructor(Environment.class).newInstance(environment); install(soaIntegrationModule); } catch ( ClassNotFoundException ignore ) { log.info("SoaFeatures not available"); } catch ( Exception e ) { log.error("Could not instantiate SoaIntegrationModule", e); } } }; Injector localInjector = getInjector(configuration, environment, additionalModule); guiceBridge.bridgeGuiceInjector(localInjector); if ( firstTime.compareAndSet(true, false) ) { registerBoundJerseyComponents(localInjector, context, environment); } } }; environment.jersey().register(feature); ApplicationEventListener listener = new ApplicationEventListener() { @Override public void onEvent(ApplicationEvent event) { if ( event.getType() == ApplicationEvent.Type.INITIALIZATION_APP_FINISHED ) { loggingConfig.logComponents(); } } @Override public RequestEventListener onRequest(RequestEvent requestEvent) { return null; } }; environment.jersey().register(listener); } }
GuiceBundle implements ConfiguredBundle<T> { @Override public void run(final T configuration, final Environment environment) throws Exception { Feature feature = new GuiceBundleFeature() { private final AtomicBoolean firstTime = new AtomicBoolean(true); @Override public boolean configure(FeatureContext context) { internalApply(context); return true; } private void internalApply(FeatureContext context) { ServiceLocator serviceLocator = ServiceLocatorProvider.getServiceLocator(context); GuiceBridge.getGuiceBridge().initializeGuiceBridge(serviceLocator); GuiceIntoHK2Bridge guiceBridge = serviceLocator.getService(GuiceIntoHK2Bridge.class); AbstractModule additionalModule = new AbstractModule() { @Override protected void configure() { try { Class.forName("io.soabase.core.SoaFeatures"); log.info("Installing SoaIntegrationModule"); Module soaIntegrationModule = (Module)Class.forName("io.soabase.guice.SoaIntegrationModule").getConstructor(Environment.class).newInstance(environment); install(soaIntegrationModule); } catch ( ClassNotFoundException ignore ) { log.info("SoaFeatures not available"); } catch ( Exception e ) { log.error("Could not instantiate SoaIntegrationModule", e); } } }; Injector localInjector = getInjector(configuration, environment, additionalModule); guiceBridge.bridgeGuiceInjector(localInjector); if ( firstTime.compareAndSet(true, false) ) { registerBoundJerseyComponents(localInjector, context, environment); } } }; environment.jersey().register(feature); ApplicationEventListener listener = new ApplicationEventListener() { @Override public void onEvent(ApplicationEvent event) { if ( event.getType() == ApplicationEvent.Type.INITIALIZATION_APP_FINISHED ) { loggingConfig.logComponents(); } } @Override public RequestEventListener onRequest(RequestEvent requestEvent) { return null; } }; environment.jersey().register(listener); } GuiceBundle(InjectorProvider<T> injectorProvider); }
GuiceBundle implements ConfiguredBundle<T> { @Override public void run(final T configuration, final Environment environment) throws Exception { Feature feature = new GuiceBundleFeature() { private final AtomicBoolean firstTime = new AtomicBoolean(true); @Override public boolean configure(FeatureContext context) { internalApply(context); return true; } private void internalApply(FeatureContext context) { ServiceLocator serviceLocator = ServiceLocatorProvider.getServiceLocator(context); GuiceBridge.getGuiceBridge().initializeGuiceBridge(serviceLocator); GuiceIntoHK2Bridge guiceBridge = serviceLocator.getService(GuiceIntoHK2Bridge.class); AbstractModule additionalModule = new AbstractModule() { @Override protected void configure() { try { Class.forName("io.soabase.core.SoaFeatures"); log.info("Installing SoaIntegrationModule"); Module soaIntegrationModule = (Module)Class.forName("io.soabase.guice.SoaIntegrationModule").getConstructor(Environment.class).newInstance(environment); install(soaIntegrationModule); } catch ( ClassNotFoundException ignore ) { log.info("SoaFeatures not available"); } catch ( Exception e ) { log.error("Could not instantiate SoaIntegrationModule", e); } } }; Injector localInjector = getInjector(configuration, environment, additionalModule); guiceBridge.bridgeGuiceInjector(localInjector); if ( firstTime.compareAndSet(true, false) ) { registerBoundJerseyComponents(localInjector, context, environment); } } }; environment.jersey().register(feature); ApplicationEventListener listener = new ApplicationEventListener() { @Override public void onEvent(ApplicationEvent event) { if ( event.getType() == ApplicationEvent.Type.INITIALIZATION_APP_FINISHED ) { loggingConfig.logComponents(); } } @Override public RequestEventListener onRequest(RequestEvent requestEvent) { return null; } }; environment.jersey().register(listener); } GuiceBundle(InjectorProvider<T> injectorProvider); @Override void initialize(Bootstrap<?> bootstrap); @Override void run(final T configuration, final Environment environment); }
GuiceBundle implements ConfiguredBundle<T> { @Override public void run(final T configuration, final Environment environment) throws Exception { Feature feature = new GuiceBundleFeature() { private final AtomicBoolean firstTime = new AtomicBoolean(true); @Override public boolean configure(FeatureContext context) { internalApply(context); return true; } private void internalApply(FeatureContext context) { ServiceLocator serviceLocator = ServiceLocatorProvider.getServiceLocator(context); GuiceBridge.getGuiceBridge().initializeGuiceBridge(serviceLocator); GuiceIntoHK2Bridge guiceBridge = serviceLocator.getService(GuiceIntoHK2Bridge.class); AbstractModule additionalModule = new AbstractModule() { @Override protected void configure() { try { Class.forName("io.soabase.core.SoaFeatures"); log.info("Installing SoaIntegrationModule"); Module soaIntegrationModule = (Module)Class.forName("io.soabase.guice.SoaIntegrationModule").getConstructor(Environment.class).newInstance(environment); install(soaIntegrationModule); } catch ( ClassNotFoundException ignore ) { log.info("SoaFeatures not available"); } catch ( Exception e ) { log.error("Could not instantiate SoaIntegrationModule", e); } } }; Injector localInjector = getInjector(configuration, environment, additionalModule); guiceBridge.bridgeGuiceInjector(localInjector); if ( firstTime.compareAndSet(true, false) ) { registerBoundJerseyComponents(localInjector, context, environment); } } }; environment.jersey().register(feature); ApplicationEventListener listener = new ApplicationEventListener() { @Override public void onEvent(ApplicationEvent event) { if ( event.getType() == ApplicationEvent.Type.INITIALIZATION_APP_FINISHED ) { loggingConfig.logComponents(); } } @Override public RequestEventListener onRequest(RequestEvent requestEvent) { return null; } }; environment.jersey().register(listener); } GuiceBundle(InjectorProvider<T> injectorProvider); @Override void initialize(Bootstrap<?> bootstrap); @Override void run(final T configuration, final Environment environment);  }