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

Replace filterPath pattern '/*' with empty string #230

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Replace filterPath pattern '/*' with empty string #230

wants to merge 1 commit into from

Conversation

fschrogl
Copy link

A filterPath pattern of '/*' is now replaced with an empty string. This matches the behavior of methods getFilterPathFromAnnotation() and getFilterPathFromConfig().

I'm not sure if it's a bug, but I noticed the different beahvior when initializing Wicket in a Spring Boot application. When using a @webfilter("/") annotation or the init parameter filterMappingUrlPattern="/" Wicket works as expected, but when doing the same programmatically with wicketFilter.setFilterPath("/") the path gets internally rewritten to "/" and Wicket than only handles HTTP requests to the root path.

A filterPath pattern of '/*' is now replaced with an empty string. This matches the behavior of methods getFilterPathFromAnnotation() and getFilterPathFromConfig().
@martin-g
Copy link
Member

bq. wicketFilter.setFilterPath("/") the path gets internally rewritten to "/"

Is something missing here ? The values are the same - "/", so I do not understand what is rewritten.
Can you please provide your Spring Boot configuration related to WicketFilter that breaks your app ? I also have Spring Boot based app and I can try it locally to verify the problem..
Thanks!

@fschrogl
Copy link
Author

I tried to initialize Wicket using WicketFilter class and three different approaches (one after another). That's where I noticed the different behavior (at least that's how I understand it).

(1) Using setFilterPath method

@Bean
public FilterRegistrationBean<WicketFilter> initWicketFilterByGetter() {
  WicketFilter wicketFilter = new WicketFilter(new MyWicketApplication());
  // filterPath '/' works for all paths
  // filterPath '/*' only works for root path
  wicketFilter.setFilterPath("/");
  return new FilterRegistrationBean<>(wicketFilter);
}

(2) Using init params

@Bean
public FilterRegistrationBean<WicketFilter> initWicketFilterByInitParam() {
  WicketFilter wicketFilter = new WicketFilter(new MyWicketApplication());
  FilterRegistrationBean<WicketFilter> wicketFilterRegistrationBean = new FilterRegistrationBean<>(wicketFilter);
  // Using '/*' works for all paths, using '/' leads to an exception
  wicketFilterRegistrationBean.addInitParameter(WicketFilter.FILTER_MAPPING_PARAM, "/*");
  return wicketFilterRegistrationBean;
}

(3) Using @WebFilter annotation on a custom filter and @ServletComponentScan for Spring Boot

// /* works, / doesn't work
@WebFilter(value = "/*", initParams = @WebInitParam(name = "applicationClassName", value = "package.MyWicketApplication"))
public static class MyWicketFilter extends WicketFilter {  }

In approach (1) I have to use / while in approaches (2) and (3) I have to use /* to achieve the same outcome.

@klopfdreh
Copy link
Member

Just my thoughts:

/* - maps every path - root paths and sub paths to the specific filter
/ - maps only the root path but not every sub path

So from my understanding they aren't the same and shouldn't be mixed up.

https://stackoverflow.com/questions/4140448/difference-between-and-in-servlet-mapping-url-pattern

Maybe we should inspect this a bit more to achieve the right handling.

WDTY?

@klopfdreh
Copy link
Member

@solomax
Copy link
Contributor

solomax commented May 4, 2022

This PR seems to be inactive for too long :(
I guess it can be dropped? :)

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

Successfully merging this pull request may close these issues.

4 participants