private void handleSubResourceLocator(SubResourceInstance subResourceInstance,
List<SubResourceInstance> subResources,
MessageContext context,
HandlersChain chain) throws Throwable {
ResourceRegistry registry = context.getAttribute(ResourceRegistry.class);
SearchResult result = context.getAttribute(SearchResult.class);
UriTemplateMatcher matcher = subResourceInstance.getMatcher();
// // dispatch to the sub-resource locator.
// result.setFound(true);
// result.setMethod(subResourceInstance);
// // save the matched template variables for UriInfo
// matcher.storeVariables(result.getData().getMatchedVariables(),
// false);
// // save the matched uri for UriInfo
// result.getData().addMatchedUri(matcher.getHead(false));
saveFoundMethod(result, matcher, subResourceInstance, context);
// continue the chain to invoke the locator
if (logger.isDebugEnabled()) {
MethodMetadata metadata =
(subResourceInstance == null) ? null : subResourceInstance.getMetadata();
logger.debug("Found subresource locator to invoke: {} ", metadata); //$NON-NLS-1$
}
chain.doChain(context);
// the object returned from the locator is a sub-resource so we must
// continue the search in it
Object subResource = context.getResponseEntity();
if (subResource == null) {
logger.debug("Subresource returned was null so returning a 404 Not Found"); //$NON-NLS-1$
result.setError(new WebApplicationException(Status.NOT_FOUND));
return;
}
ResourceRecord record = registry.getRecord(subResource, false);
ResourceInstance resourceInstance = new ResourceInstance(subResource, record, matcher);
// save the resource for UriInfo
result.getData().getMatchedResources().addFirst(resourceInstance);
// call recursively to search in the sub-resource