| @@ -5,6 +5,7 @@ import java.io.FileInputStream; | |||||
| import java.io.FileNotFoundException; | import java.io.FileNotFoundException; | ||||
| import java.io.IOException; | import java.io.IOException; | ||||
| import java.io.PrintWriter; | import java.io.PrintWriter; | ||||
| import java.util.Enumeration; | |||||
| import java.util.HashMap; | import java.util.HashMap; | ||||
| import java.util.Map; | import java.util.Map; | ||||
| import java.util.Properties; | import java.util.Properties; | ||||
| @@ -83,6 +84,9 @@ public abstract class CommEngine extends HttpServlet | |||||
| private int postbackMaxBatchSize; | private int postbackMaxBatchSize; | ||||
| protected String runtimeDirPath; | |||||
| protected String confDirPath; | |||||
| abstract protected Broadcast mkBroadcast(); | abstract protected Broadcast mkBroadcast(); | ||||
| public CommEngine(String engineName) | public CommEngine(String engineName) | ||||
| @@ -100,37 +104,51 @@ public abstract class CommEngine extends HttpServlet | |||||
| { | { | ||||
| // check init parameters | // check init parameters | ||||
| ServletContext servletContext = getServletContext(); | ServletContext servletContext = getServletContext(); | ||||
| String propertiesFilePath; | |||||
| // propertiesFilePath = servletContext.getInitParameter(getPropertiesContextName()); | |||||
| // File propertiesFile = new File(propertiesFilePath); | |||||
| // | |||||
| // // Configure log4j using log4j.properties file, \ | |||||
| // // sibling to the engine properties file. | |||||
| // // This change is backward compatible with placing the log4j.properties file in | |||||
| // // the class path. | |||||
| // String log4j_properties = propertiesFile.getParent() + "/log4j.properties"; | |||||
| // try | |||||
| // { | |||||
| // PropertyConfigurator.configure(log4j_properties); | |||||
| // } | |||||
| // catch (Exception e) | |||||
| // { | |||||
| // // Do nothing, assuming the exception is FileNotFoundException. | |||||
| // // Remaining log4j initialization will look for log4j.properties | |||||
| // // file in the class path. | |||||
| // } | |||||
| confDirPath = servletContext.getInitParameter(getConfDirContextName()); | |||||
| runtimeDirPath = servletContext.getInitParameter(getRunTimeDirContextName()); | |||||
| File propertiesFile = new File(confDirPath + "/properties"); | |||||
| // Configure log4j using log4j.properties file, \ | |||||
| // sibling to the engine properties file. | |||||
| // This change is backward compatible with placing the log4j.properties file in | |||||
| // the class path. | |||||
| String log4j_properties = confDirPath + "/log4j.properties"; | |||||
| // Relocate file property offetting it by the runtimeDirPath | |||||
| try | |||||
| { | |||||
| Properties prop = new Properties(); | |||||
| prop.load(new FileInputStream(log4j_properties)); | |||||
| Enumeration<Object> e = prop.keys(); | |||||
| while (e.hasMoreElements()) | |||||
| { | |||||
| String key = (String)e.nextElement(); | |||||
| if (key.toLowerCase().endsWith(".file")) | |||||
| { | |||||
| prop.setProperty(key, runtimeDirPath + "/" + prop.getProperty(key)); | |||||
| System.out.println(key + "=" + prop.getProperty(key)); | |||||
| } | |||||
| } | |||||
| PropertyConfigurator.configure(prop); | |||||
| } | |||||
| catch (Exception e) | |||||
| { | |||||
| System.out.println("Failed to configure log4: " + e); | |||||
| // Do nothing, assuming the exception is FileNotFoundException. | |||||
| // Remaining log4j initialization will look for log4j.properties | |||||
| // file in the class path. | |||||
| } | |||||
| // This activates Logger class instantiation. At this point, if lo4j | // This activates Logger class instantiation. At this point, if lo4j | ||||
| // is not yet configured, | // is not yet configured, | ||||
| // it will look for the log4j.properties file in the class path. | // it will look for the log4j.properties file in the class path. | ||||
| myLogger = Logger.getLogger(CommEngine.class); | myLogger = Logger.getLogger(CommEngine.class); | ||||
| myLogger.info("init() invoked"); | myLogger.info("init() invoked"); | ||||
| File propertiesFile = new File( | |||||
| getClass().getClassLoader().getResource("properties").getFile() | |||||
| ); | |||||
| // File propertiesFile = new File( | |||||
| // getClass().getClassLoader().getResource("properties").getFile() | |||||
| // ); | |||||
| // CommonLogger.startup.info("Using lo4j properites file " + log4j_properties); | |||||
| CommonLogger.startup.info("Using lo4j properites file " + log4j_properties); | |||||
| CommonLogger.startup.info("Using configuration file " + propertiesFile.getAbsolutePath()); | CommonLogger.startup.info("Using configuration file " + propertiesFile.getAbsolutePath()); | ||||
| config = new Properties(); | config = new Properties(); | ||||
| try | try | ||||
| @@ -207,7 +225,9 @@ public abstract class CommEngine extends HttpServlet | |||||
| * @return name of parameter in Tomcat context file, specifying properties file | * @return name of parameter in Tomcat context file, specifying properties file | ||||
| * for this SMSEngine. | * for this SMSEngine. | ||||
| */ | */ | ||||
| protected abstract String getPropertiesContextName(); | |||||
| protected abstract String getConfDirContextName(); | |||||
| protected abstract String getRunTimeDirContextName(); | |||||
| @Override | @Override | ||||
| protected void doPost(HttpServletRequest request, HttpServletResponse response) | protected void doPost(HttpServletRequest request, HttpServletResponse response) | ||||