public Object invoke(Exchange exchange, Object request, Object resourceObject) {
final OperationResourceInfo ori = exchange.get(OperationResourceInfo.class);
final ClassResourceInfo cri = ori.getClassResourceInfo();
final Message inMessage = exchange.getInMessage();
final ProviderFactory providerFactory = ProviderFactory.getInstance(inMessage);
boolean wasSuspended = exchange.remove(REQUEST_WAS_SUSPENDED) != null;
if (!wasSuspended) {
pushOntoStack(ori, ClassHelper.getRealClass(resourceObject), inMessage);
}
final boolean contextsAvailable = cri.contextsAvailable();
final boolean paramsAvailable = cri.paramsAvailable();
if (contextsAvailable || paramsAvailable) {
Object realResourceObject = ClassHelper.getRealObject(resourceObject);
if (paramsAvailable) {
JAXRSUtils.injectParameters(ori, realResourceObject, inMessage);
}
if (contextsAvailable) {
InjectionUtils.injectContexts(realResourceObject, cri, inMessage);
}
}
if (cri.isRoot()) {
ProviderInfo<?> appProvider =
(ProviderInfo<?>)exchange.getEndpoint().get(Application.class.getName());
if (appProvider != null) {
InjectionUtils.injectContexts(appProvider.getProvider(),
appProvider,
inMessage);
}
}
Method methodToInvoke = InjectionUtils.checkProxy(
cri.getMethodDispatcher().getMethod(ori), resourceObject);
List<Object> params = null;
if (request instanceof List) {
params = CastUtils.cast((List<?>)request);
} else if (request != null) {
params = new MessageContentsList(request);
}
Object result = null;
ClassLoaderHolder contextLoader = null;
try {
if (setServiceLoaderAsContextLoader(inMessage)) {
contextLoader = ClassLoaderUtils
.setThreadContextClassloader(resourceObject.getClass().getClassLoader());
}
AsyncResponseImpl asyncResponse = null;
if (!ori.isSubResourceLocator()) {
asyncResponse = (AsyncResponseImpl)inMessage.get(AsyncResponse.class);
}
result = invoke(exchange, resourceObject, methodToInvoke, params);
if (asyncResponse != null) {
if (!asyncResponse.isSuspended() && !asyncResponse.isResumedByApplication()) {
asyncResponse.suspendContinuation();
providerFactory.clearThreadLocalProxies();
} else {
result = handleAsyncResponse(exchange, asyncResponse.getResponseObject());
}
}
} catch (Fault ex) {