String requestURI = request.getRequestURI();
String contextPath = request.getContextPath();
if (request instanceof ModuleHttpServletRequest) {
//deal with forwards or includes
final RequestModuleMapping requestModuleMapping = (RequestModuleMapping) request.getAttribute(EXISTING_REQUEST_MODULE_MAPPING);
if (requestModuleMapping != null) {
if (!useExternalForwardingOrIncludes(request)) {
ModuleHttpServletRequest moduleRequest = (ModuleHttpServletRequest) request;
moduleRequest.setReuse();
return requestModuleMapping;
}
}
}
final String subpath;
if (contextPath != null) {
subpath = requestURI.substring(contextPath.length());
} else {
subpath = requestURI;
}
TreeNode<ModuleNameWithPath> modulePrefixNode = getModuleForURI(subpath);
if (logger.isDebugEnabled()) {
logger.debug("Module for URI " + requestURI + ": " + modulePrefixNode);
}
if (modulePrefixNode == null) {
return null;
}
ModuleNameWithPath value = modulePrefixNode.getValue();
final RequestModuleMapping newMapping = new RequestModuleMapping(modulePrefixNode.getKey(), value.getModuleName(), value.getContextPath(), value.getServletPath());
request.setAttribute(EXISTING_REQUEST_MODULE_MAPPING, newMapping);
return newMapping;
}