Search in sources :

Example 16 with ResourceProvider

use of org.apache.cxf.jaxrs.lifecycle.ResourceProvider in project tika by apache.

the class StackTraceTest method setUpResources.

@Override
protected void setUpResources(JAXRSServerFactoryBean sf) {
    List<ResourceProvider> rCoreProviders = new ArrayList<ResourceProvider>();
    rCoreProviders.add(new SingletonResourceProvider(new MetadataResource()));
    rCoreProviders.add(new SingletonResourceProvider(new RecursiveMetadataResource()));
    rCoreProviders.add(new SingletonResourceProvider(new DetectorResource()));
    rCoreProviders.add(new SingletonResourceProvider(new TikaResource()));
    rCoreProviders.add(new SingletonResourceProvider(new UnpackerResource()));
    sf.setResourceProviders(rCoreProviders);
}
Also used : RecursiveMetadataResource(org.apache.tika.server.resource.RecursiveMetadataResource) MetadataResource(org.apache.tika.server.resource.MetadataResource) SingletonResourceProvider(org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider) ResourceProvider(org.apache.cxf.jaxrs.lifecycle.ResourceProvider) TikaResource(org.apache.tika.server.resource.TikaResource) ArrayList(java.util.ArrayList) DetectorResource(org.apache.tika.server.resource.DetectorResource) RecursiveMetadataResource(org.apache.tika.server.resource.RecursiveMetadataResource) UnpackerResource(org.apache.tika.server.resource.UnpackerResource) SingletonResourceProvider(org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider)

Example 17 with ResourceProvider

use of org.apache.cxf.jaxrs.lifecycle.ResourceProvider in project tomee by apache.

the class JAXRSServerFactoryBean method setResourceProviders.

/**
 * Sets the list of providers managing the life-cycle of the resource classes
 *
 * @param rps resource providers
 */
public void setResourceProviders(List<ResourceProvider> rps) {
    for (ResourceProvider rp : rps) {
        Class<?> c = rp.getResourceClass();
        setServiceClass(c);
        resourceProviders.put(c, rp);
    }
}
Also used : PerRequestResourceProvider(org.apache.cxf.jaxrs.lifecycle.PerRequestResourceProvider) SingletonResourceProvider(org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider) ResourceProvider(org.apache.cxf.jaxrs.lifecycle.ResourceProvider)

Example 18 with ResourceProvider

use of org.apache.cxf.jaxrs.lifecycle.ResourceProvider in project tomee by apache.

the class JAXRSInInterceptor method setExchangeProperties.

private void setExchangeProperties(Message message, Exchange exchange, OperationResourceInfo ori, MultivaluedMap<String, String> values, int numberOfResources) {
    final ClassResourceInfo cri = ori.getClassResourceInfo();
    exchange.put(OperationResourceInfo.class, ori);
    exchange.put(JAXRSUtils.ROOT_RESOURCE_CLASS, cri);
    message.put(RESOURCE_METHOD, ori.getMethodToInvoke());
    message.put(URITemplate.TEMPLATE_PARAMETERS, values);
    message.put(URITemplate.URI_TEMPLATE, JAXRSUtils.getUriTemplate(message, cri, ori));
    String plainOperationName = ori.getMethodToInvoke().getName();
    if (numberOfResources > 1) {
        plainOperationName = cri.getServiceClass().getSimpleName() + "#" + plainOperationName;
    }
    exchange.put(RESOURCE_OPERATION_NAME, plainOperationName);
    if (ori.isOneway() || PropertyUtils.isTrue(HttpUtils.getProtocolHeader(message, Message.ONE_WAY_REQUEST, null))) {
        exchange.setOneWay(true);
    }
    ResourceProvider rp = cri.getResourceProvider();
    if (rp instanceof SingletonResourceProvider) {
        // cri.isSingleton is not guaranteed to indicate we have a 'pure' singleton
        exchange.put(Message.SERVICE_OBJECT, rp.getInstance(message));
    }
}
Also used : SingletonResourceProvider(org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider) ResourceProvider(org.apache.cxf.jaxrs.lifecycle.ResourceProvider) ClassResourceInfo(org.apache.cxf.jaxrs.model.ClassResourceInfo) SingletonResourceProvider(org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider)

Example 19 with ResourceProvider

use of org.apache.cxf.jaxrs.lifecycle.ResourceProvider in project tomee by apache.

the class JAXRSInvoker method invoke.

public Object invoke(Exchange exchange, Object request) {
    MessageContentsList responseList = checkExchangeForResponse(exchange);
    if (responseList != null) {
        return responseList;
    }
    AsyncResponse asyncResp = exchange.get(AsyncResponse.class);
    if (asyncResp != null) {
        AsyncResponseImpl asyncImpl = (AsyncResponseImpl) asyncResp;
        asyncImpl.prepareContinuation();
        try {
            asyncImpl.handleTimeout();
            return handleAsyncResponse(exchange, asyncImpl);
        } catch (Throwable t) {
            return handleAsyncFault(exchange, asyncImpl, t);
        }
    }
    ResourceProvider provider = getResourceProvider(exchange);
    Object rootInstance = null;
    Message inMessage = exchange.getInMessage();
    try {
        rootInstance = getServiceObject(exchange);
        Object serviceObject = getActualServiceObject(exchange, rootInstance);
        return invoke(exchange, request, serviceObject);
    } catch (WebApplicationException ex) {
        responseList = checkExchangeForResponse(exchange);
        if (responseList != null) {
            return responseList;
        }
        return handleFault(ex, inMessage);
    } finally {
        boolean suspended = isSuspended(exchange);
        if (suspended || exchange.isOneWay() || inMessage.get(Message.THREAD_CONTEXT_SWITCHED) != null) {
            ServerProviderFactory.clearThreadLocalProxies(inMessage);
        }
        if (suspended || isServiceObjectRequestScope(inMessage)) {
            persistRoots(exchange, rootInstance, provider);
        } else {
            provider.releaseInstance(inMessage, rootInstance);
        }
    }
}
Also used : MessageContentsList(org.apache.cxf.message.MessageContentsList) Message(org.apache.cxf.message.Message) WebApplicationException(javax.ws.rs.WebApplicationException) ResourceProvider(org.apache.cxf.jaxrs.lifecycle.ResourceProvider) AsyncResponseImpl(org.apache.cxf.jaxrs.impl.AsyncResponseImpl) AsyncResponse(javax.ws.rs.container.AsyncResponse)

Example 20 with ResourceProvider

use of org.apache.cxf.jaxrs.lifecycle.ResourceProvider in project tomee by apache.

the class CxfRsHttpListener method getServiceObject.

private Object getServiceObject(final Message message) {
    final OperationResourceInfo ori = message.getExchange().get(OperationResourceInfo.class);
    if (ori == null) {
        return null;
    }
    if (!ori.getClassResourceInfo().isRoot()) {
        return message.getExchange().get("org.apache.cxf.service.object.last");
    }
    final ResourceProvider resourceProvider = ori.getClassResourceInfo().getResourceProvider();
    if (resourceProvider.isSingleton()) {
        return resourceProvider.getInstance(message);
    }
    final Object o = message.getExchange().get(CdiResourceProvider.INSTANCE_KEY);
    return o != null || !OpenEJBPerRequestPojoResourceProvider.class.isInstance(resourceProvider) ? o : resourceProvider.getInstance(message);
}
Also used : ResourceProvider(org.apache.cxf.jaxrs.lifecycle.ResourceProvider) SingletonResourceProvider(org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider) OperationResourceInfo(org.apache.cxf.jaxrs.model.OperationResourceInfo)

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