Tolerate API changes between Tomcat 7 and Tomcat 8

See gh-6053
This commit is contained in:
Andy Wilkinson 2016-05-27 12:24:22 +01:00
parent a5ad2b33ab
commit 29ac6fc154
1 changed files with 13 additions and 2 deletions

View File

@ -98,7 +98,7 @@ public class TomcatEmbeddedServletContainer implements EmbeddedServletContainer
Context context = findContext(); Context context = findContext();
try { try {
ContextBindings.bindClassLoader(context, context.getNamingToken(), ContextBindings.bindClassLoader(context, getNamingToken(context),
getClass().getClassLoader()); getClass().getClassLoader());
} }
catch (NamingException ex) { catch (NamingException ex) {
@ -191,7 +191,7 @@ public class TomcatEmbeddedServletContainer implements EmbeddedServletContainer
} }
finally { finally {
Context context = findContext(); Context context = findContext();
ContextBindings.unbindClassLoader(context, context.getNamingToken(), ContextBindings.unbindClassLoader(context, getNamingToken(context),
getClass().getClassLoader()); getClass().getClassLoader());
} }
} }
@ -312,4 +312,15 @@ public class TomcatEmbeddedServletContainer implements EmbeddedServletContainer
return this.tomcat; return this.tomcat;
} }
private Object getNamingToken(Context context) {
try {
return context.getNamingToken();
}
catch (NoSuchMethodError ex) {
// Use the context itself on Tomcat 7
return context;
}
}
} }