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);
}
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);
}
}
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));
}
}
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);
}
}
}
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);
}
Aggregations