Consistent local vs external resolution of https schema references

Co-Authored-By: Sam Brannen <sbrannen@pivotal.io>

See gh-22504
This commit is contained in:
Juergen Hoeller
2019-03-31 12:23:33 +02:00
committed by Sam Brannen
parent 0970af9aa7
commit 9543b9ceac

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2012 the original author or authors. * Copyright 2002-2019 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -37,18 +37,18 @@ import org.springframework.util.CollectionUtils;
* {@link EntityResolver} implementation that attempts to resolve schema URLs into * {@link EntityResolver} implementation that attempts to resolve schema URLs into
* local {@link ClassPathResource classpath resources} using a set of mappings files. * local {@link ClassPathResource classpath resources} using a set of mappings files.
* *
* <p>By default, this class will look for mapping files in the classpath using the pattern: * <p>By default, this class will look for mapping files in the classpath using the
* {@code META-INF/spring.schemas} allowing for multiple files to exist on the * pattern: {@code META-INF/spring.schemas} allowing for multiple files to exist on
* classpath at any one time. * the classpath at any one time.
* *
* The format of {@code META-INF/spring.schemas} is a properties * <p>The format of {@code META-INF/spring.schemas} is a properties file where each line
* file where each line should be of the form {@code systemId=schema-location} * should be of the form {@code systemId=schema-location} where {@code schema-location}
* where {@code schema-location} should also be a schema file in the classpath. * should also be a schema file in the classpath. Since {@code systemId} is commonly a
* Since systemId is commonly a URL, one must be careful to escape any ':' characters * URL, one must be careful to escape any ':' characters which are treated as delimiters
* which are treated as delimiters in properties files. * in properties files.
* *
* <p>The pattern for the mapping files can be overidden using the * <p>The pattern for the mapping files can be overridden using the
* {@link #PluggableSchemaResolver(ClassLoader, String)} constructor * {@link #PluggableSchemaResolver(ClassLoader, String)} constructor.
* *
* @author Rob Harrop * @author Rob Harrop
* @author Juergen Hoeller * @author Juergen Hoeller
@@ -109,6 +109,10 @@ public class PluggableSchemaResolver implements EntityResolver {
if (systemId != null) { if (systemId != null) {
String resourceLocation = getSchemaMappings().get(systemId); String resourceLocation = getSchemaMappings().get(systemId);
if (resourceLocation == null && systemId.startsWith("https:")) {
// Retrieve canonical http schema mapping even for https declaration
resourceLocation = getSchemaMappings().get("http:" + systemId.substring(6));
}
if (resourceLocation != null) { if (resourceLocation != null) {
Resource resource = new ClassPathResource(resourceLocation, this.classLoader); Resource resource = new ClassPathResource(resourceLocation, this.classLoader);
try { try {