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
02a6de44
Commit
02a6de44
authored
Mar 24, 2021
by
Phillip Webb
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '2.4.x'
Closes gh-25787
parents
38584f06
ddf5c9f5
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
5 deletions
+25
-5
DefaultErrorWebExceptionHandler.java
...e/web/reactive/error/DefaultErrorWebExceptionHandler.java
+2
-2
DefaultErrorWebExceptionHandlerTests.java
.../reactive/error/DefaultErrorWebExceptionHandlerTests.java
+23
-3
No files found.
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/error/DefaultErrorWebExceptionHandler.java
View file @
02a6de44
/*
/*
* Copyright 2012-202
0
the original author or authors.
* Copyright 2012-202
1
the original author or authors.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
...
@@ -252,7 +252,7 @@ public class DefaultErrorWebExceptionHandler extends AbstractErrorWebExceptionHa
...
@@ -252,7 +252,7 @@ public class DefaultErrorWebExceptionHandler extends AbstractErrorWebExceptionHa
return
(
serverRequest
)
->
{
return
(
serverRequest
)
->
{
try
{
try
{
List
<
MediaType
>
acceptedMediaTypes
=
serverRequest
.
headers
().
accept
();
List
<
MediaType
>
acceptedMediaTypes
=
serverRequest
.
headers
().
accept
();
acceptedMediaTypes
.
remove
(
MediaType
.
ALL
);
acceptedMediaTypes
.
remove
If
(
MediaType
.
ALL
::
equalsTypeAndSubtype
);
MediaType
.
sortBySpecificityAndQuality
(
acceptedMediaTypes
);
MediaType
.
sortBySpecificityAndQuality
(
acceptedMediaTypes
);
return
acceptedMediaTypes
.
stream
().
anyMatch
(
MediaType
.
TEXT_HTML
::
isCompatibleWith
);
return
acceptedMediaTypes
.
stream
().
anyMatch
(
MediaType
.
TEXT_HTML
::
isCompatibleWith
);
}
}
...
...
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/error/DefaultErrorWebExceptionHandlerTests.java
View file @
02a6de44
/*
/*
* Copyright 2012-202
0
the original author or authors.
* Copyright 2012-202
1
the original author or authors.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
...
@@ -17,6 +17,7 @@
...
@@ -17,6 +17,7 @@
package
org
.
springframework
.
boot
.
autoconfigure
.
web
.
reactive
.
error
;
package
org
.
springframework
.
boot
.
autoconfigure
.
web
.
reactive
.
error
;
import
java.util.Collections
;
import
java.util.Collections
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.Test
;
...
@@ -28,9 +29,12 @@ import org.springframework.boot.web.reactive.context.AnnotationConfigReactiveWeb
...
@@ -28,9 +29,12 @@ import org.springframework.boot.web.reactive.context.AnnotationConfigReactiveWeb
import
org.springframework.boot.web.reactive.error.ErrorAttributes
;
import
org.springframework.boot.web.reactive.error.ErrorAttributes
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.http.MediaType
;
import
org.springframework.http.MediaType
;
import
org.springframework.http.codec.HttpMessageReader
;
import
org.springframework.http.codec.ServerCodecConfigurer
;
import
org.springframework.mock.http.server.reactive.MockServerHttpRequest
;
import
org.springframework.mock.http.server.reactive.MockServerHttpRequest
;
import
org.springframework.mock.web.server.MockServerWebExchange
;
import
org.springframework.mock.web.server.MockServerWebExchange
;
import
org.springframework.test.util.ReflectionTestUtils
;
import
org.springframework.test.util.ReflectionTestUtils
;
import
org.springframework.web.reactive.function.server.ServerRequest
;
import
org.springframework.web.reactive.result.view.View
;
import
org.springframework.web.reactive.result.view.View
;
import
org.springframework.web.reactive.result.view.ViewResolver
;
import
org.springframework.web.reactive.result.view.ViewResolver
;
import
org.springframework.web.server.ServerWebExchange
;
import
org.springframework.web.server.ServerWebExchange
;
...
@@ -42,7 +46,7 @@ import static org.mockito.BDDMockito.given;
...
@@ -42,7 +46,7 @@ import static org.mockito.BDDMockito.given;
import
static
org
.
mockito
.
Mockito
.
mock
;
import
static
org
.
mockito
.
Mockito
.
mock
;
/**
/**
* Tests for {@link
Abstrac
tErrorWebExceptionHandler}.
* Tests for {@link
Defaul
tErrorWebExceptionHandler}.
*
*
* @author Phillip Webb
* @author Phillip Webb
* @author Madhura Bhave
* @author Madhura Bhave
...
@@ -62,10 +66,10 @@ class DefaultErrorWebExceptionHandlerTests {
...
@@ -62,10 +66,10 @@ class DefaultErrorWebExceptionHandlerTests {
@Test
@Test
void
nonStandardErrorStatusCodeShouldNotFail
()
{
void
nonStandardErrorStatusCodeShouldNotFail
()
{
ErrorAttributes
errorAttributes
=
mock
(
ErrorAttributes
.
class
);
ErrorAttributes
errorAttributes
=
mock
(
ErrorAttributes
.
class
);
given
(
errorAttributes
.
getErrorAttributes
(
any
(),
any
())).
willReturn
(
getErrorAttributes
());
Resources
resourceProperties
=
new
Resources
();
Resources
resourceProperties
=
new
Resources
();
ErrorProperties
errorProperties
=
new
ErrorProperties
();
ErrorProperties
errorProperties
=
new
ErrorProperties
();
ApplicationContext
context
=
new
AnnotationConfigReactiveWebApplicationContext
();
ApplicationContext
context
=
new
AnnotationConfigReactiveWebApplicationContext
();
given
(
errorAttributes
.
getErrorAttributes
(
any
(),
any
())).
willReturn
(
getErrorAttributes
());
DefaultErrorWebExceptionHandler
exceptionHandler
=
new
DefaultErrorWebExceptionHandler
(
errorAttributes
,
DefaultErrorWebExceptionHandler
exceptionHandler
=
new
DefaultErrorWebExceptionHandler
(
errorAttributes
,
resourceProperties
,
errorProperties
,
context
);
resourceProperties
,
errorProperties
,
context
);
setupViewResolver
(
exceptionHandler
);
setupViewResolver
(
exceptionHandler
);
...
@@ -86,4 +90,20 @@ class DefaultErrorWebExceptionHandlerTests {
...
@@ -86,4 +90,20 @@ class DefaultErrorWebExceptionHandlerTests {
exceptionHandler
.
setViewResolvers
(
Collections
.
singletonList
(
viewResolver
));
exceptionHandler
.
setViewResolvers
(
Collections
.
singletonList
(
viewResolver
));
}
}
@Test
void
acceptsTextHtmlShouldNotConsiderMediaAllEvenWithQuality
()
{
ErrorAttributes
errorAttributes
=
mock
(
ErrorAttributes
.
class
);
Resources
resourceProperties
=
new
Resources
();
ErrorProperties
errorProperties
=
new
ErrorProperties
();
ApplicationContext
context
=
new
AnnotationConfigReactiveWebApplicationContext
();
DefaultErrorWebExceptionHandler
exceptionHandler
=
new
DefaultErrorWebExceptionHandler
(
errorAttributes
,
resourceProperties
,
errorProperties
,
context
);
MediaType
allWithQuality
=
new
MediaType
(
MediaType
.
ALL
.
getType
(),
MediaType
.
ALL
.
getSubtype
(),
0.9
);
MockServerWebExchange
exchange
=
MockServerWebExchange
.
from
(
MockServerHttpRequest
.
get
(
"/test"
).
accept
(
allWithQuality
));
List
<
HttpMessageReader
<?>>
readers
=
ServerCodecConfigurer
.
create
().
getReaders
();
ServerRequest
request
=
ServerRequest
.
create
(
exchange
,
readers
);
assertThat
(
exceptionHandler
.
acceptsTextHtml
().
test
(
request
)).
isFalse
();
}
}
}
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