1 64 package com.jcorporate.expresso.core.servlet; 65 66 import com.jcorporate.expresso.core.misc.ConfigManager; 67 import com.jcorporate.expresso.core.misc.StringUtil; 68 import com.jcorporate.expresso.core.misc.SystemMacros; 69 import com.jcorporate.expresso.kernel.RootContainerInterface; 70 import com.jcorporate.expresso.kernel.SystemFactory; 71 import com.jcorporate.expresso.kernel.exception.ConfigurationException; 72 import org.apache.log4j.Logger; 73 74 import javax.servlet.ServletConfig ; 75 import javax.servlet.ServletContext ; 76 import javax.servlet.ServletException ; 77 import javax.servlet.http.HttpServlet ; 78 79 86 public class RuntimeInitServlet extends HttpServlet { 87 88 91 private String loggingDirectory; 92 93 96 private String expressoServicesConfig; 97 98 101 private String loggingConfig; 102 103 106 private Logger log; 107 108 111 private RootContainerInterface root; 112 113 public RuntimeInitServlet() { 114 } 115 116 123 public void init(ServletConfig sc) throws javax.servlet.ServletException { 124 super.init(sc); 125 126 try { 127 initializeSystemMacros(sc); 128 long startTime = System.currentTimeMillis(); 129 loggingDirectory = sc.getInitParameter(ConfigManager.LOG_DIR_PARAM_NAME); 130 expressoServicesConfig = sc.getInitParameter("expressoConfig"); 131 loggingConfig = sc.getInitParameter("loggingConfig"); 132 root = SystemFactory.buildExpressoComponentSystem(expressoServicesConfig, 133 loggingConfig, loggingDirectory); 134 135 log = Logger.getLogger(RuntimeInitServlet.class); 136 long endTime = System.currentTimeMillis(); 137 log.info("Completed initialization in " + (endTime - startTime) / 1000 + " seconds"); 138 } catch (ConfigurationException ex) { 139 this.log("Error loading Expresso Configuration", ex); 140 throw new ServletException ("Error loading Expresso Configuration", ex); 141 } 142 } 143 144 151 public void initializeSystemMacros(ServletConfig c) { 152 ServletContext sc = c.getServletContext(); 153 String rootDir = StringUtil.notNull(sc.getRealPath("/")); 154 155 this.log("ConfigManager: Context root (webAppDir) is '" + 156 rootDir + "'"); 157 158 SystemMacros sm = SystemMacros.getInstance(); 159 if (rootDir.equals("")) { 160 this.log("Deploying inside a packed war file. Relative File URLs will throw Exceptions"); 161 rootDir = System.getProperty("expresso.home", ""); 162 if (rootDir.length() == 0) { 163 log.warn("Deployed inside WAR file and no expresso.home " + 164 "directory set. %WEB-APP% will expand to null"); 165 } else { 166 sm.setWebAppDir(rootDir); 167 } 168 } else { 169 sm.setWebAppDir(rootDir); 170 } 171 172 sm.setContextPath(this.getServletContext().getServletContextName()); 173 } 174 175 178 public void destroy() { 179 if (log != null) { 180 log.info("Destroying Global Runtime Container"); 181 } 182 183 if (root != null) { 184 root.destroy(); 185 } 186 } 187 188 189 } | Popular Tags |