Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package org.jboss.weld.servlet;
 import  javax.servlet.Filter;
 import  javax.servlet.FilterChain;
 import  javax.servlet.FilterConfig;
 import  javax.servlet.ServletException;
 import  javax.servlet.ServletRequest;
import  javax.servlet.ServletRequestEvent;
import  javax.servlet.ServletResponse;

This class provides support for cross-context dispatching to a web application that's using Weld. By default Weld assumes single context dispatching, and relies upon receiving events accordingly.

This filter is only required in special circumstances - i.e. within portlet applications.

To install add the following configuration to your portlet web archive's web.xml:


Marko Strukelj
public class WeldCrossContextFilter implements Filter {
   private static final String REQUEST_CONTEXT_KEY = "org.jboss.weld.context.http.HttpRequestContextImpl";
   private volatile WeldInitialListener listener;
   private FilterConfig config;
   public void init(FilterConfig filterConfigthrows ServletException {
      this. = filterConfig;
   public void doFilter(ServletRequest request, ServletResponse response, FilterChain chainthrows IOException, ServletException {
       if ( == null) {
            = (WeldInitialListenerrequest.getServletContext().getAttribute(WeldInitialListener.class.getName());
      // cross-context means request is dispatched as INCLUDE or FORWARD or ERROR
      boolean crossCtx = request.getAttribute("javax.servlet.include.request_uri") != null
            || request.getAttribute("javax.servlet.forward.request_uri") != null
            || request.getAttribute("javax.servlet.error.request_uri") != null;
      boolean activated = false;
      try {
         if (crossCtx) {
            if (request.getAttribute() == null) {
               .requestInitialized(new ServletRequestEvent(.getServletContext(), request));
               activated = true;
      } finally {
         if (activated) {
            .requestDestroyed(new ServletRequestEvent(.getServletContext(), request));
   public void destroy() {
New to GrepCode? Check out our FAQ X