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;
}
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);
}
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;
}
}
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);
}
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;
}
Aggregations