001: package org.nemesis.forum.config;
002:
003: import java.io.File;
004:
005: import javax.servlet.ServletContext;
006: import javax.servlet.http.HttpServlet;
007: import javax.servlet.http.HttpServletRequest;
008: import javax.servlet.http.HttpServletResponse;
009:
010: import org.apache.commons.logging.Log;
011: import org.apache.commons.logging.LogFactory;
012:
013: public class InitServlet extends HttpServlet {
014:
015: private static Log log = LogFactory.getLog(InitServlet.class);
016:
017: public static String DATA_PATH;
018:
019: /**
020: * la servlet doit etre configuré dans le web.xml pour etre chargée au demarage du container de servlet<br>
021: *
022: *
023: * */
024: public void init() {
025: log.info("--------INIT START-------------");
026:
027: if (getServletConfig().getInitParameter("dataPath") != null) {
028: DATA_PATH = getServletConfig().getInitParameter("dataPath");
029: } else {//relative
030: String realPath = getServletContext().getRealPath("");
031: if (realPath == null) {
032: System.err
033: .println("your system doesn't support getServletContext().getRealPath() method, set absolute path in your web.xml");
034: log
035: .fatal("your system doesn't support getServletContext().getRealPath() method, set absolute path in your web.xml");
036: System.exit(1);
037: }
038: DATA_PATH = realPath + File.separator + "WEB-INF"
039: + File.separator + "nemesis-data";
040: }
041:
042: //---------------- P6spy -------------
043: ServletContext context = this .getServletConfig()
044: .getServletContext();
045:
046: String jcp = System.getProperty("java.class.path");
047:
048: // System.setProperty(
049: // "java.class.path",
050: // jcp
051: // + System.getProperty("path.separator")
052: // + context.getRealPath("WEB-INF/lib/p6spy.jar")
053: // + System.getProperty("path.separator")
054: // + context.getRealPath("WEB-INF/classes/"));
055: //
056: log.info("System classpath :\n"
057: + System.getProperty("java.class.path"));
058:
059: //------------------------------------
060:
061: String encoding = System.getProperty("file.encoding");
062: //System.setProperty("file.encoding","ISO-8859-1");
063:
064: log.info("System file.encoding :" + encoding);
065: //------------------------------------
066:
067: //parfois besoin d'un repertoire temporaire
068: String tempdir = System.getProperty("java.io.tmpdir");
069:
070: log.info("System TEMP DIR :" + tempdir);
071: //------------------------------------
072:
073: //lancement du serveur hypersonic en mode serveur, a desactivé en production-->standalone
074: // String launchHSQLDB = getServletConfig().getInitParameter("launchHSQLDB");
075: // if("true".equals(launchHSQLDB)){
076: // try {
077: //
078: // Thread t=(new Thread( ){
079: // public void run(){
080: // try {
081: // Server hsql = new Server();
082: // hsql.main(
083: // new String[]{
084: // "-port","9001",
085: // "-silent","true",
086: // "-database",DATA_PATH+"/db/nemesis"
087: // }
088: // );
089: // } catch (Exception e) {
090: // log.fatal("hypersonic launch failed",e);
091: // }
092: // }
093: // });
094: // t.setDaemon(true);
095: // t.start();
096: // log.info("hypersonic ok");
097: //
098: // } catch (Throwable e) {
099: // log.fatal("hypersonic launch failed",e);
100: // }
101: // }
102: log.info("--------INIT END-------------");
103:
104: }
105:
106: public void doService(HttpServletRequest req,
107: HttpServletResponse res) {
108: return;
109: }
110:
111: /* (non-Javadoc)
112: * @see javax.servlet.Servlet#destroy()
113: */
114: public void destroy() {
115: super.destroy();
116:
117: }
118:
119: }
|