| @@ -5,6 +5,7 @@ import java.io.FileInputStream; | |||
| import java.io.FileNotFoundException; | |||
| import java.io.IOException; | |||
| import java.io.PrintWriter; | |||
| import java.util.Enumeration; | |||
| import java.util.HashMap; | |||
| import java.util.Map; | |||
| import java.util.Properties; | |||
| @@ -83,6 +84,9 @@ public abstract class CommEngine extends HttpServlet | |||
| private int postbackMaxBatchSize; | |||
| protected String runtimeDirPath; | |||
| protected String confDirPath; | |||
| abstract protected Broadcast mkBroadcast(); | |||
| public CommEngine(String engineName) | |||
| @@ -100,22 +104,36 @@ public abstract class CommEngine extends HttpServlet | |||
| { | |||
| // check init parameters | |||
| ServletContext servletContext = getServletContext(); | |||
| String propertiesFilePath; | |||
| propertiesFilePath = servletContext.getInitParameter(getPropertiesContextName()); | |||
| File propertiesFile = new File(propertiesFilePath); | |||
| 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 = propertiesFile.getParent() + "/log4j.properties"; | |||
| String log4j_properties = confDirPath + "/log4j.properties"; | |||
| // Relocate file property offetting it by the runtimeDirPath | |||
| try | |||
| { | |||
| PropertyConfigurator.configure(log4j_properties); | |||
| 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. | |||
| @@ -203,7 +221,9 @@ public abstract class CommEngine extends HttpServlet | |||
| * @return name of parameter in Tomcat context file, specifying properties file | |||
| * for this SMSEngine. | |||
| */ | |||
| protected abstract String getPropertiesContextName(); | |||
| protected abstract String getConfDirContextName(); | |||
| protected abstract String getRunTimeDirContextName(); | |||
| @Override | |||
| protected void doPost(HttpServletRequest request, HttpServletResponse response) | |||