public SelectedResourceMetaData findResource(String path, String httpMethod) throws CuubezException {
if (rootResources == null || path == null || httpMethod == null) {
log.trace("resource not found");
throw new CuubezException(CuubezException.RESOURCE_NOT_FOUND);
}
for (RootResource rootResource : rootResources) {
PathMetaData rootPathMetaData = rootResource.getUriTemplate().match(path);
if (rootPathMetaData != null) {
log.trace("root resource found");
List<SubResource> subResources = rootResource.getSubResources();
for (SubResource subResource : subResources) {
PathMetaData subPathMetaData = null;
if (subResource.getUriTemplate() != null) {
subPathMetaData = subResource.getUriTemplate().match(rootPathMetaData.getTail());
}
if(subPathMetaData != null) {
String subResourceHttpMethod = subResource.getMethodMetaData().getHttpMethod();
if (subResourceHttpMethod.equals(httpMethod)) {
SelectedResourceMetaData selectedResourceMetaData = new SelectedResourceMetaData();
selectedResourceMetaData.setSelectedMethodMetaData(subResource.getMethodMetaData());
selectedResourceMetaData.addPathVariableMetaData(rootPathMetaData.getPathVariables());
selectedResourceMetaData.addPathVariableMetaData(subPathMetaData.getPathVariables());
log.trace("sub resource found");
return selectedResourceMetaData;
}
}
}
}
}
log.trace("resource not found");
throw new CuubezException(CuubezException.RESOURCE_NOT_FOUND);
}