Skip to content

Remove support for tomcat 7 #7495

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -62,22 +57,6 @@ private void setPatternToTomcat8SkipFilter() {
}
}

// For Tomcat 7 compatibility
public void scan(ServletContext context, ClassLoader classloader,
JarScannerCallback callback, Set<String> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
*/
Expand Down