logger.debug("not rose uri: '" + this.path.getUri() + "'");
}
return false;
}
final MatchResult lastMatched = matchResults.get(matchResults.size() - 1);
final EngineGroup leafEngineGroup = lastMatched.getMappingNode().getLeafEngines();
if (leafEngineGroup.size() == 0) {
// not rose uri
if (debugEnabled) {
logger.debug("not rose uri, not exits leaf engines for it: '" + this.path.getUri()
+ "'");
}
return false;
}
final LinkedEngine leafEngine = select(leafEngineGroup.getEngines(path.getMethod()));
if (leafEngine == null) {
// 405 Method Not Allowed
/*
* The method specified in the Request-Line is not allowed for the
* resource identified by the Request-URI. The response MUST include an
* Allow header containing a list of valid methods for the requested
* resource.
*/
StringBuilder allow = new StringBuilder();
final String gap = ", ";
for (ReqMethod method : leafEngineGroup.getAllowedMethods()) {
allow.append(method.toString()).append(gap);
}
if (allow.length() > 0) {
allow.setLength(allow.length() - gap.length());
}
originalHttpResponse.addHeader("Allow", allow.toString());
originalHttpResponse.sendError(405, this.path.getUri());
// true: don't forward to next filter or servlet
return true;
}
if (debugEnabled) {
ActionEngine actionEngine = (ActionEngine) leafEngine.getTarget();
logger.debug("mapped '" + path.getUri() + "' to "
+ actionEngine.getControllerClass().getName() + "#"
+ actionEngine.getMethod().getName());
}
// bind engines
LinkedEngine tempEngine = leafEngine;
MappingNode moduleNode = null;
MappingNode controllerNode = null;
while (tempEngine != null) {
engines.add(tempEngine);
Class<? extends Engine> target = tempEngine.getTarget().getClass();
if (target == ModuleEngine.class) {
moduleNode = tempEngine.getNode();
} else if (target == ControllerEngine.class) {
controllerNode = tempEngine.getNode();
}
tempEngine = tempEngine.getParent();
}
// set module/controller/action path to RequsetPath object
StringBuilder sb = new StringBuilder(path.getUri().length());
MatchResult moduleMatchResult = null;
MatchResult controllerMatchResult = null;
for (int i = 0; i < matchResults.size(); i++) {
MatchResult matchResult = matchResults.get(i);
sb.append(matchResult.getValue());
if (matchResult.getMappingNode() == moduleNode) {
moduleMatchResult = matchResult;
path.setModulePath(sb.toString()); // modulePath
Assert.notNull(engines.get(2));
sb.setLength(0);
}
if (matchResult.getMappingNode() == controllerNode) {
controllerMatchResult = matchResult;
path.setControllerPath(sb.toString()); // controllerPath
Assert.notNull(engines.get(1));
sb.setLength(0);
}
}
path.setActionPath(sb.toString()); // actionPath
Assert.notNull(moduleMatchResult);
Assert.notNull(controllerMatchResult);
this.matchResults = matchResults;
this.curIndexOfChain = engines.size();
Map<String, String> uriParameters = null;
for (int i = matchResults.size() - 1; i >= 0; i--) {
MatchResult matchResult = matchResults.get(i);
String name = matchResult.getParameterName();
if (name != null) {
if (uriParameters == null) {
uriParameters = new HashMap<String, String>(matchResults.size() << 1);
}
uriParameters.put(name, matchResult.getValue());
}
}
HttpServletRequest httpRequest = originalHttpRequest;
if (uriParameters != null && uriParameters.size() > 0) {