users@glassfish.java.net

Re: Servlet Filter

From: Jan Luehe <Jan.Luehe_at_Sun.COM>
Date: Thu, 17 Sep 2009 14:51:18 -0700

On 09/17/09 13:09, glassfish_at_javadesktop.org wrote:
> I have a legacy EAR we have ported to run on Glassfish and I am trying to add a Servlet Filter to one of the Servlet mappings.
>
> My Servlet Filter is called as expected but when the doFilter() method completes the service() method in my servlet is never hit. I have no idea where the flow of control goes. There are no errors in the server.log file.
>
> I have successfully added Servlet Filters to Netbeans projects with no problems.
>
> Any ideas what could be going wrong? Here is my web.xml file:
>
>
>
> <?xml version="1.0" encoding="UTF-8"?>
> <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
> <web-app>
>
> <context-param>
> <param-name>weblogic.jsp.keepgenerated</param-name>
> <param-value>true</param-value>
> </context-param>
> <!--
> <filter>
> <filter-name>AuthorizationFilter Password Change</filter-name>
> <filter-class>edu.utah.acs.lib.login.security.AuthorizationFilter</filter-class>
> <init-param>
> <param-name>message</param-name>
> <param-value>You are not authorized to use this application.</param-value>
> </init-param>
> <init-param>
> <param-name>title</param-name>
> <param-value>Password Change</param-value>
> </init-param>
> <init-param>
> <param-name>forceReload</param-name>
> <param-value>false</param-value>
> </init-param>
> </filter>
>
>
>
>
>
> <filter-mapping>
> <filter-name>AuthorizationFilter Password Change</filter-name>
> <url-pattern>>/acs/acsportal/portal-password-change</url-pattern>
> </filter-mapping>
>
>
>
>
> <servlet>
> <servlet-name>portal</servlet-name>
> <description>This is the portal password Servlet</description>
> <servlet-class>edu.utah.acs.servlet.ACSPortalServlet</servlet-class>
>
> </servlet>
>
>
>
> <servlet-mapping>
> <servlet-name>portal</servlet-name>
> <url-pattern>/acs/acsportal/*</url-pattern>
>
> </servlet-mapping>
>
> <taglib>
> <taglib-uri>/linktag/LinkTags_1_0.tld</taglib-uri>
> <taglib-location>/WEB-INF/linktag/LinkTags_1_0.tld</taglib-location>
> </taglib>
> <taglib>
> <taglib-uri>/urlrewritetag/RewriteURLS_1_0.tld</taglib-uri>
> <taglib-location>/WEB-INF/urlrewritetag/RewriteURLS_1_0.tld</taglib-location>
> </taglib>
>
>
> </web-app>
> [Message sent by forum member 'bryanut' (bwooten_at_acs.utah.edu)]
>

What does your filter's doFilter impl look like?

Normally, this is implemented as follows:

  public void doFilter(ServletRequest request,
              ServletResponse response,
              FilterChain filterChain)
          throws IOException, ServletException {
      // Filter inbound processing here
      filterChain.doFilter(request, response);
      // Filter outbound processing here
  }

Note that filterChain.doFilter will call the next filter in the
chain, or the service method of the target servlet if there are no
more filters in the chain.

Therefore, a servlet's service method will execute within the scope
of a filter's doFilter, and *not* after doFilter has returned.

Of course, if your filter's doFilter is implemented such that it
never calls filterChain.doFilter, that would be a problem.


Jan

> http://forums.java.net/jive/thread.jspa?messageID=364484
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>
>