Main Content

Magnolia Community Forums: Get help with Magnolia: Couldn't access an init parameter in a filter using FilterDecorator


  • azhang4
    azhang4
    Full name: Aiping Zhang
    Posts: 10
    Last post: Feb 3, 2017 9:28:37 PM
    Registered on: Jul 29, 2015
    Couldn't access an init parameter in a filter using FilterDecorator
    #1 by azhang4 on Jan 13, 2017 9:06:03 PM

    Hi magnolia,

    I configured a decorated filter in magnolia CMS according to the document,

    https://documentation.magnolia-cms.com/display/DOCS/Custom+filters#Customfilters-Configuringandregisteringafilterwhichdoesnotimplementinfo.magnolia.cms.filters.MgnlFilter

    But the filterConfig.get("myInitParam") or filterConfig.getInitParameter("myInitParam") doesn't work as indicated there.

    Example code,

    public class AnotherFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
    String initParam = filterConfig.get("myInitParam");
    // do something usefull here with the initParam
    }
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain)
    throws IOException, ServletException {
    // do something usefull here
    filterChain.doFilter(servletRequest, servletResponse);
    }
    @Override
    public void destroy() {
    }
    }


    What did I miss? Thanks a lot for the help!

    Aiping

  • azhang4
    azhang4
    Full name: Aiping Zhang
    Posts: 10
    Last post: Feb 3, 2017 9:28:37 PM
    Registered on: Jul 29, 2015
    Re: Couldn't access an init parameter in a filter using FilterDecorator
    #2 by azhang4 on Jan 13, 2017 9:08:07 PM

    Magnolia version is CE 5.4.7. Thanks!

  • cmeier
    cmeier
    Full name: Christoph Meier
    Posts: 203
    Last post: Jun 27, 2017 4:08:00 PM
    Re: Couldn't access an init parameter in a filter using FilterDecorator
    #3 by cmeier on Jan 17, 2017 2:46:30 AM

    Hello Aiping Zhang

    Do you see the new filter config in the JCR configuration app?
    Could you provide a screenshot how the config of your new filter looks like?

    Have you already tried to debug the running app setting a breakpoint in the #init and #doFilter methods of your new filter?

    cheers,
    Christoph

  • azhang4
    azhang4
    Full name: Aiping Zhang
    Posts: 10
    Last post: Feb 3, 2017 9:28:37 PM
    Registered on: Jul 29, 2015
    Re: Couldn't access an init parameter in a filter using FilterDecorator
    #4 by azhang4 on Jan 18, 2017 4:25:05 PM

    Hi Christoph,

    Thanks for your help! Here is the link to the screenshot of the configuration,

    https://photos.google.com/share/AF1QipOWt2qf7Ooy7wWguvTenuxlhICvSJMT7rg_MFqdXq5gMI7PPsaDhpOCa5LX-I6ETg?key=RHhfVjdHLWhSZ1VJQTk1UWhmUG5qQWk2THV2OWln

    By the way, what's the "new filter config in the JCR configuration app"? Can you point me to some examples/documents?

    At the same time I'll do some debugging by setting breakpoints.

    Thanks a lot,
    Aiping

  • azhang4
    azhang4
    Full name: Aiping Zhang
    Posts: 10
    Last post: Feb 3, 2017 9:28:37 PM
    Registered on: Jul 29, 2015
    Re: Couldn't access an init parameter in a filter using FilterDecorator
    #5 by azhang4 on Jan 18, 2017 7:43:59 PM

    I found the solution for this issue. To be able to use the method, filterConfig.get("myInitParam"), we need to move the init params outside of the "config" node and we don't need "config" node there inside "decoratedFilter" node.

    Thanks for the help,
    Aiping

  • azhang4
    azhang4
    Full name: Aiping Zhang
    Posts: 10
    Last post: Feb 3, 2017 9:28:37 PM
    Registered on: Jul 29, 2015
    Re: Couldn't access an init parameter in a filter using FilterDecorator
    #6 by azhang4 on Feb 3, 2017 9:28:37 PM

    Although it seems the code,
    filterConfig.get("myInitParam")
    can get the value of the init parameter "myInitParam", but it also throws errors when initializing the filter,

    "2017-02-03 10:16:41,751 ERROR info.magnolia.cms.filters.CompositeFilter : Error initializing filter [sessionCookieFilter]
    groovy.lang.MissingMethodException: No signature of method: info.magnolia.cms.filters.FilterDecorator$CustomFilterConfig.get() is applicable for argument types: (java.lang.String) values: [logoutPath]"

    I appreciate if someone can help me with this issue!

    Thanks very much,
    Aiping

You don't have the permission to post on this thread

Sign in

To login on this forum, you can use your Magnolia Forge, Support or Partner account, or, below, your Google, Yahoo! or OpenID account. If you have trouble logging in, or any other sort of issue, please let us know in the Meta forum, on the user-list, or simply by email at forum-admin at magnolia-cms dot com.

* Required

... or sign in with:

  • icon http://{your-openid-url}
  • icon
  • icon https://me.yahoo.com/