publicvoid handle(HttpServletRequest request, HttpServletResponse response) throws IOException { try { String pathInfo = request.getPathInfo(); contextPath = request.getContextPath(); if (pathInfo ==null|| pathInfo.length() ==0||"/".equals(pathInfo)) { response.sendRedirect(contextPath + request.getServletPath() + indexHandlerUrl); } else { // Loop through all the known URLs for (Entry<String, Object> entry : urlMapping.entrySet()) { String url = entry.getKey(); // If this URL matches, call the handler if (pathInfo.startsWith(url)) { Handler handler = (Handler) entry.getValue(); handler.handle(request, response); return; } } notFoundHandler.handle(request, response); } } catch (Exception ex) { exceptionHandler.setException(ex); exceptionHandler.handle(request, response); } }
这些handle有多种
1,
/**
* A Handler that supports requests for auth.js
*/
public class AuthHandler extends JavaScriptHandler
2,
/**
* A Handler that supports requests for engine.js
* @author Joe Walker [joe at getahead dot ltd dot uk]
*/
public class EngineHandler extends JavaScriptHandler
3,
/**
* A Handler that supports requests for util.js
* @author Joe Walker [joe at getahead dot ltd dot uk]
*/
public class GiHandler extends JavaScriptHandler
4,
/**
* A handler for interface generation requests
* @author Joe Walker [joe at getahead dot ltd dot uk]
*/
public class InterfaceHandler extends JavaScriptHandler
上面三种都是系统范围的handle,对于我们自己编写的类,应该是触发InterfaceHandler 。
我们再看如下关系
public abstract class CachingFileHandler implements Handler
public abstract class TemplateHandler extends CachingFileHandler
public abstract class JavaScriptHandler extends TemplateHandler
public class InterfaceHandler extends JavaScriptHandler
逐级往上继承
InterfaceHandler,我们看到如下代码,执行顺序-4,里面调用了远程remoter
protected String generateTemplate(HttpServletRequest request, HttpServletResponse response) throws IOException { String scriptName = request.getPathInfo(); scriptName = scriptName.replace(interfaceHandlerUrl, ""); String contextServletPath = request.getContextPath() + request.getServletPath(); if (scriptName.endsWith(PathConstants.EXTENSION_JS)) { scriptName = scriptName.replace(PathConstants.EXTENSION_JS, ""); if (!LocalUtil.isJavaIdentifier(scriptName)) { log.debug("Throwing at request for script with name: '"+ scriptName +"'"); thrownew SecurityException("Script names may only contain Java Identifiers"); } return remoter.generateInterfaceScript(scriptName, contextServletPath); } elseif (scriptName.endsWith(PathConstants.EXTENSION_SDOC)) { scriptName = scriptName.replace(PathConstants.EXTENSION_SDOC, ""); if (!LocalUtil.isJavaIdentifier(scriptName)) { log.debug("Throwing at request for script with name: '"+ scriptName +"'"); thrownew SecurityException("Script names may only contain Java Identifiers"); } return remoter.generateInterfaceSDoc(scriptName, contextServletPath); } else { log.debug("Throwing at request for script with unknown extension: '"+ scriptName +"'"); thrownew SecurityException("Unknown extension"); } }