// Allow injection of template context
injectableFactory.add(new ContextInjectableProvider<TemplateContext>(
TemplateContext.class, templateContext));
// Obtain all context resolvers
final ContextResolverFactory crf = new ContextResolverFactory();
// Obtain all the exception mappers
this.exceptionFactory = new ExceptionMapperFactory();
// Obtain all message body readers/writers
this.bodyFactory = new MessageBodyFactory(providerServices,
getFeaturesAndProperties().getFeature(FeaturesAndProperties.FEATURE_PRE_1_4_PROVIDER_PRECEDENCE));
injectableFactory.add(
new ContextInjectableProvider<MessageBodyWorkers>(
MessageBodyWorkers.class, bodyFactory));
// Injection of Providers
this.providers = new Providers() {
@Override
public <T> MessageBodyReader<T> getMessageBodyReader(Class<T> c, Type t,
Annotation[] as, MediaType m) {
return bodyFactory.getMessageBodyReader(c, t, as, m);
}
@Override
public <T> MessageBodyWriter<T> getMessageBodyWriter(Class<T> c, Type t,
Annotation[] as, MediaType m) {
return bodyFactory.getMessageBodyWriter(c, t, as, m);
}
@Override
public <T extends Throwable> ExceptionMapper<T> getExceptionMapper(Class<T> c) {
if (Throwable.class.isAssignableFrom(c))
return exceptionFactory.find(c);
else
return null;
}
@Override
public <T> ContextResolver<T> getContextResolver(Class<T> ct, MediaType m) {
return crf.resolve(ct, m);
}
};
injectableFactory.add(
new ContextInjectableProvider<Providers>(
Providers.class, providers));
// Obtain all String readers
this.stringReaderFactory = new StringReaderFactory();
injectableFactory.add(
new ContextInjectableProvider<StringReaderWorkers>(
StringReaderWorkers.class, stringReaderFactory));
MultivaluedParameterExtractorProvider mpep =
new MultivaluedParameterExtractorFactory(stringReaderFactory);
// Add the multi-valued parameter extractor provider
injectableFactory.add(
new ContextInjectableProvider<MultivaluedParameterExtractorProvider>(
MultivaluedParameterExtractorProvider.class, mpep));
// Add per-request-based injectable providers
injectableFactory.add(new CookieParamInjectableProvider(mpep));
injectableFactory.add(new HeaderParamInjectableProvider(mpep));
injectableFactory.add(new HttpContextInjectableProvider());
injectableFactory.add(new MatrixParamInjectableProvider(mpep));
injectableFactory.add(new PathParamInjectableProvider(mpep));
injectableFactory.add(new QueryParamInjectableProvider(mpep));
injectableFactory.add(new FormParamInjectableProvider(mpep));
// Create filter factory
filterFactory = new FilterFactory(providerServices);
// Initiate resource method dispatchers
dispatcherFactory = ResourceMethodDispatcherFactory.create(providerServices);
dispatchingListener = new DispatchingListenerProxy();
// Initiate the WADL factory
this.wadlFactory = new WadlFactory(resourceConfig);
WadlApplicationContextInjectionProxy wadlApplicationContextInjectionProxy = null;
if(!resourceConfig.getFeature(ResourceConfig.FEATURE_DISABLE_WADL)) {
wadlApplicationContextInjectionProxy = new WadlApplicationContextInjectionProxy();
injectableFactory.add(new SingletonTypeInjectableProvider<Context, WadlApplicationContext>(
WadlApplicationContext.class, wadlApplicationContextInjectionProxy) {});
// In order for the application to properly marshall the Application
// object we need to make sure that we provide a JAXBContext that
// will work
final WadlApplicationContext wac = wadlApplicationContextInjectionProxy;
@Provider @Produces({MediaTypes.WADL_STRING,MediaTypes.WADL_JSON_STRING, MediaType.APPLICATION_XML})
class WadlContextResolver implements ContextResolver<JAXBContext>
{
@Override
public JAXBContext getContext(Class<?> type) {
if (com.sun.research.ws.wadl.Application.class.isAssignableFrom(type)) {
return wac.getJAXBContext();
}
else {
return null;
}
}
}
resourceConfig.getSingletons().add(new WadlContextResolver());
// Update the provider services, so this is used
providerServices.update(resourceConfig.getProviderClasses(),
resourceConfig.getProviderSingletons(), injectableFactory);
}
// Initiate filter
filterFactory.init(resourceConfig);
if (!resourceConfig.getMediaTypeMappings().isEmpty() ||
!resourceConfig.getLanguageMappings().isEmpty()) {
boolean present = false;
for (ContainerRequestFilter f : filterFactory.getRequestFilters()) {
present |= f instanceof UriConnegFilter;
}
if (!present) {
filterFactory.getRequestFilters().add(new UriConnegFilter(
resourceConfig.getMediaTypeMappings(),
resourceConfig.getLanguageMappings()));
} else {
LOGGER.warning("The media type and language mappings " +
"declared in the ResourceConfig are ignored because " +
"there is an instance of " + UriConnegFilter.class.getName() +
"present in the list of request filters.");
}
}
// Initiate context resolvers
crf.init(providerServices, injectableFactory);
// Initiate the exception mappers
exceptionFactory.init(providerServices);
// Initiate message body readers/writers