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 ServerProviderFactory providerFactory = ServerProviderFactory.getInstance(inMessage);
if (cri.isRoot()) {
cri.injectContexts(resourceObject, ori, inMessage);
ProviderInfo<Application> appProvider = providerFactory.getApplicationProvider();
if (appProvider != null) {
InjectionUtils.injectContexts(appProvider.getProvider(),
appProvider,
inMessage);
}
}
Method resourceMethod = cri.getMethodDispatcher().getMethod(ori);
Method methodToInvoke = null;
if (Proxy.class.isInstance(resourceObject)) {
methodToInvoke = cri.getMethodDispatcher().getProxyMethod(resourceMethod);
if (methodToInvoke == null) {
methodToInvoke = InjectionUtils.checkProxy(resourceMethod, resourceObject);
cri.getMethodDispatcher().addProxyMethod(resourceMethod, methodToInvoke);
}
} else {
methodToInvoke = resourceMethod;
}
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;
AsyncResponseImpl asyncResponse = null;
try {
if (setServiceLoaderAsContextLoader(inMessage)) {
contextLoader = ClassLoaderUtils
.setThreadContextClassloader(resourceObject.getClass().getClassLoader());
}
if (!ori.isSubResourceLocator()) {
asyncResponse = (AsyncResponseImpl)inMessage.get(AsyncResponse.class);
}
result = invoke(exchange, resourceObject, methodToInvoke, params);
if (asyncResponse != null) {
if (!asyncResponse.suspendContinuationIfNeeded()) {
result = handleAsyncResponse(exchange, asyncResponse);
} else {
providerFactory.clearThreadLocalProxies();
}
}
} catch (Fault ex) {
Object faultResponse;
if (asyncResponse != null && !asyncResponse.suspendContinuationIfNeeded()) {