1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.bitrepository.webservice;
23
24 import javax.servlet.ServletContextEvent;
25 import javax.servlet.ServletContextListener;
26
27 import org.bitrepository.BasicClient;
28 import org.bitrepository.BasicClientFactory;
29 import org.bitrepository.utils.LogbackConfigLoader;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
32
33
34
35
36
37
38
39
40 public class WebclientContextListener implements ServletContextListener {
41 private final Logger log = LoggerFactory.getLogger(getClass());
42
43
44
45
46 @SuppressWarnings("unused")
47 @Override
48 public void contextInitialized(ServletContextEvent sce) {
49 String confDir = sce.getServletContext().getInitParameter("configurationDir");
50 if(confDir == null) {
51 throw new RuntimeException("No configuration directory specified!");
52 }
53 log.debug("Configuration dir = " + confDir);
54 try {
55 new LogbackConfigLoader(confDir + "/logback.xml");
56 } catch (Exception e) {
57 log.info("Failed to read log configuration file. Falling back to default.");
58 }
59 BasicClientFactory.init(confDir);
60 BasicClient client = BasicClientFactory.getInstance();
61 log.debug("Servlet context initialized");
62 }
63
64
65
66
67
68 @Override
69 public void contextDestroyed(ServletContextEvent sce) {
70 BasicClient client = BasicClientFactory.getInstance();
71 client.shutdown();
72 log.debug("Servlet context destroyed");
73 }
74 }