use of org.glassfish.hk2.api.ServiceLocator in project jersey by jersey.
the class Hk2Helper method bind.
/**
* Bind descriptors to Hk2-like {@link Binder}.
*
* @param locator HK2 locator.
* @param descriptors collection of descriptors.
*/
static void bind(ServiceLocator locator, Iterable<Binding> descriptors) {
DynamicConfiguration dc = getDynamicConfiguration(locator);
for (Binding binding : descriptors) {
bindBinding(locator, dc, binding);
}
dc.commit();
}
use of org.glassfish.hk2.api.ServiceLocator in project jersey by jersey.
the class InjectionManagerTest method testServiceLocatorParent.
@Test
public void testServiceLocatorParent() {
AbstractBinder binder = new AbstractBinder() {
@Override
protected void configure() {
bindAsContract(EnglishGreeting.class);
}
};
ServiceLocator parentLocator = ServiceLocatorUtilities.bind(binder);
InjectionManager injectionManager = new HK2InjectionManager();
injectionManager.initialize(parentLocator);
assertNotNull(injectionManager.getInstance(EnglishGreeting.class));
}
use of org.glassfish.hk2.api.ServiceLocator in project jersey by jersey.
the class BeanParamMemoryLeakTest method testBeanParam.
@Test
public void testBeanParam() throws Exception {
initiateWebApplication(BeanParamInjectionResource.class);
final InjectionManager injectionManager = app().getInjectionManager();
if (!(injectionManager instanceof HK2InjectionManager)) {
throw new RuntimeException("Bean Manager is not an injection manager");
}
HK2InjectionManager hk2BeanManager = (HK2InjectionManager) injectionManager;
ServiceLocator serviceLocator = hk2BeanManager.getServiceLocator();
// we do not expect any descriptor registered yet
assertEquals(0, serviceLocator.getDescriptors(new ParameterBeanFilter()).size());
// now make one registered via this call
assertEquals("one", resource("/jaxrs?q=one").getEntity());
// make sure it got registered
assertEquals(1, serviceLocator.getDescriptors(new ParameterBeanFilter()).size());
// make another call
assertEquals("two", resource("/jaxrs?q=two").getEntity());
assertEquals(1, serviceLocator.getDescriptors(new ParameterBeanFilter()).size());
// and some more
for (int i = 0; i < 20; i++) {
assertEquals(Integer.toString(i), resource("/jaxrs?q=" + i).getEntity());
assertEquals(1, serviceLocator.getDescriptors(new ParameterBeanFilter()).size());
}
}
use of org.glassfish.hk2.api.ServiceLocator in project graylog2-server by Graylog2.
the class Graylog2ServiceLocatorGenerator method create.
@Override
public ServiceLocator create(String name, ServiceLocator parent) {
final ServiceLocator serviceLocator = super.create(name, parent);
final Injector injector = GuiceInjectorHolder.getInjector().createChildInjector(new HK2IntoGuiceBridge(serviceLocator));
GuiceBridge.getGuiceBridge().initializeGuiceBridge(serviceLocator);
final GuiceIntoHK2Bridge guiceBridge = serviceLocator.getService(GuiceIntoHK2Bridge.class);
guiceBridge.bridgeGuiceInjector(injector);
return serviceLocator;
}
use of org.glassfish.hk2.api.ServiceLocator in project API by ca-cwds.
the class JerseyGuiceRule method before.
@Override
protected void before() throws Throwable {
Injector baseInjector = Guice.createInjector(Stage.PRODUCTION, new ServletModule());
JerseyGuiceUtils.install(new ServiceLocatorGenerator() {
@Override
public ServiceLocator create(String name, ServiceLocator parent) {
if (!name.startsWith("__HK2_Generated_")) {
return null;
}
return baseInjector.createChildInjector(new JerseyGuiceModule(name)).getInstance(ServiceLocator.class);
}
});
}
Aggregations