Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
51fd27fa
Commit
51fd27fa
authored
Aug 17, 2018
by
artsiom
Committed by
Brian Clozel
Aug 17, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Configure HiddenHttpMethodFilter for Spring WebFlux
Closes gh-14008
parent
22bc2bd7
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
91 additions
and
0 deletions
+91
-0
WebFluxAutoConfiguration.java
.../autoconfigure/web/reactive/WebFluxAutoConfiguration.java
+9
-0
WebFluxAutoConfigurationTests.java
...configure/web/reactive/WebFluxAutoConfigurationTests.java
+29
-0
OrderedHiddenHttpMethodFilter.java
...ot/web/reactive/filter/OrderedHiddenHttpMethodFilter.java
+53
-0
No files found.
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/WebFluxAutoConfiguration.java
View file @
51fd27fa
...
...
@@ -41,6 +41,7 @@ import org.springframework.boot.autoconfigure.web.ResourceProperties;
import
org.springframework.boot.autoconfigure.web.format.WebConversionService
;
import
org.springframework.boot.context.properties.EnableConfigurationProperties
;
import
org.springframework.boot.web.codec.CodecCustomizer
;
import
org.springframework.boot.web.reactive.filter.OrderedHiddenHttpMethodFilter
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Import
;
...
...
@@ -55,6 +56,7 @@ import org.springframework.http.CacheControl;
import
org.springframework.http.codec.ServerCodecConfigurer
;
import
org.springframework.util.ClassUtils
;
import
org.springframework.validation.Validator
;
import
org.springframework.web.filter.reactive.HiddenHttpMethodFilter
;
import
org.springframework.web.reactive.config.DelegatingWebFluxConfiguration
;
import
org.springframework.web.reactive.config.EnableWebFlux
;
import
org.springframework.web.reactive.config.ResourceChainRegistration
;
...
...
@@ -80,6 +82,7 @@ import org.springframework.web.reactive.result.view.ViewResolver;
* @author Andy Wilkinson
* @author Phillip Webb
* @author Eddú Meléndez
* @author Artsiom Yudovin
* @since 2.0.0
*/
@Configuration
...
...
@@ -91,6 +94,12 @@ import org.springframework.web.reactive.result.view.ViewResolver;
@AutoConfigureOrder
(
Ordered
.
HIGHEST_PRECEDENCE
+
10
)
public
class
WebFluxAutoConfiguration
{
@Bean
@ConditionalOnMissingBean
(
HiddenHttpMethodFilter
.
class
)
public
OrderedHiddenHttpMethodFilter
hiddenHttpMethodFilter
()
{
return
new
OrderedHiddenHttpMethodFilter
();
}
@Configuration
@EnableConfigurationProperties
({
ResourceProperties
.
class
,
WebFluxProperties
.
class
})
@Import
({
EnableWebFluxConfiguration
.
class
})
...
...
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/WebFluxAutoConfigurationTests.java
View file @
51fd27fa
...
...
@@ -30,6 +30,7 @@ import org.springframework.boot.autoconfigure.validation.ValidationAutoConfigura
import
org.springframework.boot.autoconfigure.validation.ValidatorAdapter
;
import
org.springframework.boot.test.context.runner.ReactiveWebApplicationContextRunner
;
import
org.springframework.boot.web.codec.CodecCustomizer
;
import
org.springframework.boot.web.reactive.filter.OrderedHiddenHttpMethodFilter
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.core.Ordered
;
...
...
@@ -41,6 +42,7 @@ import org.springframework.http.server.reactive.HttpHandler;
import
org.springframework.test.util.ReflectionTestUtils
;
import
org.springframework.validation.Validator
;
import
org.springframework.validation.beanvalidation.LocalValidatorFactoryBean
;
import
org.springframework.web.filter.reactive.HiddenHttpMethodFilter
;
import
org.springframework.web.reactive.HandlerMapping
;
import
org.springframework.web.reactive.accept.RequestedContentTypeResolver
;
import
org.springframework.web.reactive.config.WebFluxConfigurationSupport
;
...
...
@@ -66,6 +68,7 @@ import static org.mockito.Mockito.verify;
*
* @author Brian Clozel
* @author Andy Wilkinson
* @author Artsiom Yudovin
*/
public
class
WebFluxAutoConfigurationTests
{
...
...
@@ -351,6 +354,22 @@ public class WebFluxAutoConfigurationTests {
});
}
@Test
public
void
hiddenHttpMethodFilterIsAutoConfigured
()
{
this
.
contextRunner
.
run
((
context
)
->
assertThat
(
context
)
.
hasSingleBean
(
OrderedHiddenHttpMethodFilter
.
class
));
}
@Test
public
void
hiddenHttpMethodFilterCanBeOverridden
()
{
this
.
contextRunner
.
withUserConfiguration
(
CustomHiddenHttpMethodFilter
.
class
)
.
run
((
context
)
->
{
assertThat
(
context
)
.
doesNotHaveBean
(
OrderedHiddenHttpMethodFilter
.
class
);
assertThat
(
context
).
hasSingleBean
(
HiddenHttpMethodFilter
.
class
);
});
}
@Configuration
protected
static
class
CustomArgumentResolvers
{
...
...
@@ -456,4 +475,14 @@ public class WebFluxAutoConfigurationTests {
}
@Configuration
static
class
CustomHiddenHttpMethodFilter
{
@Bean
public
HiddenHttpMethodFilter
customHiddenHttpMethodFilter
()
{
return
mock
(
HiddenHttpMethodFilter
.
class
);
}
}
}
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/reactive/filter/OrderedHiddenHttpMethodFilter.java
0 → 100644
View file @
51fd27fa
/*
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org
.
springframework
.
boot
.
web
.
reactive
.
filter
;
import
org.springframework.boot.web.servlet.FilterRegistrationBean
;
import
org.springframework.core.Ordered
;
import
org.springframework.web.filter.reactive.HiddenHttpMethodFilter
;
/**
* {@link HiddenHttpMethodFilter} that also implements {@link Ordered}.
*
* @author Artsiom Yudovin
* @since 2.0.5
*/
public
class
OrderedHiddenHttpMethodFilter
extends
HiddenHttpMethodFilter
implements
Ordered
{
/**
* The default order is high to ensure the filter is applied before Spring Security.
*/
public
static
final
int
DEFAULT_ORDER
=
FilterRegistrationBean
.
REQUEST_WRAPPER_FILTER_MAX_ORDER
-
10000
;
private
int
order
=
DEFAULT_ORDER
;
@Override
public
int
getOrder
()
{
return
this
.
order
;
}
/**
* Set the order for this filter.
* @param order the order to set
*/
public
void
setOrder
(
int
order
)
{
this
.
order
=
order
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment