View Javadoc

1   /*
2    * Copyright 2007 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.kuali.rice.core.web.jetty.JettyServer;
25  import org.springframework.util.Log4jConfigurer;
26  
27  import uk.ltd.getahead.dwr.util.LoggingOutput;
28  
29  /**
30   * A ServletContextListener that fires up the Spring context.
31   * This is used instead of a standard ContextLoaderListener in order to load
32   * an extra test context if running in unit tests. 
33   * 
34   * @author Kuali Rice Team (rice.collab@kuali.org)
35   */
36  public class TravelAppInitializeListener implements ServletContextListener {
37      private static final Logger LOG = Logger.getLogger(TravelAppInitializeListener.class);
38  
39  	public void contextDestroyed(ServletContextEvent sce) {
40  
41  	}
42  
43  	public void contextInitialized(ServletContextEvent sce) {
44      	try {
45  		    Log4jConfigurer.initLogging("classpath:log4j.properties");
46  		} catch (FileNotFoundException e) {
47  		    throw new RuntimeException("Failed to start sample application.", e);
48  		}
49  
50  		Object o = sce.getServletContext().getAttribute(JettyServer.JETTYSERVER_TESTMODE_ATTRIB);
51  		boolean testMode = false;
52  		if (o != null) {
53  		    testMode = Boolean.valueOf((String) o);
54  		}
55  		LOG.info("Travel webapp starting up in " + (testMode ? "test" : "normal") + " mode");
56  		// this loads up the Spring context
57  		TravelServiceLocator.initialize(testMode);
58  	}
59  }