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(exchange.getInMessage())) {
contextLoader = ClassLoaderUtils
.setThreadContextClassloader(resourceObject.getClass().getClassLoader());
}
result = invoke(exchange, resourceObject, methodToInvoke, params);
} catch (Fault ex) {
String errorMessage = ex.getCause().getMessage();
if (errorMessage != null
&& errorMessage.contains(PROXY_INVOCATION_ERROR_FRAGMENT)) {
org.apache.cxf.common.i18n.Message errorM =
new org.apache.cxf.common.i18n.Message("PROXY_INVOCATION_FAILURE",
BUNDLE,
methodToInvoke,
cri.getServiceClass().getName());
LOG.severe(errorM.toString());
}
Response excResponse = JAXRSUtils.convertFaultToResponse(ex.getCause(),
exchange.getInMessage());
if (excResponse == null) {
ProviderFactory.getInstance(exchange.getInMessage()).clearThreadLocalProxies();
ClassResourceInfo criRoot =
(ClassResourceInfo)exchange.get(JAXRSUtils.ROOT_RESOURCE_CLASS);
if (criRoot != null) {
criRoot.clearThreadLocalProxies();
}
exchange.put(Message.PROPOGATE_EXCEPTION,
JAXRSUtils.propogateException(exchange.getInMessage()));
throw ex;
}
return new MessageContentsList(excResponse);
} finally {
exchange.put(LAST_SERVICE_OBJECT, resourceObject);
if (contextLoader != null) {
contextLoader.reset();
}
}
ClassResourceInfo subCri = null;
if (ori.isSubResourceLocator()) {
try {
Message msg = exchange.getInMessage();
MultivaluedMap<String, String> values = getTemplateValues(msg);
String subResourcePath = values.getFirst(URITemplate.FINAL_MATCH_GROUP);
String httpMethod = (String)msg.get(Message.HTTP_REQUEST_METHOD);
String contentType = (String)msg.get(Message.CONTENT_TYPE);
if (contentType == null) {
contentType = "*/*";
}
List<MediaType> acceptContentType =
(List<MediaType>)msg.getExchange().get(Message.ACCEPT_CONTENT_TYPE);
result = checkResultObject(result, subResourcePath);
subCri = cri.getSubResource(
methodToInvoke.getReturnType(),
ClassHelper.getRealClass(result));
if (subCri == null) {
org.apache.cxf.common.i18n.Message errorM =
new org.apache.cxf.common.i18n.Message("NO_SUBRESOURCE_FOUND",
BUNDLE,
subResourcePath);
LOG.severe(errorM.toString());
throw new WebApplicationException(404);
}
OperationResourceInfo subOri = JAXRSUtils.findTargetMethod(subCri,
exchange.getInMessage(),
httpMethod,
values,
contentType,
acceptContentType,
true);
exchange.put(OperationResourceInfo.class, subOri);
msg.put(URITemplate.TEMPLATE_PARAMETERS, values);
// work out request parameters for the sub-resource class. Here we
// presume InputStream has not been consumed yet by the root resource class.
List<Object> newParams = JAXRSUtils.processParameters(subOri, values, msg);
msg.setContent(List.class, newParams);
return this.invoke(exchange, newParams, result);
} catch (IOException ex) {
Response resp = JAXRSUtils.convertFaultToResponse(ex, exchange.getInMessage());
if (resp == null) {
resp = JAXRSUtils.convertFaultToResponse(new WebApplicationException(ex),
exchange.getInMessage());
}
return new MessageContentsList(resp);
} catch (WebApplicationException ex) {
Response excResponse;
if (JAXRSUtils.noResourceMethodForOptions(ex.getResponse(),
(String)exchange.getInMessage().get(Message.HTTP_REQUEST_METHOD))) {
excResponse = JAXRSUtils.createResponse(subCri, null, null, 200, true);
} else {
excResponse = JAXRSUtils.convertFaultToResponse(ex, exchange.getInMessage());
}
return new MessageContentsList(excResponse);
}
}
return result;
}