Java Code Examples for org.glassfish.hk2.api.ServiceLocator#getService()

The following examples show how to use org.glassfish.hk2.api.ServiceLocator#getService() . 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: 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;
}
 
Example 4
Source File: Jersey2BackstopperConfigHelperTest.java    From backstopper with Apache License 2.0 5 votes vote down vote up
@Test
public void exceptionMapperFactoryOverrideBinder_configures_ExceptionMappers_override() {
    // given
    AbstractBinder defaultJersey2ExceptionMapperBinder = new ExceptionMapperFactory.Binder();
    ExceptionMapperFactoryOverrideBinder overrideBinder =  new ExceptionMapperFactoryOverrideBinder();
    ServiceLocator locator = ServiceLocatorUtilities.bind(defaultJersey2ExceptionMapperBinder, overrideBinder);

    // when
    ExceptionMappers result = locator.getService(ExceptionMappers.class);

    // then
    assertThat(result).isInstanceOf(BackstopperOnlyExceptionMapperFactory.class);
}
 
Example 5
Source File: KatharsisDynamicFeature.java    From katharsis-framework with Apache License 2.0 5 votes vote down vote up
@Inject
public KatharsisDynamicFeature(ObjectMapper objectMapper, final ServiceLocator ServiceLocator) {
    super(objectMapper, new QueryParamsBuilder(new DefaultQueryParamsParser()), new JsonServiceLocator() {
        @Override
        public <T> T getInstance(Class<T> clazz) {
            return ServiceLocator.getService(clazz);
        }
    });
}
 
Example 6
Source File: KatharsisDynamicFeature.java    From katharsis-framework with Apache License 2.0 5 votes vote down vote up
@Inject
public KatharsisDynamicFeature(ObjectMapper objectMapper, final ServiceLocator ServiceLocator) {
    super(objectMapper, new QueryParamsBuilder(new DefaultQueryParamsParser()), new JsonServiceLocator() {
        @Override
        public <T> T getInstance(Class<T> clazz) {
            return ServiceLocator.getService(clazz);
        }
    });
}
 
Example 7
Source File: ZeppelinServer.java    From zeppelin with Apache License 2.0 5 votes vote down vote up
private static void setupNotebookServer(
    WebAppContext webapp, ZeppelinConfiguration conf, ServiceLocator serviceLocator) {
  String maxTextMessageSize = conf.getWebsocketMaxTextMessageSize();
  final ServletHolder servletHolder =
      new ServletHolder(serviceLocator.getService(NotebookServer.class));
  servletHolder.setInitParameter("maxTextMessageSize", maxTextMessageSize);

  webapp.addServlet(servletHolder, "/ws/*");
}
 
Example 8
Source File: ZeppelinServer.java    From zeppelin with Apache License 2.0 5 votes vote down vote up
private static void setupClusterManagerServer(ServiceLocator serviceLocator) {
  if (conf.isClusterMode()) {
    LOG.info("Cluster mode is enabled, starting ClusterManagerServer");
    ClusterManagerServer clusterManagerServer = ClusterManagerServer.getInstance(conf);

    NotebookServer notebookServer = serviceLocator.getService(NotebookServer.class);
    clusterManagerServer.addClusterEventListeners(ClusterManagerServer.CLUSTER_NOTE_EVENT_TOPIC, notebookServer);

    AuthorizationService authorizationService = serviceLocator.getService(AuthorizationService.class);
    clusterManagerServer.addClusterEventListeners(ClusterManagerServer.CLUSTER_AUTH_EVENT_TOPIC, authorizationService);

    InterpreterSettingManager interpreterSettingManager = serviceLocator.getService(InterpreterSettingManager.class);
    clusterManagerServer.addClusterEventListeners(ClusterManagerServer.CLUSTER_INTP_SETTING_EVENT_TOPIC, interpreterSettingManager);

    // Since the ClusterInterpreterLauncher is lazy, dynamically generated, So in cluster mode,
    // when the zeppelin service starts, Create a ClusterInterpreterLauncher object,
    // This allows the ClusterInterpreterLauncher to listen for cluster events.
    try {
      InterpreterSettingManager intpSettingManager = sharedServiceLocator.getService(InterpreterSettingManager.class);
      RecoveryStorage recoveryStorage = ReflectionUtils.createClazzInstance(
              conf.getRecoveryStorageClass(),
              new Class[] {ZeppelinConfiguration.class, InterpreterSettingManager.class},
              new Object[] {conf, intpSettingManager});
      recoveryStorage.init();
      PluginManager.get().loadInterpreterLauncher(InterpreterSetting.CLUSTER_INTERPRETER_LAUNCHER_NAME, recoveryStorage);
    } catch (IOException e) {
      LOG.error(e.getMessage(), e);
    }

    clusterManagerServer.start();
  } else {
    LOG.info("Cluster mode is disabled");
  }
}
 
