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
6307cb59
Commit
6307cb59
authored
Jan 11, 2019
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Disable Tomcat’s reference clearing
Closes gh-15101
parent
82a77a35
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
79 additions
and
4 deletions
+79
-4
DisableReferenceClearingContextCustomizer.java
...ded/tomcat/DisableReferenceClearingContextCustomizer.java
+47
-0
TomcatReactiveWebServerFactory.java
...t/web/embedded/tomcat/TomcatReactiveWebServerFactory.java
+2
-1
TomcatServletWebServerFactory.java
...ot/web/embedded/tomcat/TomcatServletWebServerFactory.java
+2
-1
TomcatReactiveWebServerFactoryTests.java
.../embedded/tomcat/TomcatReactiveWebServerFactoryTests.java
+15
-1
TomcatServletWebServerFactoryTests.java
...b/embedded/tomcat/TomcatServletWebServerFactoryTests.java
+13
-1
No files found.
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/tomcat/DisableReferenceClearingContextCustomizer.java
0 → 100644
View file @
6307cb59
/*
* Copyright 2012-2019 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
.
embedded
.
tomcat
;
import
org.apache.catalina.Context
;
import
org.apache.catalina.core.StandardContext
;
/**
* A {@link TomcatContextCustomizer} that disables Tomcat's reflective reference clearing
* to avoid reflective access warnings on Java 9 and later JVMs.
*
* @author Andy Wilkinson
*/
class
DisableReferenceClearingContextCustomizer
implements
TomcatContextCustomizer
{
@Override
public
void
customize
(
Context
context
)
{
if
(!(
context
instanceof
StandardContext
))
{
return
;
}
StandardContext
standardContext
=
(
StandardContext
)
context
;
try
{
standardContext
.
setClearReferencesObjectStreamClassCaches
(
false
);
standardContext
.
setClearReferencesRmiTargets
(
false
);
standardContext
.
setClearReferencesThreadLocals
(
false
);
}
catch
(
NoSuchMethodError
ex
)
{
// Earlier version of Tomcat (probably without
// setClearReferencesThreadLocals). Continue.
}
}
}
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/tomcat/TomcatReactiveWebServerFactory.java
View file @
6307cb59
/*
/*
* Copyright 2012-201
8
the original author or authors.
* Copyright 2012-201
9
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.
...
@@ -149,6 +149,7 @@ public class TomcatReactiveWebServerFactory extends AbstractReactiveWebServerFac
...
@@ -149,6 +149,7 @@ public class TomcatReactiveWebServerFactory extends AbstractReactiveWebServerFac
*/
*/
protected
void
configureContext
(
Context
context
)
{
protected
void
configureContext
(
Context
context
)
{
this
.
contextLifecycleListeners
.
forEach
(
context:
:
addLifecycleListener
);
this
.
contextLifecycleListeners
.
forEach
(
context:
:
addLifecycleListener
);
new
DisableReferenceClearingContextCustomizer
().
customize
(
context
);
this
.
tomcatContextCustomizers
this
.
tomcatContextCustomizers
.
forEach
((
customizer
)
->
customizer
.
customize
(
context
));
.
forEach
((
customizer
)
->
customizer
.
customize
(
context
));
}
}
...
...
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/tomcat/TomcatServletWebServerFactory.java
View file @
6307cb59
/*
/*
* Copyright 2012-201
8
the original author or authors.
* Copyright 2012-201
9
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.
...
@@ -347,6 +347,7 @@ public class TomcatServletWebServerFactory extends AbstractServletWebServerFacto
...
@@ -347,6 +347,7 @@ public class TomcatServletWebServerFactory extends AbstractServletWebServerFacto
context
.
addMimeMapping
(
mapping
.
getExtension
(),
mapping
.
getMimeType
());
context
.
addMimeMapping
(
mapping
.
getExtension
(),
mapping
.
getMimeType
());
}
}
configureSession
(
context
);
configureSession
(
context
);
new
DisableReferenceClearingContextCustomizer
().
customize
(
context
);
for
(
TomcatContextCustomizer
customizer
:
this
.
tomcatContextCustomizers
)
{
for
(
TomcatContextCustomizer
customizer
:
this
.
tomcatContextCustomizers
)
{
customizer
.
customize
(
context
);
customizer
.
customize
(
context
);
}
}
...
...
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/embedded/tomcat/TomcatReactiveWebServerFactoryTests.java
View file @
6307cb59
/*
/*
* Copyright 2012-201
8
the original author or authors.
* Copyright 2012-201
9
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.
...
@@ -23,6 +23,8 @@ import org.apache.catalina.LifecycleEvent;
...
@@ -23,6 +23,8 @@ import org.apache.catalina.LifecycleEvent;
import
org.apache.catalina.LifecycleListener
;
import
org.apache.catalina.LifecycleListener
;
import
org.apache.catalina.connector.Connector
;
import
org.apache.catalina.connector.Connector
;
import
org.apache.catalina.core.AprLifecycleListener
;
import
org.apache.catalina.core.AprLifecycleListener
;
import
org.apache.catalina.core.StandardContext
;
import
org.apache.catalina.startup.Tomcat
;
import
org.apache.catalina.valves.RemoteIpValve
;
import
org.apache.catalina.valves.RemoteIpValve
;
import
org.junit.Test
;
import
org.junit.Test
;
import
org.mockito.ArgumentCaptor
;
import
org.mockito.ArgumentCaptor
;
...
@@ -138,4 +140,16 @@ public class TomcatReactiveWebServerFactoryTests
...
@@ -138,4 +140,16 @@ public class TomcatReactiveWebServerFactoryTests
assertForwardHeaderIsUsed
(
factory
);
assertForwardHeaderIsUsed
(
factory
);
}
}
@Test
public
void
referenceClearingIsDisabled
()
{
TomcatReactiveWebServerFactory
factory
=
getFactory
();
this
.
webServer
=
factory
.
getWebServer
(
mock
(
HttpHandler
.
class
));
this
.
webServer
.
start
();
Tomcat
tomcat
=
((
TomcatWebServer
)
this
.
webServer
).
getTomcat
();
StandardContext
context
=
(
StandardContext
)
tomcat
.
getHost
().
findChildren
()[
0
];
assertThat
(
context
.
getClearReferencesObjectStreamClassCaches
()).
isFalse
();
assertThat
(
context
.
getClearReferencesRmiTargets
()).
isFalse
();
assertThat
(
context
.
getClearReferencesThreadLocals
()).
isFalse
();
}
}
}
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/embedded/tomcat/TomcatServletWebServerFactoryTests.java
View file @
6307cb59
/*
/*
* Copyright 2012-201
8
the original author or authors.
* Copyright 2012-201
9
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.
...
@@ -451,6 +451,18 @@ public class TomcatServletWebServerFactoryTests
...
@@ -451,6 +451,18 @@ public class TomcatServletWebServerFactoryTests
this
.
webServer
.
start
();
this
.
webServer
.
start
();
}
}
@Test
public
void
referenceClearingIsDisabled
()
{
TomcatServletWebServerFactory
factory
=
getFactory
();
this
.
webServer
=
factory
.
getWebServer
();
this
.
webServer
.
start
();
Tomcat
tomcat
=
((
TomcatWebServer
)
this
.
webServer
).
getTomcat
();
StandardContext
context
=
(
StandardContext
)
tomcat
.
getHost
().
findChildren
()[
0
];
assertThat
(
context
.
getClearReferencesObjectStreamClassCaches
()).
isFalse
();
assertThat
(
context
.
getClearReferencesRmiTargets
()).
isFalse
();
assertThat
(
context
.
getClearReferencesThreadLocals
()).
isFalse
();
}
@Override
@Override
protected
JspServlet
getJspServlet
()
throws
ServletException
{
protected
JspServlet
getJspServlet
()
throws
ServletException
{
Tomcat
tomcat
=
((
TomcatWebServer
)
this
.
webServer
).
getTomcat
();
Tomcat
tomcat
=
((
TomcatWebServer
)
this
.
webServer
).
getTomcat
();
...
...
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