Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting filter parameters in Spring Boot #245

Open
jeffemandel opened this issue Jun 21, 2022 · 0 comments
Open

Setting filter parameters in Spring Boot #245

jeffemandel opened this issue Jun 21, 2022 · 0 comments

Comments

@jeffemandel
Copy link

I needed to change the log level in the filter in a Spring Boot package, and was initially stymied because I didn't have a web.xml. Here is what allowed me to do this:

@Component
public class MyUrlRewriteFilter extends UrlRewriteFilter {
    @Override
    public void init(FilterConfig config) throws ServletException {
        FilterConfig myConfig = new FilterConfig() {
            private final Map<String, String> params = new HashMap<String, String>();
            {
                params.put("logLevel","DEBUG");
            }
            @Override
            public String getFilterName() {
                return "MyUrlRewriteFilter";
            }
            @Override
            public ServletContext getServletContext() {
                return config.getServletContext();
            }
            @Override
            public String getInitParameter(String name) {
                return params.get(name);
            }
            @Override
            public Enumeration<String> getInitParameterNames() {
                return Collections.enumeration(params.keySet());
            }
        };
        super.init(myConfig);
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant