1 41 package com.mvnforum.admin; 42 43 import java.io.IOException ; 44 import javax.servlet.ServletException ; 45 import javax.servlet.http.*; 46 47 import org.apache.commons.logging.Log; 48 import org.apache.commons.logging.LogFactory; 49 import com.mvnforum.MVNForumInfo; 50 import net.myvietnam.mvncore.db.DBUtils; 51 import net.myvietnam.mvncore.filter.IPFilter; 52 import net.myvietnam.mvncore.filter.UserAgentFilter; 53 import net.myvietnam.mvncore.util.ParamUtil; 54 import net.myvietnam.mvncore.util.DateUtil; 55 56 public class ForumAdminServlet extends HttpServlet { 57 58 private static Log log = LogFactory.getLog(ForumAdminServlet.class); 59 60 private AdminModuleProcessor adminModuleProcessor = null; 61 private static int count = 0; 62 63 static final long START_TIME = DateUtil.getCurrentGMTTimestamp().getTime(); 64 65 public static final long getStartTime() { 66 return START_TIME; 67 } 68 69 public void init() throws ServletException { 70 adminModuleProcessor = new AdminModuleProcessor(this); 71 log.info("<<---- ForumAdminServlet has been inited. Detailed info: " + MVNForumInfo.getProductVersion() + " (Build: " + MVNForumInfo.getProductReleaseDate() + ") ---->>"); 72 } 73 74 75 public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException , IOException { 76 process(request, response); 77 } 78 79 80 public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException , IOException { 81 process(request, response); 82 } 83 84 public void process(HttpServletRequest request, HttpServletResponse response) 85 throws IOException , ServletException { 86 long startTime = 0; 87 if (log.isDebugEnabled()) { 88 startTime = System.currentTimeMillis(); 89 } 90 count++; 91 try { 92 request.setCharacterEncoding("utf-8"); 93 String responseURI = null; 95 96 if (IPFilter.filter(request) == false) { 97 getServletContext().getRequestDispatcher("/mvnplugin/mvnforum/404.jsp").forward(request, response); 98 return; 99 } 100 if (UserAgentFilter.filter(request) == false) { 101 getServletContext().getRequestDispatcher("/mvnplugin/mvnforum/404.jsp").forward(request, response); 102 return; 103 } 104 105 responseURI = adminModuleProcessor.process(request, response); 107 if ( (null!=responseURI) && (!response.isCommitted()) ) { 109 if (responseURI.endsWith(".jsp")) { 110 request.getRequestDispatcher(responseURI).forward(request, response); 111 } else { 112 response.sendRedirect(ParamUtil.getContextPath() + responseURI); 113 } 114 } 115 } catch (Exception e) { 116 log.error("Error assertion", e); 118 } finally { 119 if (log.isDebugEnabled()) { 120 long processTime = System.currentTimeMillis() - startTime; 121 log.debug("ForumAdminServlet processed " + count + " times. Took " + processTime + " miliseconds.\n"); 122 } 123 } 124 } 126 129 public void destroy() { 130 DBUtils.closeAllConnections(); 133 134 log.info("<<---- ForumAdminServlet has been destroyed. ---->>"); 135 } 136 } 137 | Popular Tags |