Skip to content

Commit df3e1f0

Browse files
eddumelendezwilkinsona
authored andcommitted
Start removing support for Tomcat 7
See gh-6416 Closes gh-7495
1 parent 5c006d0 commit df3e1f0

File tree

4 files changed

+2
-148
lines changed

4 files changed

+2
-148
lines changed

spring-boot/src/main/java/org/springframework/boot/context/embedded/tomcat/SkipPatternJarScanner.java

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,14 @@
1616

1717
package org.springframework.boot.context.embedded.tomcat;
1818

19-
import java.lang.reflect.Method;
2019
import java.util.Set;
2120

22-
import javax.servlet.ServletContext;
23-
2421
import org.apache.tomcat.JarScanner;
25-
import org.apache.tomcat.JarScannerCallback;
2622
import org.apache.tomcat.util.scan.StandardJarScanFilter;
2723
import org.apache.tomcat.util.scan.StandardJarScanner;
2824

2925
import org.springframework.util.Assert;
3026
import org.springframework.util.ClassUtils;
31-
import org.springframework.util.ReflectionUtils;
3227
import org.springframework.util.StringUtils;
3328

3429
/**
@@ -62,22 +57,6 @@ private void setPatternToTomcat8SkipFilter() {
6257
}
6358
}
6459

65-
// For Tomcat 7 compatibility
66-
public void scan(ServletContext context, ClassLoader classloader,
67-
JarScannerCallback callback, Set<String> jarsToSkip) {
68-
Method scanMethod = ReflectionUtils.findMethod(this.jarScanner.getClass(), "scan",
69-
ServletContext.class, ClassLoader.class, JarScannerCallback.class,
70-
Set.class);
71-
Assert.notNull(scanMethod, "Unable to find scan method");
72-
try {
73-
scanMethod.invoke(this.jarScanner, context, classloader, callback,
74-
(jarsToSkip == null ? this.patterns : jarsToSkip));
75-
}
76-
catch (Exception ex) {
77-
throw new IllegalStateException("Tomcat 7 reflection failed", ex);
78-
}
79-
}
80-
8160
/**
8261
* Apply this decorator the specified context.
8362
* @param context the context to apply to

spring-boot/src/main/java/org/springframework/boot/context/embedded/tomcat/TomcatEmbeddedServletContainerFactory.java

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818

1919
import java.io.File;
2020
import java.io.FileNotFoundException;
21-
import java.io.IOException;
22-
import java.io.InputStream;
2321
import java.nio.charset.Charset;
2422
import java.util.ArrayList;
2523
import java.util.Arrays;
@@ -34,7 +32,6 @@
3432
import java.util.concurrent.TimeUnit;
3533

3634
import javax.servlet.ServletContainerInitializer;
37-
import javax.servlet.ServletContext;
3835

3936
import org.apache.catalina.Context;
4037
import org.apache.catalina.Engine;
@@ -74,7 +71,6 @@
7471
import org.springframework.util.Assert;
7572
import org.springframework.util.ClassUtils;
7673
import org.springframework.util.ResourceUtils;
77-
import org.springframework.util.StreamUtils;
7874
import org.springframework.util.StringUtils;
7975

8076
/**
@@ -217,7 +213,6 @@ protected void prepareContext(Host host, ServletContextInitializer[] initializer
217213
if (shouldRegisterJspServlet()) {
218214
addJspServlet(context);
219215
addJasperInitializer(context);
220-
context.addLifecycleListener(new StoreMergedWebXmlListener());
221216
}
222217
ServletContextInitializer[] initializersToUse = mergeInitializers(initializers);
223218
configureContext(context, initializersToUse);
@@ -802,49 +797,6 @@ public void setBackgroundProcessorDelay(int delay) {
802797
this.backgroundProcessorDelay = delay;
803798
}
804799

805-
/**
806-
* {@link LifecycleListener} that stores an empty merged web.xml. This is critical for
807-
* Jasper on Tomcat 7 to prevent warnings about missing web.xml files and to enable
808-
* EL.
809-
*/
810-
private static class StoreMergedWebXmlListener implements LifecycleListener {
811-
812-
private static final String MERGED_WEB_XML = "org.apache.tomcat.util.scan.MergedWebXml";
813-
814-
@Override
815-
public void lifecycleEvent(LifecycleEvent event) {
816-
if (event.getType().equals(Lifecycle.CONFIGURE_START_EVENT)) {
817-
onStart((Context) event.getLifecycle());
818-
}
819-
}
820-
821-
private void onStart(Context context) {
822-
ServletContext servletContext = context.getServletContext();
823-
if (servletContext.getAttribute(MERGED_WEB_XML) == null) {
824-
servletContext.setAttribute(MERGED_WEB_XML, getEmptyWebXml());
825-
}
826-
TomcatResources.get(context).addClasspathResources();
827-
}
828-
829-
private String getEmptyWebXml() {
830-
InputStream stream = TomcatEmbeddedServletContainerFactory.class
831-
.getResourceAsStream("empty-web.xml");
832-
Assert.state(stream != null, "Unable to read empty web.xml");
833-
try {
834-
try {
835-
return StreamUtils.copyToString(stream, Charset.forName("UTF-8"));
836-
}
837-
finally {
838-
stream.close();
839-
}
840-
}
841-
catch (IOException ex) {
842-
throw new IllegalStateException(ex);
843-
}
844-
}
845-
846-
}
847-
848800
/**
849801
* {@link LifecycleListener} to disable persistence in the {@link StandardManager}. A
850802
* {@link LifecycleListener} is used so not to interfere with Tomcat's default manager

spring-boot/src/main/java/org/springframework/boot/context/embedded/tomcat/TomcatErrorPage.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ class TomcatErrorPage {
3636

3737
private static final String ERROR_PAGE_CLASS = "org.apache.tomcat.util.descriptor.web.ErrorPage";
3838

39-
private static final String LEGACY_ERROR_PAGE_CLASS = "org.apache.catalina.deploy.ErrorPage";
40-
4139
private final String location;
4240

4341
private final String exceptionType;
@@ -59,10 +57,6 @@ private Object createNativePage(ErrorPage errorPage) {
5957
return BeanUtils
6058
.instantiateClass(ClassUtils.forName(ERROR_PAGE_CLASS, null));
6159
}
62-
if (ClassUtils.isPresent(LEGACY_ERROR_PAGE_CLASS, null)) {
63-
return BeanUtils.instantiateClass(
64-
ClassUtils.forName(LEGACY_ERROR_PAGE_CLASS, null));
65-
}
6660
}
6761
catch (ClassNotFoundException ex) {
6862
// Swallow and continue
@@ -75,7 +69,7 @@ private Object createNativePage(ErrorPage errorPage) {
7569

7670
public void addToContext(Context context) {
7771
Assert.state(this.nativePage != null,
78-
"Neither Tomcat 7 nor 8 detected so no native error page exists");
72+
"No Tomcat 8 detected so no native error page exists");
7973
if (ClassUtils.isPresent(ERROR_PAGE_CLASS, null)) {
8074
org.apache.tomcat.util.descriptor.web.ErrorPage errorPage = (org.apache.tomcat.util.descriptor.web.ErrorPage) this.nativePage;
8175
errorPage.setLocation(this.location);

spring-boot/src/main/java/org/springframework/boot/context/embedded/tomcat/TomcatResources.java

Lines changed: 1 addition & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,14 @@
1717
package org.springframework.boot.context.embedded.tomcat;
1818

1919
import java.io.File;
20-
import java.lang.reflect.Method;
21-
import java.net.MalformedURLException;
2220
import java.net.URL;
2321
import java.net.URLClassLoader;
2422

25-
import javax.naming.directory.DirContext;
26-
import javax.servlet.ServletContext;
27-
2823
import org.apache.catalina.Context;
2924
import org.apache.catalina.WebResourceRoot.ResourceSetType;
30-
import org.apache.catalina.core.StandardContext;
31-
32-
import org.springframework.util.ClassUtils;
33-
import org.springframework.util.ReflectionUtils;
3425

3526
/**
36-
* Abstraction to add resources that works with both Tomcat 8 and 7.
27+
* Abstraction to add resources that works with Tomcat 8.
3728
*
3829
* @author Dave Syer
3930
* @author Phillip Webb
@@ -95,71 +86,9 @@ protected final Context getContext() {
9586
* @return a {@link TomcatResources} instance.
9687
*/
9788
public static TomcatResources get(Context context) {
98-
if (ClassUtils.isPresent("org.apache.catalina.deploy.ErrorPage", null)) {
99-
return new Tomcat7Resources(context);
100-
}
10189
return new Tomcat8Resources(context);
10290
}
10391

