3

我有支持 Bean,我想在它周围有一个过滤器。我尝试使用以下方法创建一个-

@Startup
@Filter(around="com.myapp.action.ViewAttachment")
@Name(value="TestFilter")
@Scope(ScopeType.APPLICATION)
@BypassInterceptors
public class GeneralRequestFilter extends AbstractFilter {

    public void doFilter(ServletRequest request, ServletResponse response,
            FilterChain chain) throws IOException, ServletException {
            System.out.println("InSide Filter!!!!!");
            chain.doFilter(request, response);
    }

}

如果我删除@BypassInterceptors注释,则每个请求都会调用此过滤器。它会为同一个请求执行多次,我什至会收到类似的错误

ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[localhost].[/gwps].[Faces Servlet]] Servlet.service() for servlet Faces Servlet threw exce
ption
java.lang.NullPointerException
        at org.jboss.seam.contexts.Contexts.destroy(Contexts.java:241)
        at org.jboss.seam.contexts.Lifecycle.endCall(Lifecycle.java:95)
        at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:122)
        at org.jboss.seam.intercept.JavaBeanInterceptor.interceptInvocation(JavaBeanInterceptor.java:185)
        at org.jboss.seam.intercept.JavaBeanInterceptor.invoke(JavaBeanInterceptor.java:103)
        at com.myapp.action.GeneralRequestFilter_$$_javassist_seam_4.doFilter(GeneralRequestFilter_$$_javassist_seam_4.java)
        at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
        at org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:158)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:235)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
        at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:190)
        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:433)
        at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:92)
        at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.process(SecurityContextEstablishmentValve.java:126)
        at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:70)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
        at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:330)
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:829)
        at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:598)
        at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
        at java.lang.Thread.run(Thread.java:636)

如果@BypassInterceptors保持原样,则不会过滤任何请求。

我的最终目标是获取HttpServletRequest对象的句柄,以便我可以从包含 fdf 格式数据的请求中提取输入流。

由于我无法HttpServletRequest在支持 Bean 中获取对象,我发现我可以编写一个自定义过滤器,它可以在执行支持 bean 之前设置请求属性,并且可以使用@RequestParameter.

4

0 回答 0