Skip to content

Commit

Permalink
Consistent local vs external resolution of https schema references
Browse files Browse the repository at this point in the history
Co-Authored-By: Sam Brannen <sbrannen@pivotal.io>

See spring-projectsgh-22504
  • Loading branch information
jhoeller authored and sbrannen committed Mar 31, 2019
1 parent 41b3d6a commit 2a268f2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -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");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -37,18 +37,18 @@
* {@link EntityResolver} implementation that attempts to resolve schema URLs into
* 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:
* {@code META-INF/spring.schemas} allowing for multiple files to exist on the
* classpath at any one time.
* <p>By default, this class will look for mapping files in the classpath using the
* pattern: {@code META-INF/spring.schemas} allowing for multiple files to exist on
* the classpath at any one time.
*
* The format of {@code META-INF/spring.schemas} is a properties
* file where each line should be of the form {@code systemId=schema-location}
* where {@code schema-location} should also be a schema file in the classpath.
* Since systemId is commonly a URL, one must be careful to escape any ':' characters
* which are treated as delimiters in properties files.
* <p>The format of {@code META-INF/spring.schemas} is a properties file where each line
* should be of the form {@code systemId=schema-location} where {@code schema-location}
* should also be a schema file in the classpath. Since {@code systemId} is commonly a
* URL, one must be careful to escape any ':' characters which are treated as delimiters
* in properties files.
*
* <p>The pattern for the mapping files can be overidden using the
* {@link #PluggableSchemaResolver(ClassLoader, String)} constructor
* <p>The pattern for the mapping files can be overridden using the
* {@link #PluggableSchemaResolver(ClassLoader, String)} constructor.
*
* @author Rob Harrop
* @author Juergen Hoeller
Expand Down Expand Up @@ -108,6 +108,10 @@ public InputSource resolveEntity(String publicId, String systemId) throws IOExce

if (systemId != null) {
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) {
Resource resource = new ClassPathResource(resourceLocation, this.classLoader);
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:test="http://www.springframework.org/schema/beans/test"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd
http://www.springframework.org/schema/beans/test http://www.springframework.org/schema/beans/factory/xml/support/CustomNamespaceHandlerTests.xsd"
xsi:schemaLocation="http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/util https://www.springframework.org/schema/util/spring-util-2.0.xsd
http://www.springframework.org/schema/beans/test https://www.springframework.org/schema/beans/factory/xml/support/CustomNamespaceHandlerTests.xsd"
default-lazy-init="true">

<test:testBean id="testBean" name="Rob Harrop" age="23"/>
Expand Down

0 comments on commit 2a268f2

Please sign in to comment.