104-
/**
105-
* {@link TomcatResources} for Tomcat 7.
106-
*/
107-
private static class Tomcat7Resources extends TomcatResources {
108-
109-
private final Method addResourceJarUrlMethod;
110-
111-
Tomcat7Resources(Context context) {
112-
super(context);
113-
this.addResourceJarUrlMethod = ReflectionUtils.findMethod(context.getClass(),
114-
"addResourceJarUrl", URL.class);
115-
}
116-
117-
@Override
118-
protected void addJar(String jar) {
119-
URL url = getJarUrl(jar);
120-
if (url != null) {
121-
try {
122-
this.addResourceJarUrlMethod.invoke(getContext(), url);
123-
}
124-
catch (Exception ex) {
125-
throw new IllegalStateException(ex);
126-
}
127-
}
128-
}
129-
130-
private URL getJarUrl(String jar) {
131-
try {
132-
return new URL(jar);
133-
}
134-
catch (MalformedURLException ex) {
135-
// Ignore
136-
return null;
137-
}
138-
}
139-
140-
@Override
141-
protected void addDir(String dir, URL url) {
142-
if (getContext() instanceof ServletContext) {
143-
try {
144-
Class<?> fileDirContextClass = Class
145-
.forName("org.apache.naming.resources.FileDirContext");
146-
Method setDocBaseMethod = ReflectionUtils
147-
.findMethod(fileDirContextClass, "setDocBase", String.class);
148-
Object fileDirContext = fileDirContextClass.newInstance();
149-
setDocBaseMethod.invoke(fileDirContext, dir);
150-
Method addResourcesDirContextMethod = ReflectionUtils.findMethod(
151-
StandardContext.class, "addResourcesDirContext",
152-
DirContext.class);
153-
addResourcesDirContextMethod.invoke(getContext(), fileDirContext);
154-
}
155-
catch (Exception ex) {
156-
throw new IllegalStateException("Tomcat 7 reflection failed", ex);
157-
}
158-
}
159-
}
160-
161-
}
162-
16392
/**
16493
* {@link TomcatResources} for Tomcat 8.
16594
*/

0 commit comments

Comments
 (0)