Search in sources :

Example 41 with WebApplicationContext

use of org.springframework.web.context.WebApplicationContext in project hudson-2.x by hudson.

the class BeanBuilder method methodMissing.

/**
	 * This method is invoked by Groovy when a method that's not defined in Java is invoked.
     * We use that as a syntax for bean definition. 
	 */
public Object methodMissing(String name, Object arg) {
    Object[] args = (Object[]) arg;
    if (args.length == 0)
        throw new MissingMethodException(name, getClass(), args);
    if (args[0] instanceof Closure) {
        // abstract bean definition
        return invokeBeanDefiningMethod(name, args);
    } else if (args[0] instanceof Class || args[0] instanceof RuntimeBeanReference || args[0] instanceof Map) {
        return invokeBeanDefiningMethod(name, args);
    } else if (args.length > 1 && args[args.length - 1] instanceof Closure) {
        return invokeBeanDefiningMethod(name, args);
    }
    WebApplicationContext ctx = springConfig.getUnrefreshedApplicationContext();
    MetaClass mc = DefaultGroovyMethods.getMetaClass(ctx);
    if (!mc.respondsTo(ctx, name, args).isEmpty()) {
        return mc.invokeMethod(ctx, name, args);
    }
    return this;
}
Also used : MissingMethodException(groovy.lang.MissingMethodException) Closure(groovy.lang.Closure) MetaClass(groovy.lang.MetaClass) GroovyObject(groovy.lang.GroovyObject) MetaClass(groovy.lang.MetaClass) RuntimeBeanReference(org.springframework.beans.factory.config.RuntimeBeanReference) HashMap(java.util.HashMap) Map(java.util.Map) ManagedMap(org.springframework.beans.factory.support.ManagedMap) WebApplicationContext(org.springframework.web.context.WebApplicationContext)

Example 42 with WebApplicationContext

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

the class SpringBootTestWebEnvironmentMockTests method validateWebApplicationContextIsSet.

@Test
public void validateWebApplicationContextIsSet() {
    WebApplicationContext fromServletContext = WebApplicationContextUtils.getWebApplicationContext(this.servletContext);
    assertThat(fromServletContext).isSameAs(this.context);
}
Also used : WebApplicationContext(org.springframework.web.context.WebApplicationContext) Test(org.junit.Test)

Example 43 with WebApplicationContext

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

the class MultipartFilter method lookupMultipartResolver.

/**
	 * Look for a MultipartResolver bean in the root web application context.
	 * Supports a "multipartResolverBeanName" filter init param; the default
	 * bean name is "filterMultipartResolver".
	 * <p>This can be overridden to use a custom MultipartResolver instance,
	 * for example if not using a Spring web application context.
	 * @return the MultipartResolver instance, or {@code null} if none found
	 */
protected MultipartResolver lookupMultipartResolver() {
    WebApplicationContext wac = WebApplicationContextUtils.getWebApplicationContext(getServletContext());
    String beanName = getMultipartResolverBeanName();
    if (wac != null && wac.containsBean(beanName)) {
        if (logger.isDebugEnabled()) {
            logger.debug("Using MultipartResolver '" + beanName + "' for MultipartFilter");
        }
        return wac.getBean(beanName, MultipartResolver.class);
    } else {
        return this.defaultMultipartResolver;
    }
}
Also used : WebApplicationContext(org.springframework.web.context.WebApplicationContext)

Example 44 with WebApplicationContext

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

the class DelegatingFilterProxy method doFilter.

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) throws ServletException, IOException {
    // Lazily initialize the delegate if necessary.
    Filter delegateToUse = this.delegate;
    if (delegateToUse == null) {
        synchronized (this.delegateMonitor) {
            if (this.delegate == null) {
                WebApplicationContext wac = findWebApplicationContext();
                if (wac == null) {
                    throw new IllegalStateException("No WebApplicationContext found: " + "no ContextLoaderListener or DispatcherServlet registered?");
                }
                this.delegate = initDelegate(wac);
            }
            delegateToUse = this.delegate;
        }
    }
    // Let the delegate perform the actual doFilter operation.
    invokeDelegate(delegateToUse, request, response, filterChain);
}
Also used : Filter(javax.servlet.Filter) WebApplicationContext(org.springframework.web.context.WebApplicationContext)

Example 45 with WebApplicationContext

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

the class SpringBeanFacesELResolver method getValue.

@Override
public Object getValue(ELContext elContext, Object base, Object property) throws ELException {
    if (base == null) {
        String beanName = property.toString();
        WebApplicationContext wac = getWebApplicationContext(elContext);
        if (wac.containsBean(beanName)) {
            elContext.setPropertyResolved(true);
            return wac.getBean(beanName);
        }
    }
    return null;
}
Also used : 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