// Obtain all context resolvers
final ContextResolverFactory crf = new ContextResolverFactory();
// Obtain all message body readers/writers
final MessageBodyFactory bodyContext = new MessageBodyFactory(providerServices,
config.getFeature(FeaturesAndProperties.FEATURE_PRE_1_4_PROVIDER_PRECEDENCE));
workers = bodyContext;
// Allow injection of message body context
injectableFactory.add(new ContextInjectableProvider<MessageBodyWorkers>(
MessageBodyWorkers.class, bodyContext));
// Injection of Providers
this.providers = new Providers() {
@Override
public <T> MessageBodyReader<T> getMessageBodyReader(Class<T> c, Type t,
Annotation[] as, MediaType m) {
return bodyContext.getMessageBodyReader(c, t, as, m);
}
@Override
public <T> MessageBodyWriter<T> getMessageBodyWriter(Class<T> c, Type t,
Annotation[] as, MediaType m) {
return bodyContext.getMessageBodyWriter(c, t, as, m);
}
@Override
public <T extends Throwable> ExceptionMapper<T> getExceptionMapper(Class<T> c) {
throw new IllegalArgumentException("This method is not supported on the client side");
}
@Override
public <T> ContextResolver<T> getContextResolver(Class<T> ct, MediaType m) {
return crf.resolve(ct, m);
}
};
injectableFactory.add(
new ContextInjectableProvider<Providers>(
Providers.class, this.providers));
injectableFactory.add(new InjectableProvider<Context, Type>() {
@Override
public ComponentScope getScope() {
return ComponentScope.Singleton;
}
@Override
public Injectable<Injectable> getInjectable(ComponentContext ic, Context a, Type c) {
if (c instanceof ParameterizedType) {
ParameterizedType pt = (ParameterizedType)c;
if (pt.getRawType() == Injectable.class) {
if (pt.getActualTypeArguments().length == 1) {
final Injectable<?> i = injectableFactory.getInjectable(
a.annotationType(),
ic,
a,
pt.getActualTypeArguments()[0],
ComponentScope.PERREQUEST_UNDEFINED_SINGLETON);
if (i == null)
return null;
return new Injectable<Injectable>() {
@Override
public Injectable getValue() {
return i;
}
};
}
}
}
return null;
}
});
// Initiate context resolvers
crf.init(providerServices, injectableFactory);
// Initiate message body readers/writers
bodyContext.init();
// Inject on all components
Errors.setReportMissingDependentFieldOrMethod(true);
componentProviderFactory.injectOnAllComponents();