Commit c3e447c8 authored by Andy Wilkinson's avatar Andy Wilkinson

Order char encoding filter so it sets encoding before request is read

For the character encoding filter to work, it's vital that it sets
the request's encoding before any other filters attempt to read the
request. This commit updates the order of
OrderedCharacterEncodingFilter to be HIGHEST_PRECEDENCE and improves
the existing test to check that the ordering is as required.

Closes gh-3912
parent 702b8d04
...@@ -27,6 +27,8 @@ import org.junit.Test; ...@@ -27,6 +27,8 @@ import org.junit.Test;
import org.junit.rules.ExpectedException; import org.junit.rules.ExpectedException;
import org.springframework.beans.DirectFieldAccessor; import org.springframework.beans.DirectFieldAccessor;
import org.springframework.beans.factory.NoSuchBeanDefinitionException; import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.boot.context.web.OrderedHiddenHttpMethodFilter;
import org.springframework.boot.context.web.OrderedHttpPutFormContentFilter;
import org.springframework.boot.test.EnvironmentTestUtils; import org.springframework.boot.test.EnvironmentTestUtils;
import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
...@@ -145,8 +147,13 @@ public class HttpEncodingAutoConfigurationTests { ...@@ -145,8 +147,13 @@ public class HttpEncodingAutoConfigurationTests {
static class OrderedConfiguration { static class OrderedConfiguration {
@Bean @Bean
public HiddenHttpMethodFilter hiddenHttpMethodFilter() { public OrderedHiddenHttpMethodFilter hiddenHttpMethodFilter() {
return new HiddenHttpMethodFilter(); return new OrderedHiddenHttpMethodFilter();
}
@Bean
public OrderedHttpPutFormContentFilter httpPutFormContentFilter() {
return new OrderedHttpPutFormContentFilter();
} }
} }
......
...@@ -16,7 +16,6 @@ ...@@ -16,7 +16,6 @@
package org.springframework.boot.context.web; package org.springframework.boot.context.web;
import org.springframework.boot.context.embedded.FilterRegistrationBean;
import org.springframework.core.Ordered; import org.springframework.core.Ordered;
import org.springframework.web.filter.CharacterEncodingFilter; import org.springframework.web.filter.CharacterEncodingFilter;
...@@ -29,7 +28,7 @@ import org.springframework.web.filter.CharacterEncodingFilter; ...@@ -29,7 +28,7 @@ import org.springframework.web.filter.CharacterEncodingFilter;
public class OrderedCharacterEncodingFilter extends CharacterEncodingFilter implements public class OrderedCharacterEncodingFilter extends CharacterEncodingFilter implements
Ordered { Ordered {
private int order = FilterRegistrationBean.REQUEST_WRAPPER_FILTER_MAX_ORDER - 9800; private int order = Ordered.HIGHEST_PRECEDENCE;
@Override @Override
public int getOrder() { public int getOrder() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment