use of org.directwebremoting.util.FakeServletConfig in project ma-core-public by infiniteautomation.
the class StartupUtil method outOfContainerInit.
/**
* A way to setup DWR outside of any Containers.
* This method can also serve as a template for in container code wanting
* to get DWR setup. Callers of this method should clean up after themselves
* by calling {@link #outOfContainerDestroy(Container)}
* @return A new initialized container.
* @throws ServletException If the setup fails.
*/
public Container outOfContainerInit() throws ServletException {
try {
ServletConfig servletConfig = new FakeServletConfig("test", new FakeServletContext());
ServletContext servletContext = servletConfig.getServletContext();
StartupUtil.setupLogging(servletConfig, null);
StartupUtil.logStartup(servletConfig);
DefaultContainer container = ContainerUtil.createDefaultContainer(servletConfig);
ContainerUtil.setupDefaultContainer(container, servletConfig);
WebContextBuilder webContextBuilder = StartupUtil.initWebContext(servletConfig, servletContext, container);
StartupUtil.initServerContext(servletConfig, servletContext, container);
ContainerUtil.prepareForWebContextFilter(servletContext, servletConfig, container, webContextBuilder, null);
ContainerUtil.configureContainerFully(container, servletConfig);
ContainerUtil.publishContainer(container, servletConfig);
return container;
} catch (ServletException ex) {
throw ex;
} catch (Exception ex) {
throw new ServletException(ex);
}
}
use of org.directwebremoting.util.FakeServletConfig in project ma-core-public by infiniteautomation.
the class DwrController method afterPropertiesSet.
/**
* Is called by the Spring container after all properties have been set. <br/>
* This method actually makes sure the container is correctly initialized and all configurators
* are processed.
* @throws Exception in case setting up fails
* @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
*/
public void afterPropertiesSet() throws Exception {
ServletContext servletContext = getServletContext();
if (logger.isDebugEnabled()) {
logger.debug("afterPropertiesSet() called with servletContext '" + servletContext + "'");
}
Assert.notNull(servletContext, "The servlet context has not been set on the controller");
Assert.notNull(configurators, "The required 'configurators' property should be set");
// Use a fake servlet config as Spring 1.x does not provide ServletConfigAware functionality
// Now only allow Controller to be configured using parameters
// We should remove adding the ContainerMap here, but that will break anyone
// who has used the spring container to configure the DwrController e.g:
// <bean name="pollAndCometEnabled" class="java.lang.String">
// <constructor-arg index="0"><value>true</value></constructor-arg>
// </bean>
configParams.putAll(new ContainerMap(container, true));
servletConfig = new FakeServletConfig(name, servletContext, configParams);
try {
ContainerUtil.setupDefaults(container, servletConfig);
ContainerUtil.setupFromServletConfig(container, servletConfig);
container.addParameter("debug", "" + debug);
container.setupFinished();
webContextBuilder = StartupUtil.initWebContext(servletConfig, servletContext, container);
StartupUtil.initServerContext(servletConfig, servletContext, container);
ContainerUtil.prepareForWebContextFilter(servletContext, servletConfig, container, webContextBuilder, null);
// The dwr.xml from within the JAR file.
if (includeDefaultConfig) {
ContainerUtil.configureFromSystemDwrXml(container);
}
ContainerUtil.configure(container, configurators);
ContainerUtil.publishContainer(container, servletConfig);
} catch (InstantiationException ex) {
throw new BeanCreationException("Failed to instansiate", ex);
} catch (IllegalAccessException ex) {
throw new BeanCreationException("Access error", ex);
} catch (Exception ex) {
log.fatal("init failed", ex);
throw ex;
} finally {
webContextBuilder.unset();
}
}
Aggregations