View Javadoc
1   /**
2    * Copyright 2005-2016 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package edu.sampleu.travel.infrastructure;
17  
18  import java.io.FileNotFoundException;
19  
20  import javax.servlet.ServletContextEvent;
21  import javax.servlet.ServletContextListener;
22  
23  import org.apache.log4j.Logger;
24  import org.springframework.util.Log4jConfigurer;
25  
26  /**
27   * A ServletContextListener that fires up the Spring context.
28   * This is used instead of a standard ContextLoaderListener in order to load
29   * an extra test context if running in unit tests. 
30   * 
31   * @author Kuali Rice Team (rice.collab@kuali.org)
32   */
33  public class TravelAppInitializeListener implements ServletContextListener {
34      private static final Logger LOG = Logger.getLogger(TravelAppInitializeListener.class);
35  
36  	public void contextDestroyed(ServletContextEvent sce) {
37  
38  	}
39  
40  	public void contextInitialized(ServletContextEvent sce) {
41      	try {
42  		    Log4jConfigurer.initLogging("classpath:log4j.properties");
43  		} catch (FileNotFoundException e) {
44  		    throw new RuntimeException("Failed to start sample application.", e);
45  		}
46  
47  		Object o = sce.getServletContext().getAttribute("JETTYSERVER_TESTMODE");
48  		boolean testMode = false;
49  		if (o != null) {
50  		    testMode = Boolean.valueOf((String) o);
51  		}
52  		LOG.info("Travel webapp starting up in " + (testMode ? "test" : "normal") + " mode");
53  		// this loads up the Spring context
54  		TravelServiceLocator.initialize(testMode);
55  	}
56  }