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
5a74f63f
Commit
5a74f63f
authored
Jan 29, 2018
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Polish "Configure ErrorReportValve not to report stack traces"
Closes gh-11790
parent
29736e34
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
68 additions
and
32 deletions
+68
-32
ServerProperties.java
...ingframework/boot/autoconfigure/web/ServerProperties.java
+19
-20
ServerPropertiesTests.java
...amework/boot/autoconfigure/web/ServerPropertiesTests.java
+25
-10
TomcatEmbeddedServletContainerFactory.java
...mbedded/tomcat/TomcatEmbeddedServletContainerFactory.java
+1
-1
TomcatEmbeddedServletContainerFactoryTests.java
...ed/tomcat/TomcatEmbeddedServletContainerFactoryTests.java
+23
-1
No files found.
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerProperties.java
View file @
5a74f63f
/*
/*
* Copyright 2012-201
7
the original author or authors.
* Copyright 2012-201
8
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.
...
@@ -38,7 +38,6 @@ import org.apache.catalina.connector.Connector;
...
@@ -38,7 +38,6 @@ import org.apache.catalina.connector.Connector;
import
org.apache.catalina.valves.AccessLogValve
;
import
org.apache.catalina.valves.AccessLogValve
;
import
org.apache.catalina.valves.ErrorReportValve
;
import
org.apache.catalina.valves.ErrorReportValve
;
import
org.apache.catalina.valves.RemoteIpValve
;
import
org.apache.catalina.valves.RemoteIpValve
;
import
org.apache.commons.logging.LogFactory
;
import
org.apache.coyote.AbstractProtocol
;
import
org.apache.coyote.AbstractProtocol
;
import
org.apache.coyote.ProtocolHandler
;
import
org.apache.coyote.ProtocolHandler
;
import
org.apache.coyote.http11.AbstractHttp11Protocol
;
import
org.apache.coyote.http11.AbstractHttp11Protocol
;
...
@@ -861,27 +860,27 @@ public class ServerProperties
...
@@ -861,27 +860,27 @@ public class ServerProperties
if
(!
ObjectUtils
.
isEmpty
(
this
.
additionalTldSkipPatterns
))
{
if
(!
ObjectUtils
.
isEmpty
(
this
.
additionalTldSkipPatterns
))
{
factory
.
getTldSkipPatterns
().
addAll
(
this
.
additionalTldSkipPatterns
);
factory
.
getTldSkipPatterns
().
addAll
(
this
.
additionalTldSkipPatterns
);
}
}
if
(
serverProperties
.
getError
().
getIncludeStacktrace
()
==
ErrorProperties
.
IncludeStacktrace
.
NEVER
)
{
if
(
serverProperties
.
getError
()
factory
.
addContextCustomizers
(
new
TomcatContextCustomizer
()
{
.
getIncludeStacktrace
()
==
ErrorProperties
.
IncludeStacktrace
.
NEVER
)
{
@Override
customizeErrorReportValve
(
factory
);
public
void
customize
(
Context
context
)
{
// org.apache.catalina.core.StandardHost() adds ErrorReportValve
// with default options if not there yet, so adding a properly
// configured one.
ErrorReportValve
valve
=
new
ErrorReportValve
();
valve
.
setShowServerInfo
(
false
);
// disable server name and version
valve
.
setShowReport
(
false
);
// disable exception
if
(
context
.
getParent
()
!=
null
)
{
context
.
getParent
().
getPipeline
().
addValve
(
valve
);
}
else
{
LogFactory
.
getLog
(
context
.
getClass
()).
warn
(
"Parent of "
+
context
+
" is not set, skip ErrorReportValve configuration"
);
}
}
});
}
}
}
}
private
void
customizeErrorReportValve
(
TomcatEmbeddedServletContainerFactory
factory
)
{
factory
.
addContextCustomizers
(
new
TomcatContextCustomizer
()
{
@Override
public
void
customize
(
Context
context
)
{
ErrorReportValve
valve
=
new
ErrorReportValve
();
valve
.
setShowServerInfo
(
false
);
valve
.
setShowReport
(
false
);
context
.
getParent
().
getPipeline
().
addValve
(
valve
);
}
});
}
private
void
customizeAcceptCount
(
TomcatEmbeddedServletContainerFactory
factory
)
{
private
void
customizeAcceptCount
(
TomcatEmbeddedServletContainerFactory
factory
)
{
factory
.
addConnectorCustomizers
(
new
TomcatConnectorCustomizer
()
{
factory
.
addConnectorCustomizers
(
new
TomcatConnectorCustomizer
()
{
...
...
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ServerPropertiesTests.java
View file @
5a74f63f
/*
/*
* Copyright 2012-201
7
the original author or authors.
* Copyright 2012-201
8
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.
...
@@ -32,6 +32,7 @@ import javax.servlet.SessionTrackingMode;
...
@@ -32,6 +32,7 @@ import javax.servlet.SessionTrackingMode;
import
org.apache.catalina.Context
;
import
org.apache.catalina.Context
;
import
org.apache.catalina.Valve
;
import
org.apache.catalina.Valve
;
import
org.apache.catalina.valves.AccessLogValve
;
import
org.apache.catalina.valves.AccessLogValve
;
import
org.apache.catalina.valves.ErrorReportValve
;
import
org.apache.catalina.valves.RemoteIpValve
;
import
org.apache.catalina.valves.RemoteIpValve
;
import
org.apache.coyote.AbstractProtocol
;
import
org.apache.coyote.AbstractProtocol
;
import
org.junit.Before
;
import
org.junit.Before
;
...
@@ -45,7 +46,6 @@ import org.springframework.boot.bind.RelaxedDataBinder;
...
@@ -45,7 +46,6 @@ import org.springframework.boot.bind.RelaxedDataBinder;
import
org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainer
;
import
org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainer
;
import
org.springframework.boot.context.embedded.EmbeddedServletContainer
;
import
org.springframework.boot.context.embedded.EmbeddedServletContainer
;
import
org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletContainerFactory
;
import
org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletContainerFactory
;
import
org.springframework.boot.context.embedded.tomcat.TomcatContextCustomizer
;
import
org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer
;
import
org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer
;
import
org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory
;
import
org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory
;
import
org.springframework.boot.context.embedded.undertow.UndertowEmbeddedServletContainerFactory
;
import
org.springframework.boot.context.embedded.undertow.UndertowEmbeddedServletContainerFactory
;
...
@@ -235,6 +235,25 @@ public class ServerPropertiesTests {
...
@@ -235,6 +235,25 @@ public class ServerPropertiesTests {
assertThat
(
tomcat
.
getBackgroundProcessorDelay
()).
isEqualTo
(
10
);
assertThat
(
tomcat
.
getBackgroundProcessorDelay
()).
isEqualTo
(
10
);
}
}
@Test
public
void
errorReportValveIsConfiguredToNotReportStackTraces
()
{
TomcatEmbeddedServletContainerFactory
tomcatContainer
=
new
TomcatEmbeddedServletContainerFactory
();
Map
<
String
,
String
>
map
=
new
HashMap
<
String
,
String
>();
bindProperties
(
map
);
this
.
properties
.
customize
(
tomcatContainer
);
Valve
[]
valves
=
((
TomcatEmbeddedServletContainer
)
tomcatContainer
.
getEmbeddedServletContainer
()).
getTomcat
().
getHost
().
getPipeline
()
.
getValves
();
assertThat
(
valves
).
hasAtLeastOneElementOfType
(
ErrorReportValve
.
class
);
for
(
Valve
valve
:
valves
)
{
if
(
valve
instanceof
ErrorReportValve
)
{
ErrorReportValve
errorReportValve
=
(
ErrorReportValve
)
valve
;
assertThat
(
errorReportValve
.
isShowReport
()).
isFalse
();
assertThat
(
errorReportValve
.
isShowServerInfo
()).
isFalse
();
}
}
}
@Test
@Test
public
void
redirectContextRootIsNotConfiguredByDefault
()
throws
Exception
{
public
void
redirectContextRootIsNotConfiguredByDefault
()
throws
Exception
{
bindProperties
(
new
HashMap
<
String
,
String
>());
bindProperties
(
new
HashMap
<
String
,
String
>());
...
@@ -249,14 +268,10 @@ public class ServerPropertiesTests {
...
@@ -249,14 +268,10 @@ public class ServerPropertiesTests {
bindProperties
(
map
);
bindProperties
(
map
);
ServerProperties
.
Tomcat
tomcat
=
this
.
properties
.
getTomcat
();
ServerProperties
.
Tomcat
tomcat
=
this
.
properties
.
getTomcat
();
assertThat
(
tomcat
.
getRedirectContextRoot
()).
isEqualTo
(
false
);
assertThat
(
tomcat
.
getRedirectContextRoot
()).
isEqualTo
(
false
);
TomcatEmbeddedServletContainerFactory
container
=
new
TomcatEmbeddedServletContainerFactory
();
TomcatEmbeddedServletContainerFactory
factory
=
new
TomcatEmbeddedServletContainerFactory
();
this
.
properties
.
customize
(
container
);
Context
context
=
(
Context
)
((
TomcatEmbeddedServletContainer
)
factory
Context
context
=
mock
(
Context
.
class
);
.
getEmbeddedServletContainer
()).
getTomcat
().
getHost
().
findChildren
()[
0
];
for
(
TomcatContextCustomizer
customizer
:
container
assertThat
(
context
.
getMapperContextRootRedirectEnabled
()).
isTrue
();
.
getTomcatContextCustomizers
())
{
customizer
.
customize
(
context
);
}
verify
(
context
).
setMapperContextRootRedirectEnabled
(
false
);
}
}
@Test
@Test
...
...
spring-boot/src/main/java/org/springframework/boot/context/embedded/tomcat/TomcatEmbeddedServletContainerFactory.java
View file @
5a74f63f
/*
/*
* Copyright 2012-201
7
the original author or authors.
* Copyright 2012-201
8
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.
...
...
spring-boot/src/test/java/org/springframework/boot/context/embedded/tomcat/TomcatEmbeddedServletContainerFactoryTests.java
View file @
5a74f63f
/*
/*
* Copyright 2012-201
7
the original author or authors.
* Copyright 2012-201
8
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.
...
@@ -53,6 +53,8 @@ import org.junit.After;
...
@@ -53,6 +53,8 @@ import org.junit.After;
import
org.junit.Rule
;
import
org.junit.Rule
;
import
org.junit.Test
;
import
org.junit.Test
;
import
org.mockito.InOrder
;
import
org.mockito.InOrder
;
import
org.mockito.invocation.InvocationOnMock
;
import
org.mockito.stubbing.Answer
;
import
org.springframework.boot.context.embedded.AbstractEmbeddedServletContainerFactory
;
import
org.springframework.boot.context.embedded.AbstractEmbeddedServletContainerFactory
;
import
org.springframework.boot.context.embedded.AbstractEmbeddedServletContainerFactoryTests
;
import
org.springframework.boot.context.embedded.AbstractEmbeddedServletContainerFactoryTests
;
...
@@ -68,6 +70,7 @@ import static org.junit.Assert.fail;
...
@@ -68,6 +70,7 @@ import static org.junit.Assert.fail;
import
static
org
.
mockito
.
BDDMockito
.
given
;
import
static
org
.
mockito
.
BDDMockito
.
given
;
import
static
org
.
mockito
.
Matchers
.
any
;
import
static
org
.
mockito
.
Matchers
.
any
;
import
static
org
.
mockito
.
Matchers
.
anyObject
;
import
static
org
.
mockito
.
Matchers
.
anyObject
;
import
static
org
.
mockito
.
Mockito
.
doAnswer
;
import
static
org
.
mockito
.
Mockito
.
inOrder
;
import
static
org
.
mockito
.
Mockito
.
inOrder
;
import
static
org
.
mockito
.
Mockito
.
mock
;
import
static
org
.
mockito
.
Mockito
.
mock
;
import
static
org
.
mockito
.
Mockito
.
verify
;
import
static
org
.
mockito
.
Mockito
.
verify
;
...
@@ -146,6 +149,25 @@ public class TomcatEmbeddedServletContainerFactoryTests
...
@@ -146,6 +149,25 @@ public class TomcatEmbeddedServletContainerFactoryTests
}
}
}
}
@Test
public
void
contextIsAddedToHostBeforeCustomizersAreCalled
()
throws
Exception
{
TomcatEmbeddedServletContainerFactory
factory
=
getFactory
();
TomcatContextCustomizer
customizer
=
mock
(
TomcatContextCustomizer
.
class
);
doAnswer
(
new
Answer
<
Void
>()
{
@Override
public
Void
answer
(
InvocationOnMock
invocation
)
throws
Throwable
{
assertThat
(((
Context
)
invocation
.
getArguments
()[
0
]).
getParent
())
.
isNotNull
();
return
null
;
}
}).
when
(
customizer
).
customize
(
any
(
Context
.
class
));
factory
.
addContextCustomizers
(
customizer
);
this
.
container
=
factory
.
getEmbeddedServletContainer
();
verify
(
customizer
).
customize
(
any
(
Context
.
class
));
}
@Test
@Test
public
void
tomcatConnectorCustomizers
()
throws
Exception
{
public
void
tomcatConnectorCustomizers
()
throws
Exception
{
TomcatEmbeddedServletContainerFactory
factory
=
getFactory
();
TomcatEmbeddedServletContainerFactory
factory
=
getFactory
();
...
...
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