1 16 package org.directwebremoting.impl; 17 18 import javax.servlet.ServletConfig ; 19 import javax.servlet.ServletContext ; 20 import javax.servlet.ServletException ; 21 import javax.servlet.http.HttpServlet ; 22 23 import org.directwebremoting.Container; 24 import org.directwebremoting.ServerContextFactory; 25 import org.directwebremoting.WebContextFactory; 26 import org.directwebremoting.ServerContextFactory.ServerContextBuilder; 27 import org.directwebremoting.WebContextFactory.WebContextBuilder; 28 import org.directwebremoting.util.FakeServletConfig; 29 import org.directwebremoting.util.FakeServletContext; 30 import org.directwebremoting.util.Logger; 31 import org.directwebremoting.util.ServletLoggingOutput; 32 import org.directwebremoting.util.VersionUtil; 33 34 38 public class StartupUtil 39 { 40 48 public Container outOfContainerInit() throws ServletException 49 { 50 try 51 { 52 ServletConfig servletConfig = new FakeServletConfig("test", new FakeServletContext()); 53 ServletContext servletContext = servletConfig.getServletContext(); 54 55 StartupUtil.setupLogging(servletConfig, null); 56 StartupUtil.logStartup(servletConfig); 57 58 DefaultContainer container = ContainerUtil.createDefaultContainer(servletConfig); 59 ContainerUtil.setupDefaultContainer(container, servletConfig); 60 61 WebContextBuilder webContextBuilder = StartupUtil.initWebContext(servletConfig, servletContext, container); 62 StartupUtil.initServerContext(servletConfig, servletContext, container); 63 64 ContainerUtil.prepareForWebContextFilter(servletContext, servletConfig, container, webContextBuilder, null); 65 ContainerUtil.configureContainerFully(container, servletConfig); 66 ContainerUtil.publishContainer(container, servletConfig); 67 68 return container; 69 } 70 catch (ServletException ex) 71 { 72 throw ex; 73 } 74 catch (Exception ex) 75 { 76 throw new ServletException (ex); 77 } 78 } 79 80 85 public void outOfContainerDestroy(Container container) 86 { 87 ServletLoggingOutput.unsetExecutionContext(); 88 89 WebContextBuilder webContextBuilder = (WebContextBuilder) container.getBean(WebContextBuilder.class.getName()); 90 if (webContextBuilder != null) 91 { 92 webContextBuilder.unset(); 93 } 94 } 95 96 100 public static void logStartup(ServletConfig config) 101 { 102 log.info("DWR Version " + VersionUtil.getVersion() + " starting."); 103 log.info("- Servlet Engine: " + config.getServletContext().getServerInfo()); 104 log.info("- Java Version: " + System.getProperty("java.version")); 105 log.info("- Java Vendor: " + System.getProperty("java.vendor")); 106 } 107 108 118 public static WebContextBuilder initWebContext(ServletConfig servletConfig, ServletContext servletContext, Container container) 119 { 120 WebContextBuilder webContextBuilder = (WebContextBuilder) container.getBean(WebContextBuilder.class.getName()); 121 WebContextFactory.setWebContextBuilder(webContextBuilder); 122 webContextBuilder.set(null, null, servletConfig, servletContext, container); 123 124 return webContextBuilder; 125 } 126 127 136 public static ServerContextBuilder initServerContext(ServletConfig servletConfig, ServletContext servletContext, Container container) 137 { 138 ServerContextBuilder serverContextBuilder = (ServerContextBuilder) container.getBean(ServerContextBuilder.class.getName()); 139 ServerContextFactory.setServerContextBuilder(serverContextBuilder); 140 serverContextBuilder.set(servletConfig, servletContext, container); 141 142 return serverContextBuilder; 143 } 144 145 151 public static void setupLogging(ServletConfig servletConfig, HttpServlet servlet) 152 { 153 ServletLoggingOutput.setExecutionContext(servlet); 154 String logLevel = servletConfig.getInitParameter(ContainerUtil.INIT_LOGLEVEL); 155 if (logLevel != null) 156 { 157 ServletLoggingOutput.setLevel(logLevel); 158 } 159 } 160 161 164 private static final Logger log = Logger.getLogger(StartupUtil.class); 165 } 166 | Popular Tags |