Example 9
Source File: SubmarineServer.java    From submarine with Apache License 2.0 5 votes vote down vote up
private static void setupNotebookServer(WebAppContext webapp,
    SubmarineConfiguration conf, ServiceLocator serviceLocator) {
  String maxTextMessageSize = conf.getWebsocketMaxTextMessageSize();
  final ServletHolder servletHolder =
      new ServletHolder(serviceLocator.getService(NotebookServer.class));
  servletHolder.setInitParameter("maxTextMessageSize", maxTextMessageSize);

  final ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
  webapp.addServlet(servletHolder, "/ws/*");
}
 
Example 10
Source File: ServiceLocatorGenerator.java    From ameba with MIT License 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public ServiceLocator create(String name, ServiceLocator parent) {
    ServiceLocator retVal = super.create(name, parent);
    DynamicConfigurationService dcs = retVal.getService(DynamicConfigurationService.class);
    Populator populator = dcs.getPopulator();

    try {
        populator.populate();
    } catch (IOException e) {
        throw new MultiException(e);
    }
    return retVal;
}
 
Example 11
Source File: JerseyGuicierModule.java    From dropwizard-guicier with Apache License 2.0 4 votes vote down vote up
@Provides
public Configuration providesConfiguration(ServiceLocator serviceLocator) {
  return serviceLocator.getService(Configuration.class);
}
 
Example 12
Source File: SpringContextJerseyTest.java    From demo-restWS-spring-jersey-tomcat-mybatis with MIT License 4 votes vote down vote up
protected ApplicationContext getSpringApplicationContext() {
    ServiceLocator serviceLocator = getApplication().getServiceLocator();
    return serviceLocator.getService(ApplicationContext.class);
}
 
Example 13
Source File: SpringContextJerseyTest.java    From demo-restWS-spring-jersey-jpa2-hibernate with MIT License 4 votes vote down vote up
protected ApplicationContext getSpringApplicationContext() {
    ServiceLocator serviceLocator = getApplication().getServiceLocator();
    return serviceLocator.getService(ApplicationContext.class);
}
 
Example 14
Source File: JerseyGuicierModule.java    From dropwizard-guicier with Apache License 2.0 4 votes vote down vote up
@Provides
public ServletConfig providesServletConfig(ServiceLocator serviceLocator) {
  return serviceLocator.getService(ServletConfig.class);
}
 
Example 15
Source File: JerseyGuicierModule.java    From dropwizard-guicier with Apache License 2.0 4 votes vote down vote up
@Provides
public ResourceContext providesResourceContext(ServiceLocator serviceLocator) {
  return serviceLocator.getService(ResourceContext.class);
}
 
Example 16
Source File: SpringContextJerseyTest.java    From demo-restWS-spring-jersey-tomcat-mybatis with MIT License 4 votes vote down vote up
protected ApplicationContext getSpringApplicationContext() {
    ServiceLocator serviceLocator = getApplication().getServiceLocator();
    return serviceLocator.getService(ApplicationContext.class);
}
 
Example 17
Source File: JerseyGuicierModule.java    From dropwizard-guicier with Apache License 2.0 4 votes vote down vote up
@Provides
@RequestScoped
public ContainerRequestContext providesContainerRequestContext(ServiceLocator serviceLocator) {
  return serviceLocator.getService(ContainerRequestContext.class);
}
 
Example 18
Source File: TestUtils.java    From zeppelin with Apache License 2.0 4 votes vote down vote up
static <T> T getInstance(ServiceLocator serviceLocator, Class<T> clazz) {
  return serviceLocator.getService(clazz);
}
 
Example 19
Source File: TestUtils.java    From submarine with Apache License 2.0 4 votes vote down vote up
static <T> T getInstance(ServiceLocator serviceLocator, Class<T> clazz) {
  return serviceLocator.getService(clazz);
}
 
Example 20
Source File: GuiceComponentProvider.java    From seed with Mozilla Public License 2.0 2 votes vote down vote up
/**
 * Get service locator {@link DynamicConfiguration dynamic configuration}.
 *
 * @param locator HK2 service locator.
 * @return dynamic configuration for a given service locator.
 */
private static DynamicConfiguration getConfiguration(final ServiceLocator locator) {
    final DynamicConfigurationService dcs = locator.getService(DynamicConfigurationService.class);
    return dcs.createDynamicConfiguration();
}