use of org.glassfish.hk2.api.ActiveDescriptor in project jersey by jersey.
the class Hk2Helper method bindBinding.
/**
* Binds the single descriptor using an external {@link DynamicConfiguration}.
*
* @param locator HK2 injection manager.
* @param dc HK2 Dynamic configuration to bind the object.
* @param binding Jersey descriptor as a holder of information about an injection point.
*/
private static void bindBinding(ServiceLocator locator, DynamicConfiguration dc, Binding<?, ?> binding) {
if (ClassBinding.class.isAssignableFrom(binding.getClass())) {
ActiveDescriptor<?> activeDescriptor = translateToActiveDescriptor((ClassBinding<?>) binding);
bindBinding(locator, dc, activeDescriptor, binding.getAliases());
} else if (InstanceBinding.class.isAssignableFrom(binding.getClass())) {
ActiveDescriptor<?> activeDescriptor = translateToActiveDescriptor((InstanceBinding<?>) binding);
bindBinding(locator, dc, activeDescriptor, binding.getAliases());
} else if (InjectionResolverBinding.class.isAssignableFrom(binding.getClass())) {
InjectionResolverBinding resolverDescriptor = (InjectionResolverBinding) binding;
bindBinding(locator, dc, wrapInjectionResolver(resolverDescriptor), binding.getAliases());
bindBinding(locator, dc, translateToActiveDescriptor(resolverDescriptor), binding.getAliases());
} else if (SupplierClassBinding.class.isAssignableFrom(binding.getClass())) {
bindSupplierClassBinding(locator, (SupplierClassBinding<?>) binding);
} else if (SupplierInstanceBinding.class.isAssignableFrom(binding.getClass())) {
bindSupplierInstanceBinding(locator, (SupplierInstanceBinding<?>) binding);
} else {
throw new RuntimeException(LocalizationMessages.UNKNOWN_DESCRIPTOR_TYPE(binding.getClass().getSimpleName()));
}
}
use of org.glassfish.hk2.api.ActiveDescriptor in project jersey by jersey.
the class ActiveBindingBindingTest method testReq.
@Test
@Ignore("At the time of ignoring this test, ResourceConfig does not support HK2 Binder registering.")
public void testReq() throws Exception {
// bootstrap the test application
ResourceConfig myConfig = new ResourceConfig();
myConfig.register(ReqResource.class);
myConfig.register(SingletonResource.class);
final MyRequestDataDescriptor activeDescriptor = new MyRequestDataDescriptor();
myConfig.register(new AbstractBinder() {
@Override
protected void configure() {
addActiveDescriptor(activeDescriptor);
}
});
initiateWebApplication(myConfig);
activeDescriptor.injectionManager = app().getInjectionManager();
// end bootstrap
String response;
response = getResponseEntity("/req");
assertThat(response, containsString(REQUEST_TAG));
assertThat(response, not(containsString(PROXY_TAG)));
response = getResponseEntity("/req/param");
assertThat(response, containsString(REQUEST_TAG));
assertThat(response, not(containsString(PROXY_TAG)));
response = getResponseEntity("/singleton");
assertThat(response, containsString(SINGLETON_TAG));
assertThat(response, containsString(PROXY_TAG));
response = getResponseEntity("/req");
assertThat(response, containsString(REQUEST_TAG));
assertThat(response, not(containsString(PROXY_TAG)));
response = getResponseEntity("/singleton");
assertThat(response, containsString(SINGLETON_TAG));
assertThat(response, containsString(PROXY_TAG));
response = getResponseEntity("/singleton/param");
assertThat(response, containsString(SINGLETON_TAG));
assertThat(response, not(containsString(PROXY_TAG)));
response = getResponseEntity("/singleton/param");
assertThat(response, containsString(SINGLETON_TAG));
assertThat(response, not(containsString(PROXY_TAG)));
}
use of org.glassfish.hk2.api.ActiveDescriptor in project jersey by jersey.
the class ContextInjectionResolverImpl method resolve.
@Override
public Object resolve(Injectee injectee, ServiceHandle<?> root) {
Type requiredType = injectee.getRequiredType();
boolean isHk2Factory = ReflectionHelper.isSubClassOf(requiredType, Factory.class);
Injectee newInjectee;
if (isHk2Factory) {
newInjectee = getFactoryInjectee(injectee, ReflectionHelper.getTypeArgument(requiredType, 0));
} else {
newInjectee = foreignRequestScopedInjecteeCache.apply(injectee);
}
ActiveDescriptor<?> ad = descriptorCache.apply(newInjectee);
if (ad != null) {
final ServiceHandle handle = serviceLocator.getServiceHandle(ad, newInjectee);
if (isHk2Factory) {
return asFactory(handle);
} else {
return handle.getService();
}
}
return null;
}
use of org.glassfish.hk2.api.ActiveDescriptor in project jersey by jersey.
the class ContextInjectionResolverImpl method resolve.
/**
* Jersey Injection Resolver method that just populate HK2 injectee object and delegates the processing to HK2 Injection
* Resolver.
*
* @param injectee The injection point this value is being injected into
* @return result of the injection processing.
*/
@Override
public Object resolve(org.glassfish.jersey.internal.inject.Injectee injectee) {
InjecteeImpl hk2injectee = new InjecteeImpl() {
@Override
public Class<?> getInjecteeClass() {
return injectee.getInjecteeClass();
}
};
hk2injectee.setRequiredType(injectee.getRequiredType());
hk2injectee.setRequiredQualifiers(injectee.getRequiredQualifiers());
if (injectee.getInjecteeDescriptor() != null) {
hk2injectee.setInjecteeDescriptor((ActiveDescriptor<?>) injectee.getInjecteeDescriptor().get());
}
// Delegate the call to HK2 Resolver, Service Handle is not need in the delegated processing.
return resolve(hk2injectee, null);
}
Aggregations