private static final Logger logger = LoggerFactory.getLogger(FindResourceMethodHandler.class);
public void handleRequest(MessageContext context, HandlersChain chain) throws Throwable {
SearchResult result = context.getAttribute(SearchResult.class);
ResourceInstance resource = result.getResource();
// resource method
if (resource.isExactMatch()) {
logger
.debug("Root resource @Path matches exactly so finding root resource method in {}",
resource.getResourceClass().getName());
handleResourceMethod(context, chain);
return;
}
// sub-resource method or locator
UriTemplateMatcher templateMatcher = resource.getMatcher();
String tail = UriTemplateProcessor.normalizeUri(templateMatcher.getTail(false));
logger.debug("Unmatched tail to the URI: {}", tail);
// get a sorted list of all the sub-resources (methods and locators)
List<SubResourceInstance> subResources = resource.getRecord().getMatchingSubResources(tail);
logger.debug("Possible subresources found: {}", subResources);
if (subResources.size() == 0) {
result.setError(new WebApplicationException(Response.Status.NOT_FOUND));
return;
}