Skip to content

Commit

Permalink
Fix double registration of Filter
Browse files Browse the repository at this point in the history
A stupid typo lurking in EmbeddedWebApplicationContext meant
that a FilterRegistrationBean would register a Filter, and then
it would be registered again without the initializer.

[Fixes #54676948] Filter registered twice
  • Loading branch information
Dave Syer committed Aug 6, 2013
1 parent 2ec953a commit 65bd9da
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ protected Collection<ServletContextInitializer> getServletContextInitializerBean
for (Entry<String, Filter> filterBean : getOrderedBeansOfType(Filter.class)) {
String name = filterBean.getKey();
Filter filter = filterBean.getValue();
if (!servletRegistrations.contains(filter)) {
if (!filterRegistrations.contains(filter)) {
FilterRegistrationBean registration = new FilterRegistrationBean(filter);
registration.setName(name);
initializers.add(registration);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,20 @@ public void servletContextInitializerBeansSkipsRegisteredServletsAndFilters()
verify(servletContext, atMost(1)).addFilter(anyString(), (Filter) anyObject());
}

@Test
public void filterReegistrationBeansSkipsRegisteredFilters() throws Exception {
addEmbeddedServletContainerFactoryBean();
Filter filter = mock(Filter.class);
FilterRegistrationBean initializer = new FilterRegistrationBean(filter);
this.context.registerBeanDefinition("initializerBean",
beanDefinition(initializer));
this.context.registerBeanDefinition("filterBean", beanDefinition(filter));
this.context.refresh();
ServletContext servletContext = getEmbeddedServletContainerFactory()
.getServletContext();
verify(servletContext, atMost(1)).addFilter(anyString(), (Filter) anyObject());
}

@Test
public void postProcessEmbeddedServletContainerFactory() throws Exception {
RootBeanDefinition bd = new RootBeanDefinition(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
* {@link TomcatEmbeddedServletContainer}.
*
* @author Phillip Webb
* @author Dave Syer
*/
public class TomcatEmbeddedServletContainerFactoryTests extends
AbstractEmbeddedServletContainerFactoryTests {
Expand Down

0 comments on commit 65bd9da

Please sign in to comment.