Search in sources :

Example 1 with ContainerMap

use of org.directwebremoting.impl.ContainerMap 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)1 ContainerMap (org.directwebremoting.impl.ContainerMap)1 FakeServletConfig (org.directwebremoting.util.FakeServletConfig)1 BeansException (org.springframework.beans.BeansException)1 BeanCreationException (org.springframework.beans.factory.BeanCreationException)1