如果请求的URI是"/",对应的servlet如何响应?
===================================================================
ServletHolder indexRedirect = new ServletHolder(new IndexRedirectServlet(defaultServletPath));
root.addServlet(indexRedirect, "/");
===================================================================
所以需要分析IndexRedirectServlet
1)servlet的init方法
这里涉及到了3个类,分别是:
IndexRedirectServlet LoginAbstractAzkabanServlet AbstractAzkabanServlet
首先找这3个类的init方法---第一个init方法在LoginAbstractAzkabanServlet
所以需要从这个类的init方法开始看
AbstractAzkabanServlet.init
@Override
public void init(ServletConfig config) throws ServletException {
//看到这里了
application =//获取之前的server实例
(AzkabanServer) config.getServletContext().getAttribute(
AzkabanServletContextListener.AZKABAN_SERVLET_CONTEXT_KEY);
if (application == null) {
throw new IllegalStateException(
"No batch application is defined in the servlet context!");
}
//看到这里了
Props props = application.getServerProps();
//看到这里了
name = props.getString("azkaban.name", "");//获取名字
label = props.getString("azkaban.label", "");//label
color = props.getString("azkaban.color", "#FF0000");//颜色
if (application instanceof AzkabanWebServer) {//
AzkabanWebServer server = (AzkabanWebServer) application;//转化
//
viewerPlugins = PluginRegistry.getRegistry().getViewerPlugins();//内容为空
//
triggerPlugins =
new ArrayList<TriggerPlugin>(server.getTriggerPlugins().values());
}
}
---然后是
LoginAbstractAzkabanServlet.init
@Override
public void init(ServletConfig config) throws ServletException {
super.init(config);
//继续
multipartParser = new MultipartParser(DEFAULT_UPLOAD_DISK_SPOOL_SIZE);
//上面是通过commons-upload来获取
shouldLogRawUserAgent =
getApplication().getServerProps().getBoolean("accesslog.raw.useragent",
false);
}
-------------------
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
// Set session id
// 入口在这
//获取session
Session session = getSessionFromRequest(req);
//记录本次访问行为
logRequest(req, session);
//第1次不执行
if (hasParam(req, "logout")) {
resp.sendRedirect(req.getContextPath());
if (session != null) {
getApplication().getSessionCache().removeSession(session.getSessionId());
}
return;
}
//不执行
if (session != null) {
if (logger.isDebugEnabled()) {
logger.debug("Found session " + session.getUser());
}
if (handleFileGet(req, resp)) {
return;
}
handleGet(req, resp, session);
} else {
if (hasParam(req, "ajax")) {
HashMap<String, String> retVal = new HashMap<String, String>();
retVal.put("error", "session");
this.writeJSON(resp, retVal);
} else {
//真正处理逻辑
handleLogin(req, resp);
}
}
}
所以,需要继续查看handleLogin的代码
private void handleLogin(HttpServletRequest req, HttpServletResponse resp, String errorMsg)
throws ServletException, IOException {
//1)生成数据
Page page = newPage(req, resp, "azkaban/webapp/servlet/velocity/login.vm");
if (errorMsg != null) {
page.add("errorMsg", errorMsg);
}
//渲染
page.render();
}
这部分跟springMVC就类似了,就不细说了!
主要看下azkaban/webapp/servlet/velocity/login.vm的内容
好,所以,,我们就能看到了
怎么样,是不是很酷
---
通过学习azkaban,可以了解以下知识
Jetty DBUtils Velocity(渲染)。