论坛首页 Java企业应用论坛

seam中自定义过滤器

浏览 3783 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2012-05-31  
seam中,通过在web.xml自定义过滤器,然后在过滤器上加上@Filter注解。
但在的问题是,我在访问时,任何请求都会被我的自定义过滤器所拦截,并且最后报一个destory方法的空指针异常。
不知道是怎么回事。
我之所以自定义过滤器的原因是现在有两套系统,一套用的是SEAM,另一套是SSH。现在要做一个集成,不知道能不能通过过滤器分开。因为SEAM的SESSION是由Identity来管理,但SSH是通过SESSION来管理。系统登陆验证是走的SEAM的那套系统。如果自定义过滤器不使用@filter注解,到是可以正常访问,但这样就拿不到SEAM的组件,Identity就无法取到。不知道有没有哪位对SEAM有研究的能给我点意见。


@Startup
@Scope(ScopeType.APPLICATION)
@Name("PermissionFilter")
@BypassInterceptors
@Filter(within="org.jboss.seam.web.ajax4jsfFilter")
public class PermissionFilter 
//implements javax.servlet.Filter
extends AbstractFilter
{
    private Log log = LogFactory.getLog(PermissionFilter.class);

    protected FilterConfig config;
    protected ServletContext context;
    protected String redirectUrl;

    public void init(FilterConfig config) throws ServletException 
    {
        this.config = config;
        this.context = config.getServletContext();
        this.redirectUrl = config.getInitParameter("redirect");
    }

    public void doFilter(ServletRequest req, ServletResponse resp,FilterChain chain) throws IOException, ServletException 
    {
        HttpServletRequest request = (HttpServletRequest) req;
        HttpServletResponse response = (HttpServletResponse) resp;

        Identity id = (Identity)Component.getInstance(Identity.class,true);
//        Object operObj = request.getSession().getAttribute("operid");
//        if ( operObj == null ) 
//        {
//            context.getRequestDispatcher(redirectUrl).forward(request, response);
//            return;
//        }
        chain.doFilter(request, response);
        return;
    }

    public void destroy() 
    {
        this.config = null;
        this.context = null;
        this.redirectUrl = null;
    }
}
论坛首页 Java企业应用版

跳转论坛:
Global site tag (gtag.js) - Google Analytics