uoa-repository-manager-service/src/main/java/eu/dnetlib/repo/manager/config/RepoManagerContextLoaderLis...

105 lines
3.8 KiB
Java

package eu.dnetlib.repo.manager.config;
import org.apache.commons.lang.ArrayUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.BeansException;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.web.context.ContextLoaderListener;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.XmlWebApplicationContext;
import javax.servlet.ServletContext;
import java.util.Properties;
public class RepoManagerContextLoaderListener extends ContextLoaderListener {
private static Logger logger = Logger.getLogger(RepoManagerContextLoaderListener.class);
public RepoManagerContextLoaderListener() {
super();
}
public RepoManagerContextLoaderListener(WebApplicationContext context) {
super(context);
}
@Override
protected WebApplicationContext createWebApplicationContext(
ServletContext servletContext)
throws BeansException {
logger.debug("Creating web application context");
Properties props = this.loadProperties();
String repoMode = props.getProperty("services.validator.mode.repo");
String userMode = props.getProperty("services.validator.mode.user");
Boolean standaloneMode = Boolean.parseBoolean(props.getProperty("services.validator.mode.standalone"));
logger.info("User mode: " + userMode);
logger.info("Repo mode: " + repoMode);
logger.info("Standalone mode: " + standaloneMode);
XmlWebApplicationContext ctx = new XmlWebApplicationContext();
ctx.setServletContext(servletContext);
String userApiContext = null;
if (userMode.equalsIgnoreCase("local"))
userApiContext = "eu/dnetlib/validator/web/api/impls/users/springContext-validator-user-local.xml";
else if (userMode.equalsIgnoreCase("ldap"))
userApiContext = "eu/dnetlib/users/springContext-users-ldap.xml";
String[] springContextCore = new String[] {
"classpath:META-INF/cxf/cxf.xml",
"classpath:META-INF/cxf/cxf-extension-soap.xml",
"classpath:META-INF/cxf/cxf-extension-jaxws.xml",
"classpath:META-INF/cxf/cxf-servlet.xml",
"classpath*:/cxf.xml",
"classpath*:/eu/dnetlib/repos/ehcacher/springContext-repos-ehcacher.xml",
"classpath*:/eu/dnetlib/clients/ws/springContext-locatorFactory.xml",
"classpath*:/eu/dnetlib/soap/cxf/applicationContext-eprbuilders.xml",
"classpath*:/eu/dnetlib/repo/manager/server/config/springContext-repo-manager-config.xml",
"classpath*:/eu/dnetlib/repos/springContext-repos-" + repoMode + ".xml",
"classpath*:/" + userApiContext
};
String[] springContextForStandalone = new String[] {
};
String[] springContextForIS = new String[] {
"classpath*:/gr/uoa/di/driver/util/springContext-locators.xml",
"classpath*:/gr/uoa/di/driver/app/springContext-lookupFactory.xml",
"classpath*:/gr/uoa/di/driver/app/springContext-lookupClients.xml",
"classpath*:/eu/dnetlib/enabling/hcm/springContext-hcmService.xml",
"classpath*:/gr/uoa/di/driver/app/springContext-commons.xml",
"classpath*:/gr/uoa/di/driver/app/springContext-registrator.xml"
};
if (standaloneMode) {
logger.debug("Loading contexts for standalone mode");
ctx.setConfigLocations((String[])ArrayUtils.addAll(springContextCore,springContextForStandalone));
} else {
logger.debug("Loading contexts for dnet");
ctx.setConfigLocations((String[])ArrayUtils.addAll(springContextCore,springContextForIS));
}
ctx.refresh();
logger.debug("done");
return ctx;
}
private Properties loadProperties() {
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(new String[] {
"classpath*:/eu/dnetlib/repo/manager/server/config/springContext-repo-manager-config.xml"
});
CascadingPropertyLoader pLoader = (CascadingPropertyLoader) ctx.getBean("propertyLoader");
Properties props = pLoader.getProperties();
ctx.destroy();
ctx.close();
return props;
}
}