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
5742eeb5
Commit
5742eeb5
authored
Mar 26, 2015
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '1.2.x'
parents
20a2f214
6d2bb68a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
75 additions
and
0 deletions
+75
-0
ErrorPageFilter.java
...org/springframework/boot/context/web/ErrorPageFilter.java
+5
-0
ErrorPageFilterTests.java
...pringframework/boot/context/web/ErrorPageFilterTests.java
+70
-0
No files found.
spring-boot/src/main/java/org/springframework/boot/context/web/ErrorPageFilter.java
View file @
5742eeb5
...
@@ -88,6 +88,11 @@ public class ErrorPageFilter extends AbstractConfigurableEmbeddedServletContaine
...
@@ -88,6 +88,11 @@ public class ErrorPageFilter extends AbstractConfigurableEmbeddedServletContaine
ErrorPageFilter
.
this
.
doFilter
(
request
,
response
,
chain
);
ErrorPageFilter
.
this
.
doFilter
(
request
,
response
,
chain
);
}
}
@Override
protected
boolean
shouldNotFilterAsyncDispatch
()
{
return
false
;
}
};
};
@Override
@Override
...
...
spring-boot/src/test/java/org/springframework/boot/context/web/ErrorPageFilterTests.java
View file @
5742eeb5
...
@@ -34,6 +34,10 @@ import org.springframework.mock.web.MockFilterChain;
...
@@ -34,6 +34,10 @@ import org.springframework.mock.web.MockFilterChain;
import
org.springframework.mock.web.MockFilterConfig
;
import
org.springframework.mock.web.MockFilterConfig
;
import
org.springframework.mock.web.MockHttpServletRequest
;
import
org.springframework.mock.web.MockHttpServletRequest
;
import
org.springframework.mock.web.MockHttpServletResponse
;
import
org.springframework.mock.web.MockHttpServletResponse
;
import
org.springframework.web.context.request.async.DeferredResult
;
import
org.springframework.web.context.request.async.StandardServletAsyncWebRequest
;
import
org.springframework.web.context.request.async.WebAsyncManager
;
import
org.springframework.web.context.request.async.WebAsyncUtils
;
import
static
org
.
hamcrest
.
Matchers
.
containsString
;
import
static
org
.
hamcrest
.
Matchers
.
containsString
;
import
static
org
.
hamcrest
.
Matchers
.
equalTo
;
import
static
org
.
hamcrest
.
Matchers
.
equalTo
;
...
@@ -373,6 +377,62 @@ public class ErrorPageFilterTests {
...
@@ -373,6 +377,62 @@ public class ErrorPageFilterTests {
assertTrue
(
this
.
response
.
isCommitted
());
assertTrue
(
this
.
response
.
isCommitted
());
}
}
@Test
public
void
responseIsNotCommitedDuringAsyncDispatch
()
throws
Exception
{
setUpAsyncDispatch
();
this
.
filter
.
doFilter
(
this
.
request
,
this
.
response
,
this
.
chain
);
assertThat
(
this
.
chain
.
getRequest
(),
equalTo
((
ServletRequest
)
this
.
request
));
assertThat
(((
HttpServletResponseWrapper
)
this
.
chain
.
getResponse
()).
getResponse
(),
equalTo
((
ServletResponse
)
this
.
response
));
assertFalse
(
this
.
response
.
isCommitted
());
}
@Test
public
void
responseIsCommitedWhenExceptionIsThrownDuringAsyncDispatch
()
throws
Exception
{
this
.
filter
.
addErrorPages
(
new
ErrorPage
(
"/error"
));
setUpAsyncDispatch
();
this
.
chain
=
new
MockFilterChain
()
{
@Override
public
void
doFilter
(
ServletRequest
request
,
ServletResponse
response
)
throws
IOException
,
ServletException
{
super
.
doFilter
(
request
,
response
);
throw
new
RuntimeException
(
"BAD"
);
}
};
this
.
filter
.
doFilter
(
this
.
request
,
this
.
response
,
this
.
chain
);
assertThat
(
this
.
chain
.
getRequest
(),
equalTo
((
ServletRequest
)
this
.
request
));
assertThat
(((
HttpServletResponseWrapper
)
this
.
chain
.
getResponse
()).
getResponse
(),
equalTo
((
ServletResponse
)
this
.
response
));
assertTrue
(
this
.
response
.
isCommitted
());
}
@Test
public
void
responseIsCommitedWhenStatusIs400PlusDuringAsyncDispatch
()
throws
Exception
{
this
.
filter
.
addErrorPages
(
new
ErrorPage
(
"/error"
));
setUpAsyncDispatch
();
this
.
chain
=
new
MockFilterChain
()
{
@Override
public
void
doFilter
(
ServletRequest
request
,
ServletResponse
response
)
throws
IOException
,
ServletException
{
super
.
doFilter
(
request
,
response
);
((
HttpServletResponse
)
response
).
sendError
(
400
,
"BAD"
);
}
};
this
.
filter
.
doFilter
(
this
.
request
,
this
.
response
,
this
.
chain
);
assertThat
(
this
.
chain
.
getRequest
(),
equalTo
((
ServletRequest
)
this
.
request
));
assertThat
(((
HttpServletResponseWrapper
)
this
.
chain
.
getResponse
()).
getResponse
(),
equalTo
((
ServletResponse
)
this
.
response
));
assertTrue
(
this
.
response
.
isCommitted
());
}
@Test
@Test
public
void
responseIsNotFlushedIfStatusIsLessThan400AndItHasAlreadyBeenCommitted
()
public
void
responseIsNotFlushedIfStatusIsLessThan400AndItHasAlreadyBeenCommitted
()
throws
Exception
{
throws
Exception
{
...
@@ -419,4 +479,14 @@ public class ErrorPageFilterTests {
...
@@ -419,4 +479,14 @@ public class ErrorPageFilterTests {
assertThat
(
this
.
output
.
toString
(),
containsString
(
"request [/test/alpha]"
));
assertThat
(
this
.
output
.
toString
(),
containsString
(
"request [/test/alpha]"
));
}
}
private
void
setUpAsyncDispatch
()
throws
Exception
{
this
.
request
.
setAsyncSupported
(
true
);
this
.
request
.
setAsyncStarted
(
true
);
DeferredResult
<
String
>
result
=
new
DeferredResult
<
String
>();
WebAsyncManager
asyncManager
=
WebAsyncUtils
.
getAsyncManager
(
this
.
request
);
asyncManager
.
setAsyncWebRequest
(
new
StandardServletAsyncWebRequest
(
this
.
request
,
this
.
response
));
asyncManager
.
startDeferredResultProcessing
(
result
);
}
}
}
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