Skip to content

Commit

Permalink
Replace usage of internal java.xml class with public abstraction (#1098)
Browse files Browse the repository at this point in the history
This commit fixes problem of using DocumentBuilderFactoryImpl from com.sun.org.apache.xerces.internal.jaxp package. Problem arises as this package is not public (not exported) since JDK 9. Solution is to replace use of this class with DocumentBuilderFactory from exported package java.xml.parsers.
  • Loading branch information
kr5ture authored and tomakehurst committed Mar 17, 2019
1 parent 739999f commit 54f500a
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions src/main/java/com/github/tomakehurst/wiremock/common/Xml.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/
package com.github.tomakehurst.wiremock.common;

import com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl;
import org.custommonkey.xmlunit.XMLUnit;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
Expand Down Expand Up @@ -150,14 +149,40 @@ public static DocumentBuilderFactory newDocumentBuilderFactory() {
}
}

public static class SkipResolvingEntitiesDocumentBuilderFactory extends DocumentBuilderFactoryImpl {
public static class SkipResolvingEntitiesDocumentBuilderFactory extends DocumentBuilderFactory {
private final DocumentBuilderFactory documentBuilderFactory;

public SkipResolvingEntitiesDocumentBuilderFactory() {
documentBuilderFactory = DocumentBuilderFactory.newInstance();
}

@Override
public DocumentBuilder newDocumentBuilder() throws ParserConfigurationException {
DocumentBuilder documentBuilder = super.newDocumentBuilder();
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
documentBuilder.setEntityResolver(new SkipResolvingEntitiesDocumentBuilderFactory.ResolveToEmptyString());
return documentBuilder;
}

@Override
public void setAttribute(String name, Object value) throws IllegalArgumentException {
documentBuilderFactory.setAttribute(name, value);
}

@Override
public Object getAttribute(String name) throws IllegalArgumentException {
return documentBuilderFactory.getAttribute(name);
}

@Override
public void setFeature(String name, boolean value) throws ParserConfigurationException {
documentBuilderFactory.setFeature(name, value);
}

@Override
public boolean getFeature(String name) throws ParserConfigurationException {
return documentBuilderFactory.getFeature(name);
}

private static class ResolveToEmptyString implements EntityResolver {
@Override
public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException {
Expand Down

0 comments on commit 54f500a

Please sign in to comment.