@@ -0,0 +1,2245 @@
+package com.dianping.cat.servlet;%0D%0A%0D%0Aimport java.io.File;%0D%0Aimport java.io.IOException;%0D%0Aimport java.io.PrintWriter;%0D%0A%0D%0Aimport javax.servlet.ServletConfig;%0D%0Aimport javax.servlet.ServletException;%0D%0Aimport javax.servlet.http.HttpServletRequest;%0D%0Aimport javax.servlet.http.HttpServletResponse;%0D%0A%0D%0Aimport org.unidal.initialization.DefaultModuleContext;%0D%0Aimport org.unidal.initialization.ModuleContext;%0D%0Aimport org.unidal.initialization.ModuleInitializer;%0D%0Aimport org.unidal.web.AbstractContainerServlet;%0D%0A%0D%0Aimport com.dianping.cat.Cat;%0D%0A%0D%0Apublic class CatServlet extends AbstractContainerServlet %7B%0D%0A%09private static final long serialVersionUID = 1L;%0D%0A%0D%0A%09private Exception m_exception;%0D%0A%0D%0A%09private File getConfigFile(ServletConfig config, String name, String defaultConfigValue) %7B%0D%0A%09%09String configValue = config.getInitParameter(name);%0D%0A%0D%0A%09%09if (configValue != null) %7B%0D%0A%09%09%09if (configValue.startsWith(%22/%22)) %7B%0D%0A%09%09%09%09return new File(configValue);%0D%0A%09%09%09%7D else %7B%0D%0A%09%09%09%09return new File(Cat.getCatHome(), configValue);%0D%0A%09%09%09%7D%0D%0A%09%09%7D else %7B%0D%0A%09%09%09return new File(Cat.getCatHome(), defaultConfigValue);%0D%0A%09%09%7D%0D%0A%09%7D%0D%0A%0D%0A%09@Override%0D%0A%09protected void initComponents(ServletConfig servletConfig) throws ServletException %7B%0D%0A%09%09try %7B%0D%0A%09%09%09ModuleContext ctx = new DefaultModuleContext(getContainer());%0D%0A%09%09%09ModuleInitializer initializer = ctx.lookup(ModuleInitializer.class);%0D%0A%09%09%09File clientXmlFile = getConfigFile(servletConfig, %22cat-client-xml%22, %22client.xml%22);%0D%0A%09%09%09File serverXmlFile = getConfigFile(servletConfig, %22cat-server-xml%22, %22server.xml%22);%0D%0A%0D%0A%09%09%09ctx.setAttribute(%22cat-client-config-file%22, clientXmlFile);%0D%0A%09%09%09ctx.setAttribute(%22cat-server-config-file%22, serverXmlFile);%0D%0A%09%09%09initializer.execute(ctx);%0D%0A%09%09%7D catch (Exception e) %7B%0D%0A%09%09%09m_exception = e;%0D%0A%09%09%09System.err.println(e);%0D%0A%09%09%09throw new ServletException(e);%0D%0A%09%09%7D%0D%0A%09%7D%0D%0A%0D%0A%09@Override%0D%0A%09protected void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException %7B%0D%0A%09%09res.setCharacterEncoding(%22utf-8%22);%0D%0A%09%09res.setContentType(%22text/plain%22);%0D%0A%0D%0A%09%09PrintWriter writer = res.getWriter();%0D%0A%0D%0A%09%09if (m_exception != null) %7B%0D%0A%09%09%09writer.write(%22Server has NOT been initialized successfully!%5Cr%5Cn%5Cr%5Cn%22);%0D%0A%09%09%09m_exception.printStackTrace(writer);%0D%0A%09%09%7D else %7B%0D%0A%09%09%09writer.write(%22Not implemented yet!%22);%0D%0A%09%09%7D%0D%0A%09%7D%0D%0A%7D

add the servlet