From cb3d156d6fa586879c42d735c6690ab0b3c8f27e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edd=C3=BA=20Mel=C3=A9ndez?= Date: Mon, 28 Nov 2016 01:51:27 -0500 Subject: [PATCH] Remove support for tomcat 7 See gh-6416 --- .../tomcat/SkipPatternJarScanner.java | 21 ------ ...TomcatEmbeddedServletContainerFactory.java | 48 ------------- .../embedded/tomcat/TomcatErrorPage.java | 8 +-- .../embedded/tomcat/TomcatResources.java | 72 +------------------ 4 files changed, 2 insertions(+), 147 deletions(-) diff --git a/spring-boot/src/main/java/org/springframework/boot/context/embedded/tomcat/SkipPatternJarScanner.java b/spring-boot/src/main/java/org/springframework/boot/context/embedded/tomcat/SkipPatternJarScanner.java index f5665b48712f..6e3343e508cb 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/embedded/tomcat/SkipPatternJarScanner.java +++ b/spring-boot/src/main/java/org/springframework/boot/context/embedded/tomcat/SkipPatternJarScanner.java @@ -16,19 +16,14 @@ package org.springframework.boot.context.embedded.tomcat; -import java.lang.reflect.Method; import java.util.Set; -import javax.servlet.ServletContext; - import org.apache.tomcat.JarScanner; -import org.apache.tomcat.JarScannerCallback; import org.apache.tomcat.util.scan.StandardJarScanFilter; import org.apache.tomcat.util.scan.StandardJarScanner; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; -import org.springframework.util.ReflectionUtils; import org.springframework.util.StringUtils; /** @@ -62,22 +57,6 @@ private void setPatternToTomcat8SkipFilter() { } } - // For Tomcat 7 compatibility - public void scan(ServletContext context, ClassLoader classloader, - JarScannerCallback callback, Set jarsToSkip) { - Method scanMethod = ReflectionUtils.findMethod(this.jarScanner.getClass(), "scan", - ServletContext.class, ClassLoader.class, JarScannerCallback.class, - Set.class); - Assert.notNull(scanMethod, "Unable to find scan method"); - try { - scanMethod.invoke(this.jarScanner, context, classloader, callback, - (jarsToSkip == null ? this.patterns : jarsToSkip)); - } - catch (Exception ex) { - throw new IllegalStateException("Tomcat 7 reflection failed", ex); - } - } - /** * Apply this decorator the specified context. * @param context the context to apply to diff --git a/spring-boot/src/main/java/org/springframework/boot/context/embedded/tomcat/TomcatEmbeddedServletContainerFactory.java b/spring-boot/src/main/java/org/springframework/boot/context/embedded/tomcat/TomcatEmbeddedServletContainerFactory.java index c0cddd65f11b..3c5bdabf716a 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/embedded/tomcat/TomcatEmbeddedServletContainerFactory.java +++ b/spring-boot/src/main/java/org/springframework/boot/context/embedded/tomcat/TomcatEmbeddedServletContainerFactory.java @@ -18,8 +18,6 @@ import java.io.File; import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.InputStream; import java.nio.charset.Charset; import java.util.ArrayList; import java.util.Arrays; @@ -34,7 +32,6 @@ import java.util.concurrent.TimeUnit; import javax.servlet.ServletContainerInitializer; -import javax.servlet.ServletContext; import org.apache.catalina.Context; import org.apache.catalina.Engine; @@ -74,7 +71,6 @@ import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.ResourceUtils; -import org.springframework.util.StreamUtils; import org.springframework.util.StringUtils; /** @@ -217,7 +213,6 @@ protected void prepareContext(Host host, ServletContextInitializer[] initializer if (shouldRegisterJspServlet()) { addJspServlet(context); addJasperInitializer(context); - context.addLifecycleListener(new StoreMergedWebXmlListener()); } ServletContextInitializer[] initializersToUse = mergeInitializers(initializers); configureContext(context, initializersToUse); @@ -802,49 +797,6 @@ public void setBackgroundProcessorDelay(int delay) { this.backgroundProcessorDelay = delay; } - /** - * {@link LifecycleListener} that stores an empty merged web.xml. This is critical for - * Jasper on Tomcat 7 to prevent warnings about missing web.xml files and to enable - * EL. - */ - private static class StoreMergedWebXmlListener implements LifecycleListener { - - private static final String MERGED_WEB_XML = "org.apache.tomcat.util.scan.MergedWebXml"; - - @Override - public void lifecycleEvent(LifecycleEvent event) { - if (event.getType().equals(Lifecycle.CONFIGURE_START_EVENT)) { - onStart((Context) event.getLifecycle()); - } - } - - private void onStart(Context context) { - ServletContext servletContext = context.getServletContext(); - if (servletContext.getAttribute(MERGED_WEB_XML) == null) { - servletContext.setAttribute(MERGED_WEB_XML, getEmptyWebXml()); - } - TomcatResources.get(context).addClasspathResources(); - } - - private String getEmptyWebXml() { - InputStream stream = TomcatEmbeddedServletContainerFactory.class - .getResourceAsStream("empty-web.xml"); - Assert.state(stream != null, "Unable to read empty web.xml"); - try { - try { - return StreamUtils.copyToString(stream, Charset.forName("UTF-8")); - } - finally { - stream.close(); - } - } - catch (IOException ex) { - throw new IllegalStateException(ex); - } - } - - } - /** * {@link LifecycleListener} to disable persistence in the {@link StandardManager}. A * {@link LifecycleListener} is used so not to interfere with Tomcat's default manager diff --git a/spring-boot/src/main/java/org/springframework/boot/context/embedded/tomcat/TomcatErrorPage.java b/spring-boot/src/main/java/org/springframework/boot/context/embedded/tomcat/TomcatErrorPage.java index 3c50794603da..a9ef66510f61 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/embedded/tomcat/TomcatErrorPage.java +++ b/spring-boot/src/main/java/org/springframework/boot/context/embedded/tomcat/TomcatErrorPage.java @@ -36,8 +36,6 @@ class TomcatErrorPage { private static final String ERROR_PAGE_CLASS = "org.apache.tomcat.util.descriptor.web.ErrorPage"; - private static final String LEGACY_ERROR_PAGE_CLASS = "org.apache.catalina.deploy.ErrorPage"; - private final String location; private final String exceptionType; @@ -59,10 +57,6 @@ private Object createNativePage(ErrorPage errorPage) { return BeanUtils .instantiateClass(ClassUtils.forName(ERROR_PAGE_CLASS, null)); } - if (ClassUtils.isPresent(LEGACY_ERROR_PAGE_CLASS, null)) { - return BeanUtils.instantiateClass( - ClassUtils.forName(LEGACY_ERROR_PAGE_CLASS, null)); - } } catch (ClassNotFoundException ex) { // Swallow and continue @@ -75,7 +69,7 @@ private Object createNativePage(ErrorPage errorPage) { public void addToContext(Context context) { Assert.state(this.nativePage != null, - "Neither Tomcat 7 nor 8 detected so no native error page exists"); + "No Tomcat 8 detected so no native error page exists"); if (ClassUtils.isPresent(ERROR_PAGE_CLASS, null)) { org.apache.tomcat.util.descriptor.web.ErrorPage errorPage = (org.apache.tomcat.util.descriptor.web.ErrorPage) this.nativePage; errorPage.setLocation(this.location); diff --git a/spring-boot/src/main/java/org/springframework/boot/context/embedded/tomcat/TomcatResources.java b/spring-boot/src/main/java/org/springframework/boot/context/embedded/tomcat/TomcatResources.java index 78df53bc1ba2..6a6883e9233f 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/embedded/tomcat/TomcatResources.java +++ b/spring-boot/src/main/java/org/springframework/boot/context/embedded/tomcat/TomcatResources.java @@ -17,23 +17,14 @@ package org.springframework.boot.context.embedded.tomcat; import java.io.File; -import java.lang.reflect.Method; -import java.net.MalformedURLException; import java.net.URL; import java.net.URLClassLoader; -import javax.naming.directory.DirContext; -import javax.servlet.ServletContext; - import org.apache.catalina.Context; import org.apache.catalina.WebResourceRoot.ResourceSetType; -import org.apache.catalina.core.StandardContext; - -import org.springframework.util.ClassUtils; -import org.springframework.util.ReflectionUtils; /** - * Abstraction to add resources that works with both Tomcat 8 and 7. + * Abstraction to add resources that works with Tomcat 8. * * @author Dave Syer * @author Phillip Webb @@ -95,70 +86,9 @@ protected final Context getContext() { * @return a {@link TomcatResources} instance. */ public static TomcatResources get(Context context) { - if (ClassUtils.isPresent("org.apache.catalina.deploy.ErrorPage", null)) { - return new Tomcat7Resources(context); - } return new Tomcat8Resources(context); } - /** - * {@link TomcatResources} for Tomcat 7. - */ - private static class Tomcat7Resources extends TomcatResources { - - private final Method addResourceJarUrlMethod; - - Tomcat7Resources(Context context) { - super(context); - this.addResourceJarUrlMethod = ReflectionUtils.findMethod(context.getClass(), - "addResourceJarUrl", URL.class); - } - - @Override - protected void addJar(String jar) { - URL url = getJarUrl(jar); - if (url != null) { - try { - this.addResourceJarUrlMethod.invoke(getContext(), url); - } - catch (Exception ex) { - throw new IllegalStateException(ex); - } - } - } - - private URL getJarUrl(String jar) { - try { - return new URL(jar); - } - catch (MalformedURLException ex) { - // Ignore - return null; - } - } - - @Override - protected void addDir(String dir, URL url) { - if (getContext() instanceof ServletContext) { - try { - Class fileDirContextClass = Class - .forName("org.apache.naming.resources.FileDirContext"); - Method setDocBaseMethod = ReflectionUtils - .findMethod(fileDirContextClass, "setDocBase", String.class); - Object fileDirContext = fileDirContextClass.newInstance(); - setDocBaseMethod.invoke(fileDirContext, dir); - Method addResourcesDirContextMethod = ReflectionUtils.findMethod( - StandardContext.class, "addResourcesDirContext", - DirContext.class); - addResourcesDirContextMethod.invoke(getContext(), fileDirContext); - } - catch (Exception ex) { - throw new IllegalStateException("Tomcat 7 reflection failed", ex); - } - } - } - } - /** * {@link TomcatResources} for Tomcat 8. */