use of org.apache.cxf.jaxrs.lifecycle.ResourceProvider in project tomee by apache.
the class JAXRSInvoker method getResourceProvider.
private ResourceProvider getResourceProvider(Exchange exchange) {
Object provider = exchange.remove(JAXRSUtils.ROOT_PROVIDER);
if (provider == null) {
OperationResourceInfo ori = exchange.get(OperationResourceInfo.class);
ClassResourceInfo cri = ori.getClassResourceInfo();
return cri.getResourceProvider();
}
return (ResourceProvider) provider;
}
use of org.apache.cxf.jaxrs.lifecycle.ResourceProvider in project tomee by apache.
the class ResourceContextImpl method getResource.
@Override
public <T> T getResource(Class<T> cls) {
final ResourceProvider rp;
Object propValue = m.getContextualProperty(CONTEXT_PROVIDER_PROP);
if (propValue instanceof ResourceContextProvider) {
rp = ((ResourceContextProvider) propValue).getResourceProvider(cls);
} else {
rp = new PerRequestResourceProvider(cls);
}
T resource = cls.cast(rp.getInstance(m));
return doInitResource(cls, resource);
}
use of org.apache.cxf.jaxrs.lifecycle.ResourceProvider in project nutch by apache.
the class NutchServer method getResourceProviders.
private List<ResourceProvider> getResourceProviders() {
List<ResourceProvider> resourceProviders = new ArrayList<>();
resourceProviders.add(new SingletonResourceProvider(getConfManager()));
return resourceProviders;
}
use of org.apache.cxf.jaxrs.lifecycle.ResourceProvider in project cxf by apache.
the class JAXRSCdiResourceExtension method classes2singletons.
/**
* JAX-RS application has defined singletons as being classes of any providers, resources and features.
* In the JAXRSServerFactoryBean, those should be split around several method calls depending on instance
* type. At the moment, only the Feature is CXF-specific and should be replaced by JAX-RS Feature implementation.
* @param application the application instance
* @return classified instances of classes by instance types
*/
private ClassifiedClasses classes2singletons(final Application application, final BeanManager beanManager) {
final ClassifiedClasses classified = new ClassifiedClasses();
// now loop through the classes
Set<Class<?>> classes = application.getClasses();
if (!classes.isEmpty()) {
classified.addProviders(loadProviders(beanManager, classes));
classified.addFeatures(loadFeatures(beanManager, classes));
for (final Bean<?> bean : serviceBeans) {
if (classes.contains(bean.getBeanClass())) {
// normal scoped beans will return us a proxy in getInstance so it is singletons for us,
// @Singleton is indeed a singleton
// @Dependent should be a request scoped instance but for backward compat we kept it a singleton
//
// other scopes are considered request scoped (for jaxrs)
// and are created per request (getInstance/releaseInstance)
final ResourceProvider resourceProvider;
if (isCxfSingleton(beanManager, bean)) {
final Lifecycle lifecycle = new Lifecycle(beanManager, bean);
resourceProvider = new SingletonResourceProvider(lifecycle, bean.getBeanClass());
// so we only need this case here
if (Dependent.class == bean.getScope()) {
disposableLifecycles.add(lifecycle);
}
} else {
resourceProvider = new PerRequestResourceProvider(() -> new Lifecycle(beanManager, bean), bean.getBeanClass());
}
classified.addResourceProvider(resourceProvider);
}
}
}
return classified;
}
use of org.apache.cxf.jaxrs.lifecycle.ResourceProvider in project cxf by apache.
the class JAXRSCdiResourceExtension method createFactoryInstance.
/**
* Create the JAXRSServerFactoryBean from the objects declared by application itself.
* @param application application instance
* @return JAXRSServerFactoryBean instance
*/
private JAXRSServerFactoryBean createFactoryInstance(final Application application, final BeanManager beanManager) {
final JAXRSServerFactoryBean instance = ResourceUtils.createApplication(application, false, false, false, bus);
final ClassifiedClasses classified = classes2singletons(application, beanManager);
instance.setProviders(classified.getProviders());
instance.getFeatures().addAll(classified.getFeatures());
for (final ResourceProvider resourceProvider : classified.getResourceProviders()) {
instance.setResourceProvider(resourceProvider.getResourceClass(), resourceProvider);
}
return instance;
}
Aggregations