Search in sources :

Example 6 with ResourceProvider

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;
}
Also used : ResourceProvider(org.apache.cxf.jaxrs.lifecycle.ResourceProvider) ClassResourceInfo(org.apache.cxf.jaxrs.model.ClassResourceInfo) OperationResourceInfo(org.apache.cxf.jaxrs.model.OperationResourceInfo)

Example 7 with ResourceProvider

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);
}
Also used : PerRequestResourceProvider(org.apache.cxf.jaxrs.lifecycle.PerRequestResourceProvider) ResourceProvider(org.apache.cxf.jaxrs.lifecycle.ResourceProvider) ResourceContextProvider(org.apache.cxf.jaxrs.ext.ResourceContextProvider) PerRequestResourceProvider(org.apache.cxf.jaxrs.lifecycle.PerRequestResourceProvider)

Example 8 with ResourceProvider

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;
}
Also used : SingletonResourceProvider(org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider) ResourceProvider(org.apache.cxf.jaxrs.lifecycle.ResourceProvider) ArrayList(java.util.ArrayList) SingletonResourceProvider(org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider)

Example 9 with ResourceProvider

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;
}
Also used : ResourceProvider(org.apache.cxf.jaxrs.lifecycle.ResourceProvider)

Example 10 with ResourceProvider

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;
}
Also used : ResourceProvider(org.apache.cxf.jaxrs.lifecycle.ResourceProvider) JAXRSServerFactoryBean(org.apache.cxf.jaxrs.JAXRSServerFactoryBean)

Aggregations

ResourceProvider (org.apache.cxf.jaxrs.lifecycle.ResourceProvider)25 SingletonResourceProvider (org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider)14 PerRequestResourceProvider (org.apache.cxf.jaxrs.lifecycle.PerRequestResourceProvider)8 ArrayList (java.util.ArrayList)7 JAXRSServerFactoryBean (org.apache.cxf.jaxrs.JAXRSServerFactoryBean)6 ClassResourceInfo (org.apache.cxf.jaxrs.model.ClassResourceInfo)5 OperationResourceInfo (org.apache.cxf.jaxrs.model.OperationResourceInfo)5 HashMap (java.util.HashMap)4 Map (java.util.Map)4 DetectorResource (org.apache.tika.server.resource.DetectorResource)4 MetadataResource (org.apache.tika.server.resource.MetadataResource)4 RecursiveMetadataResource (org.apache.tika.server.resource.RecursiveMetadataResource)3 TikaResource (org.apache.tika.server.resource.TikaResource)3 UnpackerResource (org.apache.tika.server.resource.UnpackerResource)3 ApplicationPath (javax.ws.rs.ApplicationPath)2 MultivaluedMap (javax.ws.rs.core.MultivaluedMap)2 Feature (org.apache.cxf.feature.Feature)2 ResourceContextProvider (org.apache.cxf.jaxrs.ext.ResourceContextProvider)2 ElementClass (org.apache.cxf.jaxrs.ext.xml.ElementClass)2 MessageImpl (org.apache.cxf.message.MessageImpl)2