Search in sources :

Example 1 with CubaXmlWebApplicationContext

use of com.haulmont.cuba.core.sys.CubaXmlWebApplicationContext in project cuba by cuba-platform.

the class SingleAppRestApiServlet method createWebApplicationContext.

@Override
protected WebApplicationContext createWebApplicationContext(ApplicationContext parent) {
    if (this.logger.isDebugEnabled()) {
        this.logger.debug("Servlet with name '" + getServletName() + "' will try to create custom WebApplicationContext context of class '" + CubaXmlWebApplicationContext.class.getName() + "'" + ", using parent context [" + parent + "]");
    }
    ConfigurableWebApplicationContext wac = new CubaXmlWebApplicationContext() {

        @Override
        protected ResourcePatternResolver getResourcePatternResolver() {
            if (dependencyJars == null || dependencyJars.isEmpty()) {
                throw new RuntimeException("No JARs defined for the 'web' block. " + "Please check that web.dependencies file exists in WEB-INF directory.");
            }
            return new SingleAppResourcePatternResolver(this, dependencyJars);
        }
    };
    wac.setEnvironment(getEnvironment());
    wac.setParent(parent);
    wac.setConfigLocation(getContextConfigLocation());
    configureAndRefreshWebApplicationContext(wac);
    return wac;
}
Also used : ConfigurableWebApplicationContext(org.springframework.web.context.ConfigurableWebApplicationContext) CubaXmlWebApplicationContext(com.haulmont.cuba.core.sys.CubaXmlWebApplicationContext) SingleAppResourcePatternResolver(com.haulmont.cuba.core.sys.SingleAppResourcePatternResolver)

Example 2 with CubaXmlWebApplicationContext

use of com.haulmont.cuba.core.sys.CubaXmlWebApplicationContext in project cuba by cuba-platform.

the class SingleAppIdpServlet method createWebApplicationContext.

@Override
protected WebApplicationContext createWebApplicationContext(ApplicationContext parent) {
    if (this.logger.isDebugEnabled()) {
        this.logger.debug("Servlet with name '" + getServletName() + "' will try to create custom WebApplicationContext context of class '" + CubaXmlWebApplicationContext.class.getName() + "'" + ", using parent context [" + parent + "]");
    }
    ConfigurableWebApplicationContext wac = new CubaXmlWebApplicationContext() {

        @Override
        protected ResourcePatternResolver getResourcePatternResolver() {
            if (dependencyJars == null || dependencyJars.isEmpty()) {
                throw new RuntimeException("No JARs defined for the 'web' block. " + "Please check that web.dependencies file exists in WEB-INF directory.");
            }
            return new SingleAppResourcePatternResolver(this, dependencyJars);
        }
    };
    wac.setEnvironment(getEnvironment());
    wac.setParent(parent);
    wac.setConfigLocation(getContextConfigLocation());
    configureAndRefreshWebApplicationContext(wac);
    return wac;
}
Also used : ConfigurableWebApplicationContext(org.springframework.web.context.ConfigurableWebApplicationContext) CubaXmlWebApplicationContext(com.haulmont.cuba.core.sys.CubaXmlWebApplicationContext) SingleAppResourcePatternResolver(com.haulmont.cuba.core.sys.SingleAppResourcePatternResolver)

Example 3 with CubaXmlWebApplicationContext

use of com.haulmont.cuba.core.sys.CubaXmlWebApplicationContext in project cuba by cuba-platform.

the class PortalAppContextLoader method createApplicationContext.

@Override
protected ApplicationContext createApplicationContext(String[] locations) {
    CubaXmlWebApplicationContext webContext = new CubaXmlWebApplicationContext();
    String[] classPathLocations = new String[locations.length];
    for (int i = 0; i < locations.length; i++) {
        classPathLocations[i] = "classpath:" + locations[i];
    }
    webContext.setConfigLocations(classPathLocations);
    webContext.setServletContext(ServletContextHolder.getServletContext());
    webContext.refresh();
    ServletContext servletContext = ServletContextHolder.getServletContext();
    if (servletContext.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE) != null) {
        throw new IllegalStateException("Cannot initialize context because there is already a root application context present - " + "check whether you have multiple ContextLoader* definitions in your web.xml!");
    }
    servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, webContext);
    return webContext;
}
Also used : CubaXmlWebApplicationContext(com.haulmont.cuba.core.sys.CubaXmlWebApplicationContext) ServletContext(javax.servlet.ServletContext)

Example 4 with CubaXmlWebApplicationContext

use of com.haulmont.cuba.core.sys.CubaXmlWebApplicationContext in project cuba by cuba-platform.

the class PortalAppContextLoader method createApplicationContext.

@Override
protected ApplicationContext createApplicationContext(String[] locations, ServletContext servletContext) {
    CubaXmlWebApplicationContext webContext = new CubaXmlWebApplicationContext();
    String[] classPathLocations = new String[locations.length];
    for (int i = 0; i < locations.length; i++) {
        classPathLocations[i] = "classpath:" + locations[i];
    }
    webContext.setConfigLocations(classPathLocations);
    webContext.setServletContext(ServletContextHolder.getServletContext());
    webContext.refresh();
    if (servletContext.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE) != null) {
        throw new IllegalStateException("Cannot initialize context because there is already a root application context present - " + "check whether you have multiple ContextLoader* definitions in your web.xml!");
    }
    servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, webContext);
    return webContext;
}
Also used : CubaXmlWebApplicationContext(com.haulmont.cuba.core.sys.CubaXmlWebApplicationContext)

Example 5 with CubaXmlWebApplicationContext

use of com.haulmont.cuba.core.sys.CubaXmlWebApplicationContext in project cuba by cuba-platform.

the class SingleAppDispatcherServlet method createWebApplicationContext.

@Override
@Nonnull
protected WebApplicationContext createWebApplicationContext(@Nullable ApplicationContext parent) {
    if (this.logger.isDebugEnabled()) {
        this.logger.debug(String.format("Servlet with name '%s' will try to create custom WebApplicationContext context of class '%s', using parent context [%s]", getServletName(), CubaXmlWebApplicationContext.class.getName(), parent));
    }
    ConfigurableWebApplicationContext wac = new CubaXmlWebApplicationContext();
    String contextConfigLocation = getContextConfigLocation();
    if (contextConfigLocation == null) {
        throw new RuntimeException("Unable to determine context config location");
    }
    wac.setEnvironment(getEnvironment());
    wac.setParent(parent);
    wac.setConfigLocation(contextConfigLocation);
    configureAndRefreshWebApplicationContext(wac);
    return wac;
}
Also used : ConfigurableWebApplicationContext(org.springframework.web.context.ConfigurableWebApplicationContext) CubaXmlWebApplicationContext(com.haulmont.cuba.core.sys.CubaXmlWebApplicationContext) Nonnull(javax.annotation.Nonnull)

Aggregations

CubaXmlWebApplicationContext (com.haulmont.cuba.core.sys.CubaXmlWebApplicationContext)5 ConfigurableWebApplicationContext (org.springframework.web.context.ConfigurableWebApplicationContext)3 SingleAppResourcePatternResolver (com.haulmont.cuba.core.sys.SingleAppResourcePatternResolver)2 Nonnull (javax.annotation.Nonnull)1 ServletContext (javax.servlet.ServletContext)1