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