use of org.jboss.weld.servlet.spi.HttpContextActivationFilter in project core by weld.
the class ServletUtils method getContextActivationFilter.
/**
* Returns the right {@link HttpContextActivationFilter}. If one is set through the SPI it has precedence. Otherwise, if a mapping is set using web.xml, a
* new {@link RegexHttpContextActivationFilter} is constructed and returned. By default, {@link AcceptingHttpContextActivationFilter} is used.
*
* @param manager
* @param context
* @return
*/
public static HttpContextActivationFilter getContextActivationFilter(BeanManagerImpl manager, ServletContext context) {
HttpContextActivationFilter filter = manager.getServices().get(HttpContextActivationFilter.class);
final String pattern = context.getInitParameter(InitParameters.CONTEXT_MAPPING);
if (filter == AcceptingHttpContextActivationFilter.INSTANCE) {
// SPI has precedence. If a filter was not set through SPI let's see if a mapping is set in web.xml
if (pattern != null) {
return new RegexHttpContextActivationFilter(pattern);
}
} else if (pattern != null) {
ServletLogger.LOG.webXmlMappingPatternIgnored(pattern);
}
return filter;
}
use of org.jboss.weld.servlet.spi.HttpContextActivationFilter in project core by weld.
the class WeldInitialListener method contextInitialized.
@Override
public void contextInitialized(ServletContextEvent sce) {
final ServletContext ctx = sce.getServletContext();
// First try to use the context id obtained from the servlet context (OSGi, Servlet containers, etc.)
if (beanManager == null) {
String contextId = ctx.getInitParameter(Container.CONTEXT_ID_KEY);
if (contextId != null) {
List<BeanManagerImpl> managers = new ArrayList<BeanManagerImpl>(Container.instance(contextId).beanDeploymentArchives().values());
Collections.sort(managers, BeanManagers.ID_COMPARATOR);
beanManager = managers.get(0);
}
}
// servlet containers may not be able to inject fields in a servlet listener
if (beanManager == null) {
beanManager = BeanManagerProxy.unwrap(CDI.current().getBeanManager());
}
HttpContextActivationFilter filter = ServletUtils.getContextActivationFilter(beanManager, ctx);
final boolean ignoreForwards = getBooleanInitParameter(ctx, InitParameters.CONTEXT_IGNORE_FORWARD, false);
final boolean ignoreIncludes = getBooleanInitParameter(ctx, InitParameters.CONTEXT_IGNORE_INCLUDE, false);
final boolean nestedInvocationGuard = getBooleanInitParameter(ctx, CONTEXT_IGNORE_GUARD_PARAMETER, true);
final boolean lazyConversationContext = getBooleanInitParameter(ctx, CONVERSATION_CONTEXT_LAZY_PARAM, true);
this.lifecycle = new HttpContextLifecycle(beanManager, filter, ignoreForwards, ignoreIncludes, lazyConversationContext, nestedInvocationGuard);
if (Boolean.valueOf(ctx.getInitParameter(CONVERSATION_FILTER_REGISTERED))) {
this.lifecycle.setConversationActivationEnabled(false);
}
this.lifecycle.contextInitialized(ctx);
ctx.setAttribute(WeldInitialListener.class.getName(), this);
}
Aggregations