Skip to content

Commit

Permalink
log error on failed startup of servlet context listener.
Browse files Browse the repository at this point in the history
  • Loading branch information
chenson42 committed Jan 7, 2008
1 parent 3c0749e commit f516088
Showing 1 changed file with 25 additions and 22 deletions.
Expand Up @@ -23,6 +23,8 @@
import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
Expand All @@ -47,12 +49,22 @@ public class SymmetricEngineContextLoaderListener extends ContextLoaderListener

static final String SYMMETRIC_SPRING_LOCATION = "classpath:/symmetric.xml";

static final Log logger = LogFactory.getLog(SymmetricEngineContextLoaderListener.class);

@Override
final public void contextInitialized(ServletContextEvent event) {
super.contextInitialized(event);
ApplicationContext ctx = WebApplicationContextUtils
.getWebApplicationContext(event.getServletContext());
createConfigureAndStartEngine(ctx);
try {
super.contextInitialized(event);
ApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(event.getServletContext());
createConfigureAndStartEngine(ctx);
} catch (Exception ex) {
logger.error("Failed to initialize the web server context.", ex);
if (ex instanceof RuntimeException) {
throw (RuntimeException) ex;
} else {
throw new RuntimeException(ex);
}
}
}

protected void createConfigureAndStartEngine(ApplicationContext ctx) {
Expand All @@ -64,36 +76,27 @@ protected void createConfigureAndStartEngine(ApplicationContext ctx) {
protected ContextLoader createContextLoader() {
return new ContextLoader() {
@SuppressWarnings("unchecked")
protected WebApplicationContext createWebApplicationContext(
ServletContext servletContext, ApplicationContext parent)
throws BeansException {
protected WebApplicationContext createWebApplicationContext(ServletContext servletContext,
ApplicationContext parent) throws BeansException {

Class contextClass = determineContextClass(servletContext);
if (!ConfigurableWebApplicationContext.class
.isAssignableFrom(contextClass)) {
throw new ApplicationContextException(
"Custom context class ["
+ contextClass.getName()
+ "] is not of type ConfigurableWebApplicationContext");
if (!ConfigurableWebApplicationContext.class.isAssignableFrom(contextClass)) {
throw new ApplicationContextException("Custom context class [" + contextClass.getName()
+ "] is not of type ConfigurableWebApplicationContext");
}

ConfigurableWebApplicationContext wac = (ConfigurableWebApplicationContext) BeanUtils
.instantiateClass(contextClass);
wac.setParent(parent);
wac.setServletContext(servletContext);
String configLocation = servletContext
.getInitParameter(CONFIG_LOCATION_PARAM);
String configLocation = servletContext.getInitParameter(CONFIG_LOCATION_PARAM);
if (configLocation == null) {
configLocation = SYMMETRIC_SPRING_LOCATION;
} else if (!configLocation.contains(SYMMETRIC_SPRING_LOCATION)) {
configLocation = SYMMETRIC_SPRING_LOCATION + ","
+ configLocation;
configLocation = SYMMETRIC_SPRING_LOCATION + "," + configLocation;
}
wac
.setConfigLocations(StringUtils
.tokenizeToStringArray(
configLocation,
ConfigurableWebApplicationContext.CONFIG_LOCATION_DELIMITERS));
wac.setConfigLocations(StringUtils.tokenizeToStringArray(configLocation,
ConfigurableWebApplicationContext.CONFIG_LOCATION_DELIMITERS));

wac.refresh();
return wac;
Expand Down

0 comments on commit f516088

Please sign in to comment.