Polish contribution

Closes gh-3643
This commit is contained in:
Andy Wilkinson
2015-08-06 12:05:56 +01:00
parent 7568af1710
commit 9fcc860908
3 changed files with 32 additions and 3 deletions

View File

@@ -107,13 +107,13 @@ public class WebMvcAutoConfiguration {
@Bean
@ConditionalOnMissingBean(HiddenHttpMethodFilter.class)
public HiddenHttpMethodFilter hiddenHttpMethodFilter() {
public OrderedHiddenHttpMethodFilter hiddenHttpMethodFilter() {
return new OrderedHiddenHttpMethodFilter();
}
@Bean
@ConditionalOnMissingBean(HttpPutFormContentFilter.class)
public HttpPutFormContentFilter httpPutFormContentFilter() {
public OrderedHttpPutFormContentFilter httpPutFormContentFilter() {
return new OrderedHttpPutFormContentFilter();
}

View File

@@ -41,6 +41,7 @@ import org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebAppl
import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizerBeanPostProcessor;
import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory;
import org.springframework.boot.context.embedded.MockEmbeddedServletContainerFactory;
import org.springframework.boot.context.web.OrderedHttpPutFormContentFilter;
import org.springframework.boot.test.EnvironmentTestUtils;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -51,6 +52,7 @@ import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.test.util.ReflectionTestUtils;
import org.springframework.util.ReflectionUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.filter.HttpPutFormContentFilter;
import org.springframework.web.servlet.HandlerAdapter;
import org.springframework.web.servlet.HandlerMapping;
import org.springframework.web.servlet.LocaleResolver;
@@ -441,6 +443,22 @@ public class WebMvcAutoConfigurationTests {
assertEquals(123456L, actual);
}
@Test
public void httpPutFormContentFilterIsAutoConfigured() {
load();
assertThat(this.context.getBeansOfType(OrderedHttpPutFormContentFilter.class)
.size(), is(equalTo(1)));
}
@Test
public void httpPutFormContentFilterCanBeOverridden() {
load(CustomHttpPutFormContentFilter.class);
assertThat(this.context.getBeansOfType(OrderedHttpPutFormContentFilter.class)
.size(), is(equalTo(0)));
assertThat(this.context.getBeansOfType(HttpPutFormContentFilter.class).size(),
is(equalTo(1)));
}
@SuppressWarnings("unchecked")
private void load(Class<?> config, String... environment) {
this.context = new AnnotationConfigEmbeddedWebApplicationContext();
@@ -552,4 +570,14 @@ public class WebMvcAutoConfigurationTests {
}
@Configuration
static class CustomHttpPutFormContentFilter {
@Bean
public HttpPutFormContentFilter customHttpPutFormContentFilter() {
return new HttpPutFormContentFilter();
}
}
}

View File

@@ -25,7 +25,8 @@ import org.springframework.web.filter.HttpPutFormContentFilter;
* @author Joao Pedro Evangelista
* @since 1.3.0
*/
public class OrderedHttpPutFormContentFilter extends HttpPutFormContentFilter implements Ordered {
public class OrderedHttpPutFormContentFilter extends HttpPutFormContentFilter implements
Ordered {
/**
* Higher order to ensure the filter is applied before Spring Security.