Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GEODE-3306: Remove whitespace StringBuffers/nodes created by Apache X… #668

Closed
wants to merge 8 commits into from
2 changes: 2 additions & 0 deletions geode-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ dependencies {
testCompile 'com.pholser:junit-quickcheck-core:' + project.'junit-quickcheck.version'
testCompile 'com.pholser:junit-quickcheck-generators:' + project.'junit-quickcheck.version'
testCompile 'com.pholser:junit-quickcheck-guava:' + project.'junit-quickcheck.version'

testRuntime 'xerces:xercesImpl:' + project.'xercesImpl.version'
}

def generatedResources = "$buildDir/generated-resources/main"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@

import org.apache.geode.cache.util.GatewayConflictResolver;
import org.apache.logging.log4j.Logger;
import org.apache.commons.lang.StringUtils;
import org.xml.sax.Attributes;
import org.xml.sax.ContentHandler;
import org.xml.sax.InputSource;
Expand Down Expand Up @@ -2596,6 +2597,17 @@ private void endDeclarable() {

public void startElement(String namespaceURI, String localName, String qName, Attributes atts)
throws SAXException {
// This while loop pops all StringBuffers at the top of the stack
// that contain only whitespace; see GEODE-3306
while (!stack.empty()) {
Object o = stack.peek();
if (o instanceof StringBuffer && StringUtils.isBlank(((StringBuffer) o).toString())) {
stack.pop();
} else {
break;
}
}

if (qName.equals(CACHE)) {
startCache(atts);
} else if (qName.equals(CLIENT_CACHE)) {
Expand Down Expand Up @@ -2872,6 +2884,17 @@ private void startDiskWriteAttributes(Attributes atts) {
}

public void endElement(String namespaceURI, String localName, String qName) throws SAXException {
// This while loop pops all StringBuffers at the top of the stack
// that contain only whitespace; see GEODE-3306
while (!stack.empty()) {
Object o = stack.peek();
if (o instanceof StringBuffer && StringUtils.isBlank(((StringBuffer) o).toString())) {
stack.pop();
} else {
break;
}
}

try {
// logger.debug("endElement namespaceURI=" + namespaceURI
// + "; localName = " + localName + "; qName = " + qName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,15 @@
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import org.apache.geode.cache.client.ClientCache;
import org.apache.geode.cache.client.ClientCacheFactory;
import org.apache.geode.distributed.internal.DM;
import org.apache.geode.distributed.internal.InternalDistributedSystem;
import org.apache.geode.test.junit.categories.UnitTest;
import org.junit.After;
import org.junit.Rule;
import org.junit.Test;
import org.junit.contrib.java.lang.system.RestoreSystemProperties;
import org.junit.experimental.categories.Category;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
Expand All @@ -47,6 +51,9 @@
@Category(UnitTest.class)
public class CacheXmlParserJUnitTest {

@Rule
public final RestoreSystemProperties restoreSystemProperties = new RestoreSystemProperties();

private static final String NAMESPACE_URI =
"urn:java:org.apache.geode.internal.cache.xmlcache.MockXmlParser";

Expand Down Expand Up @@ -103,18 +110,26 @@ public void testCacheXmlParserWithSimplePool() {
assertNotNull("Did not find simple config.xml file", getClass()
.getResourceAsStream("CacheXmlParserJUnitTest.testSimpleClientCacheXml.cache.xml"));

DM dm = mock(DM.class);

Properties nonDefault = new Properties();
nonDefault.setProperty(MCAST_PORT, "0"); // loner

InternalDistributedSystem system =
InternalDistributedSystem.newInstanceForTesting(dm, nonDefault);
when(dm.getSystem()).thenReturn(system);
InternalDistributedSystem.connect(nonDefault);
ClientCache cache = new ClientCacheFactory(nonDefault).set("cache-xml-file",
"xmlcache/CacheXmlParserJUnitTest.testSimpleClientCacheXml.cache.xml").create();
cache.close();
}

CacheXmlParser.parse(getClass()
.getResourceAsStream("CacheXmlParserJUnitTest.testSimpleClientCacheXml.cache.xml"));
/**
* Test that {@link CacheXmlParser} can parse the test cache.xml file, using the Apache Xerces XML
* parser.
*
* @since Geode 1.3
*/
@Test
public void testCacheXmlParserWithSimplePoolXerces() {
System.setProperty("javax.xml.parsers.SAXParserFactory",
"org.apache.xerces.jaxp.SAXParserFactoryImpl");

testCacheXmlParserWithSimplePool();
}

/**
Expand All @@ -137,6 +152,20 @@ public void testDTDFallbackWithNonEnglishLocal() {
}
}

/**
* Test that {@link CacheXmlParser} falls back to DTD parsing when locale language is not English,
* using the Apache Xerces XML parser.
*
* @since Geode 1.3
*/
@Test
public void testDTDFallbackWithNonEnglishLocalXerces() {
System.setProperty("javax.xml.parsers.SAXParserFactory",
"org.apache.xerces.jaxp.SAXParserFactoryImpl");

testDTDFallbackWithNonEnglishLocal();
}

/**
* Get access to {@link CacheXmlParser} protected methods and fields.
*
Expand Down
1 change: 1 addition & 0 deletions gradle/dependency-versions.properties
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,4 @@ tomcat6.version = 6.0.37
tomcat7.version = 7.0.73
tomcat8.version = 8.5.9
commons-validator.version = 1.6
xercesImpl.version = 2.11.0