Java based configuration and Filters- ConfigurableSiteMeshFilter

173 views
Skip to first unread message

Ilyas Patel

unread,
Jun 1, 2012, 12:07:11 PM6/1/12
to sitemes...@googlegroups.com
Hello

I am fairly new to Java and have been tasked with creating a filter to decorate a response depending on a particular HTTP_Referer.

I have created a filter which extends ConfigurableSiteMeshFilter according to the documentation here - http://www.sitemesh.org/configuration.html.

Here is the Class:

public class PageFilter extends ConfigurableSiteMeshFilter {
    @Override
    protected void applyCustomConfiguration(SiteMeshFilterBuilder builder) {
        System.out.println("1 : " + builder.toString());
    }

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        System.out.println("2");
    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)throws IOException, ServletException  {
        System.out.println("3");
        chain.doFilter(request, response);
    }

    @Override
    public void destroy() {
        System.out.println("4");
    }
}

Web.xml:

<filter>
        <filter-name>pageFilter</filter-name>
        <filter-class>com.company.mycompany.core.filters.PageFilter</filter-class>
</filter>
<filter-mapping>
        <filter-name>pageFilter</filter-name>
        <url-pattern>/*</url-pattern>
</filter-mapping>

<filter>
        <filter-name>sitemesh</filter-name>
        <filter-class>com.opensymphony.module.sitemesh.filter.PageFilter</filter-class>
</filter>

<filter-mapping>
        <filter-name>sitemesh</filter-name>
        <url-pattern>/*</url-pattern>
        <dispatcher>REQUEST</dispatcher>
        <dispatcher>FORWARD</dispatcher>
</filter-mapping>


The problem I am having is applyCustomConfiguration() is never being called. I have stepped debug and only the doFilter() method is being called.  One of the experience developers tells me this method should be called automatically by the container. 

Is there anything else I need to do?

Thanks
Reply all
Reply to author
Forward
0 new messages