Allow adding additional tld skip patterns
This commit improves `TomcatEmbeddedServletContainerFactory` so that tld skip patterns can be set or added to an existing set. An additional `server.tomcat.additional-tld-skip-patterns` is now being exposed to easily add patterns via configuration. Closes gh-5010
This commit is contained in:
@@ -19,8 +19,10 @@ package org.springframework.boot.autoconfigure.web;
|
||||
import java.io.File;
|
||||
import java.net.InetAddress;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -72,6 +74,7 @@ import org.springframework.boot.web.servlet.ServletContextInitializer;
|
||||
import org.springframework.context.EnvironmentAware;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
@@ -671,6 +674,13 @@ public class ServerProperties
|
||||
*/
|
||||
private int acceptCount = 0;
|
||||
|
||||
/**
|
||||
* Comma-separated list of additional patterns that match jars to ignore for
|
||||
* TLD scanning. The special '?' and '*' characters can be used in the pattern
|
||||
* to match one and only one character and zero or more characters respectively.
|
||||
*/
|
||||
private List<String> additionalTldSkipPatterns = new ArrayList<String>();
|
||||
|
||||
public int getMaxThreads() {
|
||||
return this.maxThreads;
|
||||
}
|
||||
@@ -779,6 +789,14 @@ public class ServerProperties
|
||||
this.acceptCount = acceptCount;
|
||||
}
|
||||
|
||||
public List<String> getAdditionalTldSkipPatterns() {
|
||||
return this.additionalTldSkipPatterns;
|
||||
}
|
||||
|
||||
public void setAdditionalTldSkipPatterns(List<String> additionalTldSkipPatterns) {
|
||||
this.additionalTldSkipPatterns = additionalTldSkipPatterns;
|
||||
}
|
||||
|
||||
void customizeTomcat(ServerProperties serverProperties,
|
||||
TomcatEmbeddedServletContainerFactory factory) {
|
||||
if (getBasedir() != null) {
|
||||
@@ -819,6 +837,9 @@ public class ServerProperties
|
||||
if (this.acceptCount > 0) {
|
||||
customizeAcceptCount(factory);
|
||||
}
|
||||
if (!ObjectUtils.isEmpty(this.additionalTldSkipPatterns)) {
|
||||
factory.getTldSkipPatterns().addAll(this.additionalTldSkipPatterns);
|
||||
}
|
||||
}
|
||||
|
||||
private void customizeAcceptCount(TomcatEmbeddedServletContainerFactory factory) {
|
||||
|
||||
@@ -488,6 +488,32 @@ public class ServerPropertiesTests {
|
||||
verify(container).setAccessLogRotate(false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void customTomcatTldSkip() {
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
map.put("server.tomcat.additional-tld-skip-patterns", "foo.jar,bar.jar");
|
||||
bindProperties(map);
|
||||
|
||||
testCustomTomcatTldSkip("foo.jar", "bar.jar");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void customTomcatTldSkipAsList() {
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
map.put("server.tomcat.additional-tld-skip-patterns[0]", "biz.jar");
|
||||
map.put("server.tomcat.additional-tld-skip-patterns[1]", "bah.jar");
|
||||
bindProperties(map);
|
||||
|
||||
testCustomTomcatTldSkip("biz.jar", "bah.jar");
|
||||
}
|
||||
|
||||
private void testCustomTomcatTldSkip(String... expectedJars) {
|
||||
TomcatEmbeddedServletContainerFactory container = new TomcatEmbeddedServletContainerFactory();
|
||||
this.properties.customize(container);
|
||||
assertThat(container.getTldSkipPatterns()).contains(expectedJars);
|
||||
assertThat(container.getTldSkipPatterns()).contains("junit-*.jar", "spring-boot-*.jar");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void defaultUseForwardHeadersUndertow() throws Exception {
|
||||
UndertowEmbeddedServletContainerFactory container = spy(
|
||||
|
||||
Reference in New Issue
Block a user