Skip to content

Commit

Permalink
Updating various old/moved URL references found across project (`jett…
Browse files Browse the repository at this point in the history
…y-10.0.x`) (#10098)

* Now that the migration of `https://eclipse.org/jetty/` to `https://eclipse.dev/jetty/` has occurred, it is time to review the URI use in our project

+ Added more URIs to XmlConfiguration

---------

Signed-off-by: Joakim Erdfelt <joakim.erdfelt@gmail.com>
  • Loading branch information
joakime committed Aug 11, 2023
1 parent 9a0ad21 commit a7dea3e
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,10 @@ public void stop() throws Exception
public void testTmpDirectory() throws Exception
{
Path warPath = MavenTestingUtils.getTestResourcePath("webapps/foo-webapp-1.war");
String deploymentXml = "<Configure class=\"org.eclipse.jetty.webapp.WebAppContext\">\n" +
String deploymentXml =
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" +
"<!DOCTYPE Configure PUBLIC \"-//Jetty//Configure//EN\" \"https://eclipse.dev/jetty/configure.dtd\">\n" +
"<Configure class=\"org.eclipse.jetty.webapp.WebAppContext\">\n" +
"<Set name=\"war\">" + warPath + "</Set>\n" +
"<Set name=\"tempDirectory\">" + tmpDir + "</Set>\n" +
"<Set name=\"persistTempDirectory\">false</Set>\n" +
Expand Down Expand Up @@ -141,7 +144,10 @@ public void testTmpDirectory() throws Exception
public void testPersistentTmpDirectory() throws Exception
{
Path warPath = MavenTestingUtils.getTestResourcePath("webapps/foo-webapp-1.war");
String deploymentXml = "<Configure class=\"org.eclipse.jetty.webapp.WebAppContext\">\n" +
String deploymentXml =
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" +
"<!DOCTYPE Configure PUBLIC \"-//Jetty//Configure//EN\" \"https://eclipse.dev/jetty/configure.dtd\">\n" +
"<Configure class=\"org.eclipse.jetty.webapp.WebAppContext\">\n" +
"<Set name=\"war\">" + warPath + "</Set>\n" +
"<Set name=\"tempDirectory\">" + tmpDir + "</Set>\n" +
"<Set name=\"persistTempDirectory\">true</Set>\n" +
Expand Down
2 changes: 2 additions & 0 deletions jetty-deploy/src/test/resources/context-binding-test-1.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "https://eclipse.dev/jetty/configure_9_3.dtd">
<Configure class="org.eclipse.jetty.webapp.WebAppContext">

<Call name="addServerClass">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

package org.eclipse.jetty.xml;

import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.StringReader;
Expand Down Expand Up @@ -204,7 +205,7 @@ public static String normalizeURI(String uri)
private final String _dtd;
private ConfigurationProcessor _processor;

ConfigurationParser getParser()
public XmlParser getXmlParser()
{
Pool<ConfigurationParser>.Entry entry = __parsers.acquire(ConfigurationParser::new);
if (entry == null)
Expand All @@ -221,7 +222,8 @@ ConfigurationParser getParser()
*/
public XmlConfiguration(Resource resource) throws SAXException, IOException
{
try (ConfigurationParser parser = getParser(); InputStream inputStream = resource.getInputStream())
XmlParser parser = getXmlParser();
try (InputStream inputStream = resource.getInputStream())
{
_location = resource;
setConfig(parser.parse(inputStream));
Expand All @@ -231,6 +233,11 @@ public XmlConfiguration(Resource resource) throws SAXException, IOException
{
throw new SAXException("Unable to parse: " + resource + " ", e);
}
finally
{
if (parser instanceof Closeable)
((Closeable)parser).close();
}
}

/**
Expand Down Expand Up @@ -262,13 +269,19 @@ public XmlConfiguration(String configuration) throws SAXException, IOException
configuration = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" +
"<!DOCTYPE Configure PUBLIC \"-//Jetty//Configure//EN\" \"http://www.eclipse.org/jetty/configure_9_3.dtd\">" +
configuration;
try (ConfigurationParser parser = getParser(); StringReader reader = new StringReader(configuration))
XmlParser parser = getXmlParser();
try (StringReader reader = new StringReader(configuration))
{
InputSource source = new InputSource(reader);
_location = null;
setConfig(parser.parse(source));
_dtd = parser.getDTD();
}
finally
{
if (parser instanceof Closeable)
((Closeable)parser).close();
}
}

/**
Expand All @@ -283,12 +296,18 @@ public XmlConfiguration(String configuration) throws SAXException, IOException
public XmlConfiguration(InputStream configuration) throws SAXException, IOException
{
InputSource source = new InputSource(configuration);
try (ConfigurationParser parser = getParser())
XmlParser parser = getXmlParser();
try
{
_location = null;
setConfig(parser.parse(source));
_dtd = parser.getDTD();
}
finally
{
if (parser instanceof Closeable)
((Closeable)parser).close();
}
}

@Override
Expand Down Expand Up @@ -1923,7 +1942,7 @@ else if (arg.toLowerCase(Locale.ENGLISH).endsWith(".properties"))
}
}

private static class ConfigurationParser extends XmlParser implements AutoCloseable
private static class ConfigurationParser extends XmlParser implements Closeable
{
private final Pool<ConfigurationParser>.Entry _entry;

Expand All @@ -1947,7 +1966,9 @@ private ConfigurationParser(Pool<ConfigurationParser>.Entry entry)
redirectEntity("http://jetty.mortbay.org/configure.dtd", config93);
redirectEntity("http://jetty.eclipse.org/configure.dtd", config93);
redirectEntity("https://jetty.eclipse.org/configure.dtd", config93);
redirectEntity("http://jetty.mortbay.org/configure.dtd", config93);

// Register all variations of DOCTYPE entity references for Config 9.3
String[] schemes = {"http", "https"};
String[] hosts = {"www.eclipse.org", "eclipse.org", "www.eclipse.dev", "eclipse.dev"};
String[] paths = {"/jetty/configure.dtd", "/jetty/configure_9_3.dtd"};
Expand All @@ -1958,7 +1979,7 @@ private ConfigurationParser(Pool<ConfigurationParser>.Entry entry)
{
for (String path : paths)
{
redirectEntity(scheme + "://" + host + path, config93);
redirectEntity(String.format("%s://%s%s", scheme, host, path), config93);
}
}
}
Expand Down
17 changes: 6 additions & 11 deletions jetty-xml/src/main/java/org/eclipse/jetty/xml/XmlParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -271,18 +271,10 @@ protected InputSource resolveEntity(String pid, String sid)
if (pid != null)
entity = _redirectMap.get(pid);
if (entity == null)
entity = _redirectMap.get(sid);
if (entity == null)
{
String dtd = sid;
if (dtd.lastIndexOf('/') >= 0)
dtd = dtd.substring(dtd.lastIndexOf('/') + 1);

if (LOG.isDebugEnabled())
LOG.debug("Can't exact match entity in redirect map, trying " + dtd);
entity = _redirectMap.get(dtd);
}
entity = (URL)_redirectMap.get(sid);

// Only serve entity if found.
// We don't want to serve from unknown hosts or random paths.
if (entity != null)
{
try
Expand All @@ -299,6 +291,9 @@ protected InputSource resolveEntity(String pid, String sid)
LOG.ignore(e);
}
}

if (LOG.isDebugEnabled())
LOG.debug("Entity not found for PID:{} / SID:{}", pid, sid);
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
import org.junit.jupiter.params.provider.ArgumentsProvider;
import org.junit.jupiter.params.provider.ArgumentsSource;
import org.junit.jupiter.params.provider.MethodSource;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;

import static java.nio.charset.StandardCharsets.UTF_8;
Expand Down Expand Up @@ -105,8 +106,16 @@ public void testMortBay() throws Exception
configuration.configure();
}

public static Stream<Arguments> xmlConfigs()
{
return Stream.of(
Arguments.of("org/eclipse/jetty/xml/configureWithAttr.xml"),
Arguments.of("org/eclipse/jetty/xml/configureWithElements.xml")
);
}

@ParameterizedTest
@ArgumentsSource(ScenarioProvider.class)
@MethodSource("xmlConfigs")
public void testPassedObject(String configure) throws Exception
{
Map<String, String> properties = new HashMap<>();
Expand Down Expand Up @@ -1728,6 +1737,43 @@ public static Predicate<String> deprecatedDebug(Class<?> testClass)
}
}

public static Stream<Arguments> xmlSystemIdSource()
{
List<Arguments> ids = new ArrayList<>();

String[] schemes = {"http", "https"};
String[] hosts = {"eclipse.org", "www.eclipse.org", "eclipse.dev", "www.eclipse.dev"};
String[] paths = {"/jetty/configure.dtd", "/jetty/configure_9_3.dtd"};

for (String scheme: schemes)
{
for (String host: hosts)
{
for (String path: paths)
{
ids.add(Arguments.of(String.format("%s://%s%s", scheme, host, path)));
}
}
}

return ids.stream();
}

/**
* Test to ensure that all the XML System ID variants are covered in the
* {@link XmlConfiguration} internals.
*/
@ParameterizedTest
@MethodSource("xmlSystemIdSource")
public void testSystemIdVariants(String xmlSystemId) throws IOException, SAXException
{
// empty raw xml, just to instantiate XmlConfiguration, so we can access the XmlParser / ConfigurationParser.
XmlConfiguration xmlConfiguration = asXmlConfiguration("<Configure class=\"org.eclipse.jetty.xml.TestConfiguration\" />");
XmlParser configurationProcessor = xmlConfiguration.getXmlParser();
InputSource inputSource = configurationProcessor.resolveEntity(null, xmlSystemId);
assertNotNull(inputSource, "SystemID: " + xmlSystemId + " does not exist");
}

private void assertHasExpectedLines(String type, List<String> actualLines, String[] expectedLines)
{
assertThat("Count of " + type, actualLines.size(), is(expectedLines.length));
Expand Down

0 comments on commit a7dea3e

Please sign in to comment.