Search in sources :

Example 1 with FakeServletConfig

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);
    }
}
Also used : ServletException(javax.servlet.ServletException) FakeServletContext(org.directwebremoting.util.FakeServletContext) ServletConfig(javax.servlet.ServletConfig) FakeServletConfig(org.directwebremoting.util.FakeServletConfig) FakeServletContext(org.directwebremoting.util.FakeServletContext) ServletContext(javax.servlet.ServletContext) WebContextBuilder(org.directwebremoting.WebContextFactory.WebContextBuilder) ServletException(javax.servlet.ServletException) FakeServletConfig(org.directwebremoting.util.FakeServletConfig)

Example 2 with FakeServletConfig

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();
    }
}
Also used : BeanCreationException(org.springframework.beans.factory.BeanCreationException) ServletContext(javax.servlet.ServletContext) ContainerMap(org.directwebremoting.impl.ContainerMap) BeansException(org.springframework.beans.BeansException) BeanCreationException(org.springframework.beans.factory.BeanCreationException) FakeServletConfig(org.directwebremoting.util.FakeServletConfig)

Aggregations

ServletContext (javax.servlet.ServletContext)2 FakeServletConfig (org.directwebremoting.util.FakeServletConfig)2 ServletConfig (javax.servlet.ServletConfig)1 ServletException (javax.servlet.ServletException)1 WebContextBuilder (org.directwebremoting.WebContextFactory.WebContextBuilder)1 ContainerMap (org.directwebremoting.impl.ContainerMap)1 FakeServletContext (org.directwebremoting.util.FakeServletContext)1 BeansException (org.springframework.beans.BeansException)1 BeanCreationException (org.springframework.beans.factory.BeanCreationException)1