ソースを参照

merged with master

tags/CommEngine-0.0.1
Yiu Leung 6年前
コミット
2f2bfa5403
1個のファイルの変更44行の追加24行の削除
  1. +44
    -24
      src/main/java/altk/comm/engine/CommEngine.java

+ 44
- 24
src/main/java/altk/comm/engine/CommEngine.java ファイルの表示

@@ -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,37 +104,51 @@ public abstract class CommEngine extends HttpServlet
{
// check init parameters
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
// is not yet configured,
// it will look for the log4j.properties file in the class path.
myLogger = Logger.getLogger(CommEngine.class);
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());
config = new Properties();
try
@@ -207,7 +225,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)


読み込み中…
キャンセル
保存