Creating a custom filter in Jboss Seam

1.2k views Asked by At

I have backing Bean around which I would like to have a filter. I tried creating one using the following-

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

}

If I remove the @BypassInterceptors annot, this filter is called in for every request. It get executed multiple time for the same request and I even get errors like

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)

If the @BypassInterceptors is kept as it is, none of the request get filtered.

My Final goal is to get a handle over the HttpServletRequest object so that I can extract the input stream from the request which contains data in the fdf format.

Since I cannot get an HttpServletRequest object in a backing Bean, I figured out that I can write a custom filter which can set a request attribute before the backing bean is executed and I can access my data using the @RequestParameter.

0

There are 0 answers