1
|
package eu.dnetlib.repo.manager.config;
|
2
|
|
3
|
import org.apache.commons.lang.ArrayUtils;
|
4
|
import org.apache.log4j.Logger;
|
5
|
import org.springframework.beans.BeansException;
|
6
|
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
7
|
import org.springframework.web.context.ContextLoaderListener;
|
8
|
import org.springframework.web.context.WebApplicationContext;
|
9
|
import org.springframework.web.context.support.XmlWebApplicationContext;
|
10
|
|
11
|
import javax.servlet.ServletContext;
|
12
|
import java.util.Properties;
|
13
|
|
14
|
public class RepoManagerContextLoaderListener extends ContextLoaderListener {
|
15
|
private static Logger logger = Logger.getLogger(RepoManagerContextLoaderListener.class);
|
16
|
|
17
|
|
18
|
public RepoManagerContextLoaderListener() {
|
19
|
super();
|
20
|
}
|
21
|
|
22
|
public RepoManagerContextLoaderListener(WebApplicationContext context) {
|
23
|
super(context);
|
24
|
}
|
25
|
|
26
|
@Override
|
27
|
protected WebApplicationContext createWebApplicationContext(
|
28
|
ServletContext servletContext)
|
29
|
throws BeansException {
|
30
|
logger.debug("Creating web application context");
|
31
|
Properties props = this.loadProperties();
|
32
|
String repoMode = props.getProperty("services.validator.mode.repo");
|
33
|
String userMode = props.getProperty("services.validator.mode.user");
|
34
|
Boolean standaloneMode = Boolean.parseBoolean(props.getProperty("services.validator.mode.standalone"));
|
35
|
|
36
|
logger.info("User mode: " + userMode);
|
37
|
logger.info("Repo mode: " + repoMode);
|
38
|
logger.info("Standalone mode: " + standaloneMode);
|
39
|
// logger.info("Dnet workflow enabled: " + repoMode);
|
40
|
XmlWebApplicationContext ctx = new XmlWebApplicationContext();
|
41
|
|
42
|
ctx.setServletContext(servletContext);
|
43
|
|
44
|
String userApiContext = null;
|
45
|
if (userMode.equalsIgnoreCase("local"))
|
46
|
userApiContext = "eu/dnetlib/validator/web/api/impls/users/springContext-validator-user-local.xml";
|
47
|
else if (userMode.equalsIgnoreCase("ldap"))
|
48
|
userApiContext = "eu/dnetlib/users/springContext-users-ldap.xml";
|
49
|
|
50
|
String[] springContextCore = new String[] {
|
51
|
"classpath:META-INF/cxf/cxf.xml",
|
52
|
"classpath:META-INF/cxf/cxf-extension-soap.xml",
|
53
|
"classpath:META-INF/cxf/cxf-extension-jaxws.xml",
|
54
|
"classpath:META-INF/cxf/cxf-servlet.xml",
|
55
|
"classpath*:/cxf.xml",
|
56
|
"classpath*:/eu/dnetlib/repos/ehcacher/springContext-repos-ehcacher.xml",
|
57
|
"classpath*:/eu/dnetlib/clients/ws/springContext-locatorFactory.xml",
|
58
|
"classpath*:/eu/dnetlib/soap/cxf/applicationContext-eprbuilders.xml",
|
59
|
// "classpath*:/eu/dnetlib/validator/web/actions/springContext-validator-struts.xml",
|
60
|
// "classpath*:/eu/dnetlib/validator/web/actions/springContext-validator-emailer.xml",
|
61
|
// "classpath*:/eu/dnetlib/validator/web/config/springContext-validator.xml",
|
62
|
"classpath*:/eu/dnetlib/repo/manager/server/config/springContext-repo-manager-config.xml",
|
63
|
// "classpath*:/eu/dnetlib/validator/commons/dao/springContext-*.xml",
|
64
|
"classpath*:/eu/dnetlib/repos/springContext-repos-" + repoMode + ".xml",
|
65
|
"classpath*:/" + userApiContext
|
66
|
};
|
67
|
|
68
|
|
69
|
String[] springContextForStandalone = new String[] {
|
70
|
};
|
71
|
|
72
|
String[] springContextForIS = new String[] {
|
73
|
"classpath*:/gr/uoa/di/driver/util/springContext-locators.xml",
|
74
|
"classpath*:/gr/uoa/di/driver/app/springContext-lookupFactory.xml",
|
75
|
"classpath*:/gr/uoa/di/driver/app/springContext-lookupClients.xml",
|
76
|
"classpath*:/eu/dnetlib/enabling/hcm/springContext-hcmService.xml",
|
77
|
"classpath*:/gr/uoa/di/driver/app/springContext-commons.xml",
|
78
|
"classpath*:/gr/uoa/di/driver/app/springContext-registrator.xml"
|
79
|
};
|
80
|
|
81
|
if (standaloneMode) {
|
82
|
logger.debug("Loading contexts for standalone mode");
|
83
|
ctx.setConfigLocations((String[])ArrayUtils.addAll(springContextCore,springContextForStandalone));
|
84
|
} else {
|
85
|
logger.debug("Loading contexts for dnet");
|
86
|
ctx.setConfigLocations((String[])ArrayUtils.addAll(springContextCore,springContextForIS));
|
87
|
}
|
88
|
|
89
|
ctx.refresh();
|
90
|
|
91
|
logger.debug("done");
|
92
|
|
93
|
return ctx;
|
94
|
}
|
95
|
|
96
|
private Properties loadProperties() {
|
97
|
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(new String[] {
|
98
|
"classpath*:/eu/dnetlib/repo/manager/server/config/springContext-repo-manager-config.xml"
|
99
|
});
|
100
|
|
101
|
CascadingPropertyLoader pLoader = (CascadingPropertyLoader) ctx.getBean("propertyLoader");
|
102
|
Properties props = pLoader.getProperties();
|
103
|
|
104
|
ctx.destroy();
|
105
|
ctx.close();
|
106
|
return props;
|
107
|
}
|
108
|
|
109
|
}
|