use of org.glassfish.jersey.internal.inject.InjectionManager in project jersey by jersey.
the class ProviderBinderTest method testServicesNotEmpty.
@Test
public void testServicesNotEmpty() {
InjectionManager injectionManager = Injections.createInjectionManager(initBinders());
Set<MessageBodyReader> providers = Providers.getProviders(injectionManager, MessageBodyReader.class);
assertTrue(providers.size() > 0);
}
use of org.glassfish.jersey.internal.inject.InjectionManager in project jersey by jersey.
the class ProviderBinderTest method testServicesMbw.
@Test
public void testServicesMbw() {
InjectionManager injectionManager = Injections.createInjectionManager(initBinders());
Set<MessageBodyWriter> providers = Providers.getProviders(injectionManager, MessageBodyWriter.class);
assertTrue(providers.size() > 0);
}
use of org.glassfish.jersey.internal.inject.InjectionManager in project jersey by jersey.
the class ParameterInjectionBinder method configure.
@Override
public void configure() {
// Param converter providers
// TODO: Replace by non-di version
bind(new ParamConverters.AggregatedProvider()).to(ParamConverterProvider.class);
Provider<ContainerRequest> requestProvider = Injections.getProvider(injectionManager, ContainerRequest.class);
Provider<AsyncContext> asyncContextProvider = Injections.getProvider(injectionManager, AsyncContext.class);
Function<Class<? extends Configuration>, Configuration> clientConfigProvider = clientConfigClass -> Injections.getOrCreate(injectionManager, clientConfigClass);
// Param Converters must be initialized Lazy and created at the time of the call on extractor
LazyValue<ParamConverterFactory> lazyParamConverterFactory = Values.lazy((Value<ParamConverterFactory>) () -> new ParamConverterFactory(Providers.getProviders(injectionManager, ParamConverterProvider.class), Providers.getCustomProviders(injectionManager, ParamConverterProvider.class)));
LazyValue<Configuration> lazyConfiguration = Values.lazy((Value<Configuration>) () -> injectionManager.getInstance(Configuration.class));
MultivaluedParameterExtractorFactory paramExtractor = new MultivaluedParameterExtractorFactory(lazyParamConverterFactory);
bind(paramExtractor).to(MultivaluedParameterExtractorProvider.class);
// Parameter injection value providers
AsyncResponseValueSupplierProvider asyncSupplier = new AsyncResponseValueSupplierProvider(asyncContextProvider);
bindValueSupplier(asyncSupplier);
CookieParamValueSupplierProvider cookieSupplier = new CookieParamValueSupplierProvider(paramExtractor, requestProvider);
bindValueSupplier(cookieSupplier);
EntityParamValueSupplierProvider entitySupplier = new EntityParamValueSupplierProvider(paramExtractor, requestProvider);
bindValueSupplier(entitySupplier);
FormParamValueSupplierProvider formSupplier = new FormParamValueSupplierProvider(paramExtractor, requestProvider);
bindValueSupplier(formSupplier);
HeaderParamValueSupplierProvider headerSupplier = new HeaderParamValueSupplierProvider(paramExtractor, requestProvider);
bindValueSupplier(headerSupplier);
MatrixParamValueSupplierProvider matrixSupplier = new MatrixParamValueSupplierProvider(paramExtractor, requestProvider);
bindValueSupplier(matrixSupplier);
PathParamValueSupplierProvider pathSupplier = new PathParamValueSupplierProvider(paramExtractor, requestProvider);
bindValueSupplier(pathSupplier);
QueryParamValueSupplierProvider querySupplier = new QueryParamValueSupplierProvider(paramExtractor, requestProvider);
bindValueSupplier(querySupplier);
WebTargetValueSupplierProvider webTargetSupplier = new WebTargetValueSupplierProvider(requestProvider, lazyConfiguration, clientConfigProvider);
bindValueSupplier(webTargetSupplier);
BeanParamValueSupplierProvider beanSupplier = new BeanParamValueSupplierProvider(paramExtractor, requestProvider, injectionManager);
bindValueSupplier(beanSupplier);
// Register InjectionResolvers with param providers
// TODO: RENAME INJECTION RESOLVER
bind(new ParamInjectionResolver<>(cookieSupplier, CookieParam.class));
bind(new ParamInjectionResolver<>(formSupplier, FormParam.class));
bind(new ParamInjectionResolver<>(headerSupplier, HeaderParam.class));
bind(new ParamInjectionResolver<>(matrixSupplier, MatrixParam.class));
bind(new ParamInjectionResolver<>(querySupplier, QueryParam.class));
bind(new ParamInjectionResolver<>(pathSupplier, PathParam.class));
bind(new ParamInjectionResolver<>(asyncSupplier, Suspended.class));
bind(new ParamInjectionResolver<>(webTargetSupplier, Uri.class));
bind(new ParamInjectionResolver<>(beanSupplier, BeanParam.class));
// Delegated value supplier for Context InjectionResolver which is implemented directly in DI provider
ContextInjectionResolver contextInjectionResolver = injectionManager.getInstance(ContextInjectionResolver.class);
bind(new DelegatedInjectionValueSupplierProvider(contextInjectionResolver, injectionManager::createForeignDescriptor)).to(ValueSupplierProvider.class);
}
use of org.glassfish.jersey.internal.inject.InjectionManager in project jersey by jersey.
the class RequestResponseWrapperProvider method getRequestScopedInitializerProvider.
@Override
public RequestScopedInitializerProvider getRequestScopedInitializerProvider() {
return new RequestScopedInitializerProvider() {
@Override
public RequestScopedInitializer get(final RequestContextProvider context) {
return new RequestScopedInitializer() {
@Override
public void initialize(InjectionManager injectionManager) {
ServiceLocator locator = ((HK2InjectionManager) injectionManager).getServiceLocator();
locator.<Ref<HttpServletRequest>>getService(REQUEST_TYPE).set(finalWrap(context.getHttpServletRequest()));
locator.<Ref<HttpServletResponse>>getService(RESPONSE_TYPE).set(finalWrap(context.getHttpServletResponse()));
}
};
}
};
}
use of org.glassfish.jersey.internal.inject.InjectionManager in project jersey by jersey.
the class ApplicationHandler method bindProvidersAndResources.
private void bindProvidersAndResources(final Iterable<ComponentProvider> componentProviders, final ComponentBag componentBag, final Collection<Class<?>> resourceClasses, final Collection<Object> resourceInstances) {
JerseyResourceContext resourceContext = injectionManager.getInstance(JerseyResourceContext.class);
Set<Class<?>> registeredClasses = runtimeConfig.getRegisteredClasses();
/*
* Check the {@code component} whether it is correctly configured for client or server {@link RuntimeType runtime}.
*/
java.util.function.Predicate<Class<?>> correctlyConfigured = componentClass -> Providers.checkProviderRuntime(componentClass, componentBag.getModel(componentClass), RuntimeType.SERVER, !registeredClasses.contains(componentClass), resourceClasses.contains(componentClass));
/*
* Check the {@code resource class} whether it is correctly configured for client or server {@link RuntimeType runtime}.
*/
BiPredicate<Class<?>, ContractProvider> correctlyConfiguredResource = (resourceClass, model) -> Providers.checkProviderRuntime(resourceClass, model, RuntimeType.SERVER, !registeredClasses.contains(resourceClass), true);
Set<Class<?>> componentClassses = componentBag.getClasses(ComponentBag.excludeMetaProviders(injectionManager)).stream().filter(correctlyConfigured).collect(Collectors.toSet());
// Merge programmatic resource classes with component classes.
Set<Class<?>> classes = Collections.newSetFromMap(new IdentityHashMap<>());
classes.addAll(componentClassses);
classes.addAll(resourceClasses);
// Bind classes.
for (final Class<?> componentClass : classes) {
ContractProvider model = componentBag.getModel(componentClass);
if (bindWithComponentProvider(componentClass, model, componentProviders)) {
continue;
}
if (resourceClasses.contains(componentClass)) {
if (!Resource.isAcceptable(componentClass)) {
LOGGER.warning(LocalizationMessages.NON_INSTANTIABLE_COMPONENT(componentClass));
continue;
}
if (model != null && !correctlyConfiguredResource.test(componentClass, model)) {
model = null;
}
resourceContext.unsafeBindResource(componentClass, model, injectionManager);
} else {
ProviderBinder.bindProvider(componentClass, model, injectionManager);
}
}
// Merge programmatic resource instances with other component instances.
Set<Object> instances = componentBag.getInstances(ComponentBag.excludeMetaProviders(injectionManager)).stream().filter(instance -> correctlyConfigured.test(instance.getClass())).collect(Collectors.toSet());
instances.addAll(resourceInstances);
// Bind instances.
for (Object component : instances) {
ContractProvider model = componentBag.getModel(component.getClass());
if (resourceInstances.contains(component)) {
if (model != null && !correctlyConfiguredResource.test(component.getClass(), model)) {
model = null;
}
resourceContext.unsafeBindResource(component, model, injectionManager);
} else {
ProviderBinder.bindProvider(component, model, injectionManager);
}
}
}
Aggregations