/[projects]/dao/DaoAdresseVedligehold/src/main/java/dk/daoas/adressevedligehold/ContextListener.java
ViewVC logotype

Annotation of /dao/DaoAdresseVedligehold/src/main/java/dk/daoas/adressevedligehold/ContextListener.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2948 - (hide annotations) (download)
Sat Feb 13 15:56:00 2016 UTC (8 years, 3 months ago) by torben
File size: 2830 byte(s)
cleanup
1 torben 2878 package dk.daoas.adressevedligehold;
2    
3 torben 2903 /*
4     * Denne Serivce bruger log4j og det kræver at tomcat leder efter log4j
5     * Tomcat 7 <7.0.43 ignores all JAR files named log4j*.jar, which prevents this feature from working.
6     * This has been fixed in Tomcat 7.0.43, Tomcat 8, and later.
7     * In Tomcat 7 <7.0.43 you will need to change catalina.properties and remove "log4j*.jar" from the jarsToSkip property.
8     * You may need to do something similar on other containers if they skip scanning Log4j JAR files.
9     *
10     */
11 torben 2878
12     import java.io.FileInputStream;
13     import java.io.IOException;
14     import java.io.InputStreamReader;
15     import java.io.Reader;
16     import java.nio.charset.Charset;
17     import java.util.Properties;
18    
19     import javax.servlet.ServletContext;
20     import javax.servlet.ServletContextEvent;
21     import javax.servlet.ServletContextListener;
22     import javax.servlet.ServletRegistration;
23     import javax.servlet.annotation.WebListener;
24    
25     import org.apache.commons.lang3.SystemUtils;
26    
27     import dk.thoerup.webconfig.ConfigServlet;
28     import dk.thoerup.webconfig.PropertiesConfigLoader;
29    
30     /**
31     * Application Lifecycle Listener implementation class ContextListener
32     *
33     */
34     @WebListener
35     public class ContextListener implements ServletContextListener {
36    
37    
38    
39     public void contextDestroyed(ServletContextEvent ctxtEvt) {
40     // TODO Auto-generated method stub
41     }
42    
43     @Override
44     public void contextInitialized(ServletContextEvent ctxtEvt) {
45     System.out.println("Starting DAO Context");
46    
47    
48    
49     ServletContext ctxt = ctxtEvt.getServletContext();
50    
51     try {
52     initConfig(ctxt);
53     } catch (IOException e) {
54     System.out.println("Error loading config " + e.getMessage());
55     throw new RuntimeException(e);
56     }
57    
58    
59     System.out.println("DAO Context done");
60     }
61    
62    
63    
64    
65     private ServiceConfig initConfig(ServletContext ctxt) throws IOException {
66    
67     final String CONF_FILE_NAME = "daoadressevedligehold.conf";
68    
69    
70     ServiceConfig conf = ServiceConfig.getInstance();
71    
72     String file = null;
73     if (SystemUtils.IS_OS_WINDOWS) {
74     file = "C:\\" + CONF_FILE_NAME;
75     } else {
76     file = "/etc/" + CONF_FILE_NAME;
77     }
78    
79     Properties propsFile = new Properties();
80     try ( Reader reader = new InputStreamReader(new FileInputStream(file), Charset.forName("UTF-8")) ) {
81     propsFile.load(reader);
82     }
83    
84    
85     new PropertiesConfigLoader(propsFile).loadConfig(conf);
86    
87    
88     ctxt.setAttribute("config", conf);
89    
90     // /////////////////////////////////////
91     ConfigServlet servlet = new ConfigServlet();
92     servlet.setConfigObject( conf );
93     ServletRegistration.Dynamic dynconf = ctxt.addServlet("webconfig", servlet );
94     dynconf.addMapping("/ConfigServlet");
95    
96     return conf;
97     }
98    
99    
100     }

  ViewVC Help
Powered by ViewVC 1.1.20