Search in sources :

Example 66 with WebApplicationContext

use of org.springframework.web.context.WebApplicationContext in project grails-core by grails.

the class GroovyPagesServlet method initFrameworkServlet.

@Override
protected void initFrameworkServlet() throws ServletException, BeansException {
    context = getServletContext();
    context.log("GSP servlet initialized");
    context.setAttribute(SERVLET_INSTANCE, this);
    final WebApplicationContext webApplicationContext = getWebApplicationContext();
    grailsAttributes = GrailsFactoriesLoader.loadFactoriesWithArguments(GrailsApplicationAttributes.class, getClass().getClassLoader(), new Object[] { context }).get(0);
    webApplicationContext.getAutowireCapableBeanFactory().autowireBeanProperties(this, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, false);
    groovyPagesTemplateEngine = webApplicationContext.getBean(GroovyPagesTemplateEngine.BEAN_ID, GroovyPagesTemplateEngine.class);
}
Also used : GroovyPagesTemplateEngine(org.grails.gsp.GroovyPagesTemplateEngine) WebApplicationContext(org.springframework.web.context.WebApplicationContext)

Example 67 with WebApplicationContext

use of org.springframework.web.context.WebApplicationContext in project grails-core by grails.

the class GrailsWebUtil method lookupApplication.

/**
     * Looks up a GrailsApplication instance from the ServletContext.
     *
     * @param servletContext The ServletContext
     * @return A GrailsApplication or null if there isn't one
     */
public static GrailsApplication lookupApplication(ServletContext servletContext) {
    if (servletContext == null) {
        return null;
    }
    GrailsApplication grailsApplication = (GrailsApplication) servletContext.getAttribute(ApplicationAttributes.APPLICATION);
    if (grailsApplication != null) {
        return grailsApplication;
    }
    final WebApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(servletContext);
    if (context == null || !context.containsBean(GrailsApplication.APPLICATION_ID)) {
        return null;
    }
    return context.getBean(GrailsApplication.APPLICATION_ID, GrailsApplication.class);
}
Also used : GrailsApplication(grails.core.GrailsApplication) WebApplicationContext(org.springframework.web.context.WebApplicationContext)

Example 68 with WebApplicationContext

use of org.springframework.web.context.WebApplicationContext in project grails-core by grails.

the class WebUtils method lookupWebRequestInterceptors.

/**
     * Looks up all of the WebRequestInterceptor instances registered with the application
     *
     * @param servletContext The ServletContext instance
     * @return An array of WebRequestInterceptor instances
     */
public static WebRequestInterceptor[] lookupWebRequestInterceptors(ServletContext servletContext) {
    WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
    final Collection<WebRequestInterceptor> webRequestInterceptors = wac.getBeansOfType(WebRequestInterceptor.class).values();
    return webRequestInterceptors.toArray(new WebRequestInterceptor[webRequestInterceptors.size()]);
}
Also used : WebRequestInterceptor(org.springframework.web.context.request.WebRequestInterceptor) WebApplicationContext(org.springframework.web.context.WebApplicationContext)

Example 69 with WebApplicationContext

use of org.springframework.web.context.WebApplicationContext in project grails-core by grails.

the class GrailsLayoutDecoratorMapper method init.

@Override
public void init(Config c, Properties properties, DecoratorMapper parentMapper) throws InstantiationException {
    super.init(c, properties, parentMapper);
    ServletContext servletContext = c.getServletContext();
    WebApplicationContext applicationContext = WebApplicationContextUtils.getWebApplicationContext(servletContext);
    if (applicationContext != null) {
        GrailsApplication grailsApplication = applicationContext.getBean(GrailsApplication.APPLICATION_ID, GrailsApplication.class);
        groovyPageLayoutFinder = grailsApplication.getMainContext().getBean("groovyPageLayoutFinder", GroovyPageLayoutFinder.class);
    }
}
Also used : GrailsApplication(grails.core.GrailsApplication) ServletContext(javax.servlet.ServletContext) WebApplicationContext(org.springframework.web.context.WebApplicationContext)

Example 70 with WebApplicationContext

use of org.springframework.web.context.WebApplicationContext in project spring-framework by spring-projects.

the class MockHttpServletRequestBuilder method getFlashMapManager.

private FlashMapManager getFlashMapManager(MockHttpServletRequest request) {
    FlashMapManager flashMapManager = null;
    try {
        ServletContext servletContext = request.getServletContext();
        WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
        flashMapManager = wac.getBean(DispatcherServlet.FLASH_MAP_MANAGER_BEAN_NAME, FlashMapManager.class);
    } catch (IllegalStateException ex) {
    // ignore
    } catch (NoSuchBeanDefinitionException ex) {
    // ignore
    }
    return (flashMapManager != null ? flashMapManager : new SessionFlashMapManager());
}
Also used : SessionFlashMapManager(org.springframework.web.servlet.support.SessionFlashMapManager) FlashMapManager(org.springframework.web.servlet.FlashMapManager) ServletContext(javax.servlet.ServletContext) SessionFlashMapManager(org.springframework.web.servlet.support.SessionFlashMapManager) NoSuchBeanDefinitionException(org.springframework.beans.factory.NoSuchBeanDefinitionException) WebApplicationContext(org.springframework.web.context.WebApplicationContext)

Aggregations

WebApplicationContext (org.springframework.web.context.WebApplicationContext)103 Test (org.junit.Test)32 ServletContext (javax.servlet.ServletContext)17 MockHttpServletRequest (org.springframework.mock.web.test.MockHttpServletRequest)15 MockHttpServletResponse (org.springframework.mock.web.test.MockHttpServletResponse)13 ApplicationContext (org.springframework.context.ApplicationContext)11 GenericWebApplicationContext (org.springframework.web.context.support.GenericWebApplicationContext)11 HashMap (java.util.HashMap)9 StaticWebApplicationContext (org.springframework.web.context.support.StaticWebApplicationContext)9 MockServletContext (org.springframework.mock.web.test.MockServletContext)8 ConfigurableWebApplicationContext (org.springframework.web.context.ConfigurableWebApplicationContext)7 Filter (javax.servlet.Filter)6 HttpServletResponse (javax.servlet.http.HttpServletResponse)6 AnnotationConfigWebApplicationContext (org.springframework.web.context.support.AnnotationConfigWebApplicationContext)6 Binding (groovy.lang.Binding)5 BeanBuilder (hudson.util.spring.BeanBuilder)5 HttpServletRequest (javax.servlet.http.HttpServletRequest)5 DispatcherServlet (org.springframework.web.servlet.DispatcherServlet)5 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)4 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)4