ServletContextHooks.java [src/csip] Revision: 71821307bfe742c00c6dc582c171224a9ac59935 Date: Fri Apr 21 11:46:19 MDT 2017
/*
* $Id$
*
* This file is part of the Cloud Services Integration Platform (CSIP),
* a Model-as-a-Service framework, API and application suite.
*
* 2012-2017, Olaf David and others, OMSLab, Colorado State University.
*
* OMSLab licenses this file to you under the MIT license.
* See the LICENSE file in the project root for more information.
*/
package csip;
import java.io.File;
import java.util.logging.Logger;
import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;
/**
* Context Registration.
*
* @author Olaf David
*/
@WebListener
public class ServletContextHooks implements ServletContextListener {
static Logger l = Logger.getLogger(ServletContextHooks.class.getName());
@Override
public void contextInitialized(ServletContextEvent e) {
ServletContext ctx = e.getServletContext();
Config.startup();
ContextConfig cc = new ContextConfig();
// Context internal settings.
cc.load(ctx, "/WEB-INF/csip-defaults.json");
cc.load(ctx, "/META-INF/csip-conf.json"); // deprecated
// Servlet init params.
cc.load(ctx);
// Tomcat/conf folder as <context>.yaml
cc.load(new File(System.getProperty("catalina.home") + File.separatorChar + "conf" + ctx.getContextPath() + ".yaml"));
// webapp folder configuration files
cc.load(ctx, ".json");
cc.load(ctx, ".properties");
cc.load(ctx, ".yaml");
if (!cc.getConfig().isEmpty()) {
ControlService.updateConfig(cc.getConfig());
}
l.info("CSIP Context Created: " + ctx.getContextPath());
}
@Override
public void contextDestroyed(ServletContextEvent e) {
Config.shutdown();
l.info("CSIP Context Destroyed: " + e.getServletContext().getContextPath());
}
}