org.jvnet.hk2.guice.bridge.api.GuiceIntoHK2Bridge Java Examples

The following examples show how to use org.jvnet.hk2.guice.bridge.api.GuiceIntoHK2Bridge. 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: JerseyApplication.java    From onedev with MIT License 6 votes vote down vote up
@Inject
public JerseyApplication(ServiceLocator serviceLocator) {
	GuiceBridge.getGuiceBridge().initializeGuiceBridge(serviceLocator);
	GuiceIntoHK2Bridge guiceBridge = serviceLocator.getService(GuiceIntoHK2Bridge.class);
    guiceBridge.bridgeGuiceInjector(AppLoader.injector);
    
    String disableMoxy = PropertiesHelper.getPropertyNameForRuntime(
    		CommonProperties.MOXY_JSON_FEATURE_DISABLE,
               getConfiguration().getRuntimeType());
       property(disableMoxy, true);
       property(ServerProperties.BV_SEND_ERROR_IN_RESPONSE, true);

       // add the default Jackson exception mappers
       register(JacksonFeature.class);
       
       packages(JerseyApplication.class.getPackage().getName());
       
    for (JerseyConfigurator configurator: AppLoader.getExtensions(JerseyConfigurator.class)) {
    	configurator.configure(this);
    }
}
 
Example #2
Source File: GuiceFeature.java    From jrestless-examples with Apache License 2.0 6 votes vote down vote up
@Override
public boolean configure(FeatureContext context) {
	InjectionManager injectionManager = InjectionManagerProvider.getInjectionManager(context);
	ServiceLocator locator;
	if (injectionManager instanceof ImmediateHk2InjectionManager) {
		locator = ((ImmediateHk2InjectionManager) injectionManager).getServiceLocator();
	} else if (injectionManager instanceof DelayedHk2InjectionManager) {
		locator = ((DelayedHk2InjectionManager) injectionManager).getServiceLocator();
	} else {
		throw new IllegalStateException("expected an hk2 injection manager");
	}
	GuiceBridge.getGuiceBridge().initializeGuiceBridge(locator);
	// register all your modules, here
	Injector injector = Guice.createInjector(new GreetingModule());
	GuiceIntoHK2Bridge guiceBridge = locator.getService(GuiceIntoHK2Bridge.class);
	guiceBridge.bridgeGuiceInjector(injector);
	return true;
}
 
Example #3
Source File: GuiceComponentProviderTest.java    From seed with Mozilla Public License 2.0 6 votes vote down vote up
@Test
public void testPrepareHK2Bridge(@Mocked final GuiceBridge guiceBridge) {
    givenServiceLocator();
    new Expectations() {{
        serviceLocator.getService(GuiceIntoHK2Bridge.class);
        result = guiceIntoHK2Bridge;
    }};

    underTest.initialize(serviceLocator);

    new Verifications() {{
        guiceBridge.initializeGuiceBridge(serviceLocator);
        serviceLocator.getService(GuiceIntoHK2Bridge.class);
        guiceIntoHK2Bridge.bridgeGuiceInjector(injector);
    }};
}
 
Example #4
Source File: MCRGuiceBridgeFeature.java    From mycore with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean configure(FeatureContext context) {
    Objects.requireNonNull(scopedLocator, "HK2 ServiceLocator was not injected");
    Injector injector = MCRInjectorConfig.injector();
    GuiceBridge.getGuiceBridge().initializeGuiceBridge(scopedLocator);
    GuiceIntoHK2Bridge guiceBridge = scopedLocator.getService(GuiceIntoHK2Bridge.class);
    guiceBridge.bridgeGuiceInjector(injector);
    LogManager.getLogger().info("Initialize hk2 - guice bridge...done");
    return true;
}
 
Example #5
Source File: GuiceBridgeActivator.java    From dropwizard-guicey with MIT License 5 votes vote down vote up
/**
 * Activate HK2 guice bridge.
 */
public void activate() {
    final ServiceLocator locator = injectionManager.getInstance(ServiceLocator.class);
    GuiceBridge.getGuiceBridge().initializeGuiceBridge(locator);
    final GuiceIntoHK2Bridge guiceBridge = injectionManager.getInstance(GuiceIntoHK2Bridge.class);
    guiceBridge.bridgeGuiceInjector(injector);
}
 
Example #6
Source File: GuiceComponentProvider.java    From seed with Mozilla Public License 2.0 5 votes vote down vote up
void initialize(ServiceLocator serviceLocator) {
    this.serviceLocator = serviceLocator;
    this.injector = ServletContextUtils.getInjector(getServletContext());
    if (injector == null) {
        throw SeedException.createNew(Jersey2ErrorCode.MISSING_INJECTOR);
    }
    GuiceBridge.getGuiceBridge().initializeGuiceBridge(this.serviceLocator);
    this.serviceLocator.getService(GuiceIntoHK2Bridge.class).bridgeGuiceInjector(this.injector);
}
 
Example #7
Source File: GuiceComponentProviderTest.java    From seed with Mozilla Public License 2.0 5 votes vote down vote up
private void givenServiceLocator() {
    new Expectations() {{
        serviceLocator.getService(ServletContext.class);
        result = servletContext;
        servletContext.getAttribute(Injector.class.getName());
        result = injector;
        serviceLocator.getService(GuiceIntoHK2Bridge.class);
        result = guiceIntoHK2Bridge;
    }};
}
 
Example #8
Source File: GuiceFeature.java    From usergrid with Apache License 2.0 5 votes vote down vote up
@Override
public boolean configure(FeatureContext context) {

    ServiceLocator serviceLocator = ServiceLocatorProvider.getServiceLocator( context );
    GuiceBridge.getGuiceBridge().initializeGuiceBridge( serviceLocator );

    GuiceIntoHK2Bridge guiceBridge = serviceLocator.getService( GuiceIntoHK2Bridge.class );
    guiceBridge.bridgeGuiceInjector( StartupListener.INJECTOR );

    return true;
}