Skip to content

Commit 777b4c8

Browse files
committed
Merge branch '5.1.x'
2 parents fd5a7c2 + 7cbb3b0 commit 777b4c8

File tree

8 files changed

+78
-55
lines changed

8 files changed

+78
-55
lines changed

spring-beans/src/main/java/org/springframework/beans/factory/xml/BeansDtdResolver.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package org.springframework.beans.factory.xml;
1818

19+
import java.io.FileNotFoundException;
1920
import java.io.IOException;
2021

2122
import org.apache.commons.logging.Log;
@@ -52,7 +53,7 @@ public class BeansDtdResolver implements EntityResolver {
5253

5354
@Override
5455
@Nullable
55-
public InputSource resolveEntity(String publicId, @Nullable String systemId) throws IOException {
56+
public InputSource resolveEntity(@Nullable String publicId, @Nullable String systemId) throws IOException {
5657
if (logger.isTraceEnabled()) {
5758
logger.trace("Trying to resolve XML entity with public ID [" + publicId +
5859
"] and system ID [" + systemId + "]");
@@ -76,7 +77,7 @@ public InputSource resolveEntity(String publicId, @Nullable String systemId) thr
7677
}
7778
return source;
7879
}
79-
catch (IOException ex) {
80+
catch (FileNotFoundException ex) {
8081
if (logger.isDebugEnabled()) {
8182
logger.debug("Could not resolve beans DTD [" + systemId + "]: not found in classpath", ex);
8283
}

spring-beans/src/main/java/org/springframework/beans/factory/xml/DelegatingEntityResolver.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -79,7 +79,9 @@ public DelegatingEntityResolver(EntityResolver dtdResolver, EntityResolver schem
7979

8080
@Override
8181
@Nullable
82-
public InputSource resolveEntity(String publicId, @Nullable String systemId) throws SAXException, IOException {
82+
public InputSource resolveEntity(@Nullable String publicId, @Nullable String systemId)
83+
throws SAXException, IOException {
84+
8385
if (systemId != null) {
8486
if (systemId.endsWith(DTD_SUFFIX)) {
8587
return this.dtdResolver.resolveEntity(publicId, systemId);
@@ -88,6 +90,8 @@ else if (systemId.endsWith(XSD_SUFFIX)) {
8890
return this.schemaResolver.resolveEntity(publicId, systemId);
8991
}
9092
}
93+
94+
// Fall back to the parser's default behavior.
9195
return null;
9296
}
9397

spring-beans/src/main/java/org/springframework/beans/factory/xml/PluggableSchemaResolver.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,14 +106,18 @@ public PluggableSchemaResolver(@Nullable ClassLoader classLoader, String schemaM
106106

107107
@Override
108108
@Nullable
109-
public InputSource resolveEntity(String publicId, @Nullable String systemId) throws IOException {
109+
public InputSource resolveEntity(@Nullable String publicId, @Nullable String systemId) throws IOException {
110110
if (logger.isTraceEnabled()) {
111111
logger.trace("Trying to resolve XML entity with public id [" + publicId +
112112
"] and system id [" + systemId + "]");
113113
}
114114

115115
if (systemId != null) {
116116
String resourceLocation = getSchemaMappings().get(systemId);
117+
if (resourceLocation == null && systemId.startsWith("https:")) {
118+
// Retrieve canonical http schema mapping even for https declaration
119+
resourceLocation = getSchemaMappings().get("http:" + systemId.substring(6));
120+
}
117121
if (resourceLocation != null) {
118122
Resource resource = new ClassPathResource(resourceLocation, this.classLoader);
119123
try {

spring-beans/src/main/java/org/springframework/beans/factory/xml/ResourceEntityResolver.java

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -31,9 +31,9 @@
3131
import org.springframework.lang.Nullable;
3232

3333
/**
34-
* EntityResolver implementation that tries to resolve entity references
34+
* {@code EntityResolver} implementation that tries to resolve entity references
3535
* through a {@link org.springframework.core.io.ResourceLoader} (usually,
36-
* relative to the resource base of an ApplicationContext), if applicable.
36+
* relative to the resource base of an {@code ApplicationContext}), if applicable.
3737
* Extends {@link DelegatingEntityResolver} to also provide DTD and XSD lookup.
3838
*
3939
* <p>Allows to use standard XML entities to include XML snippets into an
@@ -72,8 +72,11 @@ public ResourceEntityResolver(ResourceLoader resourceLoader) {
7272

7373
@Override
7474
@Nullable
75-
public InputSource resolveEntity(String publicId, @Nullable String systemId) throws SAXException, IOException {
75+
public InputSource resolveEntity(@Nullable String publicId, @Nullable String systemId)
76+
throws SAXException, IOException {
77+
7678
InputSource source = super.resolveEntity(publicId, systemId);
79+
7780
if (source == null && systemId != null) {
7881
String resourcePath = null;
7982
try {
@@ -105,7 +108,18 @@ public InputSource resolveEntity(String publicId, @Nullable String systemId) thr
105108
logger.debug("Found XML entity [" + systemId + "]: " + resource);
106109
}
107110
}
111+
else if (systemId.endsWith(DTD_SUFFIX) || systemId.endsWith(XSD_SUFFIX)) {
112+
// External dtd/xsd lookup via https even for canonical http declaration
113+
String url = systemId;
114+
if (url.startsWith("http:")) {
115+
url = "https:" + url.substring(5);
116+
}
117+
source = new InputSource(url);
118+
source.setPublicId(publicId);
119+
return source;
120+
}
108121
}
122+
109123
return source;
110124
}
111125

spring-context/src/test/java/org/springframework/beans/factory/xml/XmlBeanFactoryTests.java

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -123,16 +123,16 @@ private static ClassPathResource classPathResource(String suffix) {
123123
return new ClassPathResource(CLASSNAME + suffix, CLASS);
124124
}
125125

126-
/* SPR-2368 */
127-
@Test
128-
public void testCollectionsReferredToAsRefLocals() throws Exception {
126+
127+
@Test // SPR-2368
128+
public void testCollectionsReferredToAsRefLocals() {
129129
DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
130130
new XmlBeanDefinitionReader(factory).loadBeanDefinitions(COLLECTIONS_XSD_CONTEXT);
131131
factory.preInstantiateSingletons();
132132
}
133133

134134
@Test
135-
public void testRefToSeparatePrototypeInstances() throws Exception {
135+
public void testRefToSeparatePrototypeInstances() {
136136
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
137137
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf);
138138
reader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_NONE);
@@ -151,7 +151,7 @@ public void testRefToSeparatePrototypeInstances() throws Exception {
151151
}
152152

153153
@Test
154-
public void testRefToSingleton() throws Exception {
154+
public void testRefToSingleton() {
155155
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
156156
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf);
157157
reader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_NONE);
@@ -307,7 +307,7 @@ public void testFailsOnInnerBean() {
307307
}
308308

309309
@Test
310-
public void testInheritanceFromParentFactoryPrototype() throws Exception {
310+
public void testInheritanceFromParentFactoryPrototype() {
311311
DefaultListableBeanFactory parent = new DefaultListableBeanFactory();
312312
new XmlBeanDefinitionReader(parent).loadBeanDefinitions(PARENT_CONTEXT);
313313
DefaultListableBeanFactory child = new DefaultListableBeanFactory(parent);
@@ -323,7 +323,7 @@ public void testInheritanceFromParentFactoryPrototype() throws Exception {
323323
}
324324

325325
@Test
326-
public void testInheritanceWithDifferentClass() throws Exception {
326+
public void testInheritanceWithDifferentClass() {
327327
DefaultListableBeanFactory parent = new DefaultListableBeanFactory();
328328
new XmlBeanDefinitionReader(parent).loadBeanDefinitions(PARENT_CONTEXT);
329329
DefaultListableBeanFactory child = new DefaultListableBeanFactory(parent);
@@ -338,7 +338,7 @@ public void testInheritanceWithDifferentClass() throws Exception {
338338
}
339339

340340
@Test
341-
public void testInheritanceWithClass() throws Exception {
341+
public void testInheritanceWithClass() {
342342
DefaultListableBeanFactory parent = new DefaultListableBeanFactory();
343343
new XmlBeanDefinitionReader(parent).loadBeanDefinitions(PARENT_CONTEXT);
344344
DefaultListableBeanFactory child = new DefaultListableBeanFactory(parent);
@@ -353,7 +353,7 @@ public void testInheritanceWithClass() throws Exception {
353353
}
354354

355355
@Test
356-
public void testPrototypeInheritanceFromParentFactoryPrototype() throws Exception {
356+
public void testPrototypeInheritanceFromParentFactoryPrototype() {
357357
DefaultListableBeanFactory parent = new DefaultListableBeanFactory();
358358
new XmlBeanDefinitionReader(parent).loadBeanDefinitions(PARENT_CONTEXT);
359359
DefaultListableBeanFactory child = new DefaultListableBeanFactory(parent);
@@ -373,7 +373,7 @@ public void testPrototypeInheritanceFromParentFactoryPrototype() throws Exceptio
373373
}
374374

375375
@Test
376-
public void testPrototypeInheritanceFromParentFactorySingleton() throws Exception {
376+
public void testPrototypeInheritanceFromParentFactorySingleton() {
377377
DefaultListableBeanFactory parent = new DefaultListableBeanFactory();
378378
new XmlBeanDefinitionReader(parent).loadBeanDefinitions(PARENT_CONTEXT);
379379
DefaultListableBeanFactory child = new DefaultListableBeanFactory(parent);
@@ -433,7 +433,7 @@ public void testAbstractParentBeans() {
433433
}
434434

435435
@Test
436-
public void testDependenciesMaterializeThis() throws Exception {
436+
public void testDependenciesMaterializeThis() {
437437
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
438438
new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(DEP_MATERIALIZE_CONTEXT);
439439

@@ -452,7 +452,7 @@ public void testDependenciesMaterializeThis() throws Exception {
452452
}
453453

454454
@Test
455-
public void testChildOverridesParentBean() throws Exception {
455+
public void testChildOverridesParentBean() {
456456
DefaultListableBeanFactory parent = new DefaultListableBeanFactory();
457457
new XmlBeanDefinitionReader(parent).loadBeanDefinitions(PARENT_CONTEXT);
458458
DefaultListableBeanFactory child = new DefaultListableBeanFactory(parent);
@@ -471,7 +471,7 @@ public void testChildOverridesParentBean() throws Exception {
471471
* If a singleton does this the factory will fail to load.
472472
*/
473473
@Test
474-
public void testBogusParentageFromParentFactory() throws Exception {
474+
public void testBogusParentageFromParentFactory() {
475475
DefaultListableBeanFactory parent = new DefaultListableBeanFactory();
476476
new XmlBeanDefinitionReader(parent).loadBeanDefinitions(PARENT_CONTEXT);
477477
DefaultListableBeanFactory child = new DefaultListableBeanFactory(parent);
@@ -493,7 +493,7 @@ public void testBogusParentageFromParentFactory() throws Exception {
493493
* instances even if derived from a prototype
494494
*/
495495
@Test
496-
public void testSingletonInheritsFromParentFactoryPrototype() throws Exception {
496+
public void testSingletonInheritsFromParentFactoryPrototype() {
497497
DefaultListableBeanFactory parent = new DefaultListableBeanFactory();
498498
new XmlBeanDefinitionReader(parent).loadBeanDefinitions(PARENT_CONTEXT);
499499
DefaultListableBeanFactory child = new DefaultListableBeanFactory(parent);
@@ -658,7 +658,7 @@ public void noSuchFactoryBeanMethod() {
658658
}
659659

660660
@Test
661-
public void testInitMethodIsInvoked() throws Exception {
661+
public void testInitMethodIsInvoked() {
662662
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
663663
new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(INITIALIZERS_CONTEXT);
664664
DoubleInitializer in = (DoubleInitializer) xbf.getBean("init-method1");
@@ -685,7 +685,7 @@ public void testInitMethodThrowsException() {
685685
}
686686

687687
@Test
688-
public void testNoSuchInitMethod() throws Exception {
688+
public void testNoSuchInitMethod() {
689689
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
690690
new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(INITIALIZERS_CONTEXT);
691691
try {
@@ -704,7 +704,7 @@ public void testNoSuchInitMethod() throws Exception {
704704
* Check that InitializingBean method is called first.
705705
*/
706706
@Test
707-
public void testInitializingBeanAndInitMethod() throws Exception {
707+
public void testInitializingBeanAndInitMethod() {
708708
InitAndIB.constructed = false;
709709
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
710710
new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(INITIALIZERS_CONTEXT);
@@ -725,7 +725,7 @@ public void testInitializingBeanAndInitMethod() throws Exception {
725725
* Check that InitializingBean method is not called twice.
726726
*/
727727
@Test
728-
public void testInitializingBeanAndSameInitMethod() throws Exception {
728+
public void testInitializingBeanAndSameInitMethod() {
729729
InitAndIB.constructed = false;
730730
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
731731
new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(INITIALIZERS_CONTEXT);
@@ -743,7 +743,7 @@ public void testInitializingBeanAndSameInitMethod() throws Exception {
743743
}
744744

745745
@Test
746-
public void testDefaultLazyInit() throws Exception {
746+
public void testDefaultLazyInit() {
747747
InitAndIB.constructed = false;
748748
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
749749
new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(DEFAULT_LAZY_CONTEXT);
@@ -759,19 +759,19 @@ public void testDefaultLazyInit() throws Exception {
759759
}
760760

761761
@Test(expected = BeanDefinitionStoreException.class)
762-
public void noSuchXmlFile() throws Exception {
762+
public void noSuchXmlFile() {
763763
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
764764
new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(MISSING_CONTEXT);
765765
}
766766

767767
@Test(expected = BeanDefinitionStoreException.class)
768-
public void invalidXmlFile() throws Exception {
768+
public void invalidXmlFile() {
769769
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
770770
new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(INVALID_CONTEXT);
771771
}
772772

773773
@Test
774-
public void testAutowire() throws Exception {
774+
public void testAutowire() {
775775
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
776776
new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(AUTOWIRE_CONTEXT);
777777
TestBean spouse = new TestBean("kerry", 0);
@@ -780,7 +780,7 @@ public void testAutowire() throws Exception {
780780
}
781781

782782
@Test
783-
public void testAutowireWithParent() throws Exception {
783+
public void testAutowireWithParent() {
784784
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
785785
new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(AUTOWIRE_CONTEXT);
786786
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
@@ -793,7 +793,7 @@ public void testAutowireWithParent() throws Exception {
793793
doTestAutowire(xbf);
794794
}
795795

796-
private void doTestAutowire(DefaultListableBeanFactory xbf) throws Exception {
796+
private void doTestAutowire(DefaultListableBeanFactory xbf) {
797797
DependenciesBean rod1 = (DependenciesBean) xbf.getBean("rod1");
798798
TestBean kerry = (TestBean) xbf.getBean("spouse");
799799
// should have been autowired
@@ -842,7 +842,7 @@ private void doTestAutowire(DefaultListableBeanFactory xbf) throws Exception {
842842
}
843843

844844
@Test
845-
public void testAutowireWithDefault() throws Exception {
845+
public void testAutowireWithDefault() {
846846
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
847847
new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(DEFAULT_AUTOWIRE_CONTEXT);
848848

@@ -858,7 +858,7 @@ public void testAutowireWithDefault() throws Exception {
858858
}
859859

860860
@Test
861-
public void testAutowireByConstructor() throws Exception {
861+
public void testAutowireByConstructor() {
862862
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
863863
new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(CONSTRUCTOR_ARG_CONTEXT);
864864
ConstructorDependenciesBean rod1 = (ConstructorDependenciesBean) xbf.getBean("rod1");
@@ -896,7 +896,7 @@ public void testAutowireByConstructor() throws Exception {
896896
}
897897

898898
@Test
899-
public void testAutowireByConstructorWithSimpleValues() throws Exception {
899+
public void testAutowireByConstructorWithSimpleValues() {
900900
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
901901
new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(CONSTRUCTOR_ARG_CONTEXT);
902902

@@ -1014,14 +1014,14 @@ public void testConstructorArgWithSingleMatch() {
10141014
}
10151015

10161016
@Test(expected = BeanCreationException.class)
1017-
public void throwsExceptionOnTooManyArguments() throws Exception {
1017+
public void throwsExceptionOnTooManyArguments() {
10181018
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
10191019
new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(CONSTRUCTOR_ARG_CONTEXT);
10201020
xbf.getBean("rod7", ConstructorDependenciesBean.class);
10211021
}
10221022

10231023
@Test(expected = UnsatisfiedDependencyException.class)
1024-
public void throwsExceptionOnAmbiguousResolution() throws Exception {
1024+
public void throwsExceptionOnAmbiguousResolution() {
10251025
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
10261026
new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(CONSTRUCTOR_ARG_CONTEXT);
10271027
xbf.getBean("rod8", ConstructorDependenciesBean.class);
@@ -1372,7 +1372,7 @@ public void testRejectsOverrideOfBogusMethodName() {
13721372
}
13731373

13741374
@Test
1375-
public void serializableMethodReplacerAndSuperclass() throws Exception {
1375+
public void serializableMethodReplacerAndSuperclass() throws IOException {
13761376
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
13771377
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf);
13781378
reader.loadBeanDefinitions(DELEGATION_OVERRIDES_CONTEXT);
@@ -1571,7 +1571,7 @@ public void testConstructorWithUnresolvableParameterName() {
15711571
}
15721572

15731573
@Test
1574-
public void testWithDuplicateName() throws Exception {
1574+
public void testWithDuplicateName() {
15751575
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
15761576
try {
15771577
new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(TEST_WITH_DUP_NAMES_CONTEXT);
@@ -1583,7 +1583,7 @@ public void testWithDuplicateName() throws Exception {
15831583
}
15841584

15851585
@Test
1586-
public void testWithDuplicateNameInAlias() throws Exception {
1586+
public void testWithDuplicateNameInAlias() {
15871587
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
15881588
try {
15891589
new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(TEST_WITH_DUP_NAME_IN_ALIAS_CONTEXT);

0 commit comments

Comments
 (0)