|
36 | 36 | import org.apache.catalina.Context;
|
37 | 37 | import org.apache.catalina.connector.Connector;
|
38 | 38 | import org.apache.catalina.valves.AccessLogValve;
|
| 39 | +import org.apache.catalina.valves.ErrorReportValve; |
39 | 40 | import org.apache.catalina.valves.RemoteIpValve;
|
| 41 | +import org.apache.commons.logging.LogFactory; |
40 | 42 | import org.apache.coyote.AbstractProtocol;
|
41 | 43 | import org.apache.coyote.ProtocolHandler;
|
42 | 44 | import org.apache.coyote.http11.AbstractHttp11Protocol;
|
@@ -859,6 +861,25 @@ void customizeTomcat(ServerProperties serverProperties,
|
859 | 861 | if (!ObjectUtils.isEmpty(this.additionalTldSkipPatterns)) {
|
860 | 862 | factory.getTldSkipPatterns().addAll(this.additionalTldSkipPatterns);
|
861 | 863 | }
|
| 864 | + if (serverProperties.getError().getIncludeStacktrace() == ErrorProperties.IncludeStacktrace.NEVER) { |
| 865 | + factory.addContextCustomizers(new TomcatContextCustomizer() { |
| 866 | + @Override |
| 867 | + public void customize(Context context) { |
| 868 | + // org.apache.catalina.core.StandardHost() adds ErrorReportValve |
| 869 | + // with default options if not there yet, so adding a properly |
| 870 | + // configured one. |
| 871 | + ErrorReportValve valve = new ErrorReportValve(); |
| 872 | + valve.setShowServerInfo(false); // disable server name and version |
| 873 | + valve.setShowReport(false); // disable exception |
| 874 | + if (context.getParent() != null) { |
| 875 | + context.getParent().getPipeline().addValve(valve); |
| 876 | + } else { |
| 877 | + LogFactory.getLog(context.getClass()).warn("Parent of " + context |
| 878 | + + " is not set, skip ErrorReportValve configuration"); |
| 879 | + } |
| 880 | + } |
| 881 | + }); |
| 882 | + } |
862 | 883 | }
|
863 | 884 |
|
864 | 885 | private void customizeAcceptCount(TomcatEmbeddedServletContainerFactory factory) {
|
|
0 commit comments