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 {}", //$NON-NLS-1$
resource.getResourceClass().getName());
handleResourceMethod(context, chain);
return;
}
// sub-resource method or locator
UriTemplateMatcher templateMatcher = resource.getMatcher();
String tail = templateMatcher.getTail(false);
if (tail == null) {
tail = ""; //$NON-NLS-1$
}
if (tail.startsWith("/")) { //$NON-NLS-1$
tail = tail.substring(1);
}
logger.debug("Unmatched tail to the URI: {}", tail); //$NON-NLS-1$
// 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); //$NON-NLS-1$
if (subResources.size() == 0) {
result.setError(new WebApplicationException(Response.Status.NOT_FOUND));
return;
}