From 5658bf96f6920f789039291d306a1c696d6a5569 Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Fri, 1 Mar 2019 08:24:58 -0500 Subject: [PATCH] Issue #1676 - Removing Deprecated Resource.getURL() Signed-off-by: Joakim Erdfelt --- .../maven/plugin/SelectiveJarResource.java | 2 +- .../osgi/boot/AbstractWebAppProvider.java | 30 ++++++------ .../quickstart/PreconfigureQuickStartWar.java | 2 +- .../java/org/eclipse/jetty/runner/Runner.java | 46 +++++++++++++------ .../jetty/server/ResourceCacheTest.java | 15 ------ .../jetty/util/resource/EmptyResource.java | 4 +- .../jetty/util/resource/JarFileResource.java | 26 +---------- .../jetty/util/resource/JarResource.java | 2 +- .../jetty/util/resource/PathResource.java | 13 ------ .../eclipse/jetty/util/resource/Resource.java | 24 +--------- .../util/resource/ResourceCollection.java | 10 ++-- .../jetty/util/resource/URLResource.java | 16 +++++-- .../util/resource/FileSystemResourceTest.java | 20 -------- .../util/resource/ResourceCollectionTest.java | 16 +++++-- .../eclipse/jetty/webapp/OrderingTest.java | 18 ++++---- .../eclipse/jetty/xml/XmlConfiguration.java | 18 ++++++++ .../jetty/quickstart/QuickStartTest.java | 4 +- .../eclipse/jetty/quickstart/Quickstart.java | 2 +- 18 files changed, 113 insertions(+), 155 deletions(-) diff --git a/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/SelectiveJarResource.java b/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/SelectiveJarResource.java index 91a9d4b96234..9a0fe5b567d2 100644 --- a/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/SelectiveJarResource.java +++ b/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/SelectiveJarResource.java @@ -127,7 +127,7 @@ public void copyTo(File directory) throws IOException if (!exists()) return; - String urlString = this.getURL().toExternalForm().trim(); + String urlString = this.getURI().toASCIIString().trim(); int endOfJarUrl = urlString.indexOf("!/"); int startOfJarUrl = (endOfJarUrl >= 0?4:0); diff --git a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/AbstractWebAppProvider.java b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/AbstractWebAppProvider.java index c48988d44b0e..8ec84811fc2f 100644 --- a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/AbstractWebAppProvider.java +++ b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/AbstractWebAppProvider.java @@ -19,30 +19,24 @@ package org.eclipse.jetty.osgi.boot; import java.io.File; +import java.net.URI; import java.net.URL; -import java.security.PrivilegedExceptionAction; -import java.util.ArrayList; import java.util.Dictionary; import java.util.Enumeration; import java.util.HashMap; -import org.eclipse.jetty.annotations.AnnotationConfiguration; import org.eclipse.jetty.deploy.App; import org.eclipse.jetty.deploy.AppProvider; import org.eclipse.jetty.deploy.DeploymentManager; import org.eclipse.jetty.osgi.boot.internal.serverfactory.ServerInstanceWrapper; import org.eclipse.jetty.osgi.boot.internal.webapp.OSGiWebappClassLoader; import org.eclipse.jetty.osgi.boot.utils.BundleFileLocatorHelperFactory; -import org.eclipse.jetty.plus.webapp.EnvConfiguration; -import org.eclipse.jetty.plus.webapp.PlusConfiguration; import org.eclipse.jetty.server.handler.ContextHandler; -import org.eclipse.jetty.util.Loader; import org.eclipse.jetty.util.component.AbstractLifeCycle; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.util.resource.JarResource; import org.eclipse.jetty.util.resource.Resource; -import org.eclipse.jetty.webapp.Configuration; import org.eclipse.jetty.webapp.WebAppClassLoader; import org.eclipse.jetty.webapp.WebAppContext; import org.eclipse.jetty.xml.XmlConfiguration; @@ -380,11 +374,17 @@ protected void applyMetaInfContextXml(Resource rootResource, String overrideBund Thread.currentThread().setContextClassLoader(_webApp.getClassLoader()); + URI contextXmlUri = null; + //TODO replace this with getting the InputStream so we don't cache in URL //Try looking for a context xml file in META-INF with a specific name - URL contextXmlUrl = _bundle.getEntry("/META-INF/jetty-webapp-context.xml"); - - if (contextXmlUrl == null) + URL url = _bundle.getEntry("/META-INF/jetty-webapp-context.xml"); + if(url != null) + { + contextXmlUri = url.toURI(); + } + + if (contextXmlUri == null) { //Didn't find specially named file, try looking for a property that names a context xml file to use if (_properties != null) @@ -401,18 +401,20 @@ protected void applyMetaInfContextXml(Resource rootResource, String overrideBund jettyHome = System.getProperty(OSGiServerConstants.JETTY_HOME); Resource res = findFile(filename, jettyHome, overrideBundleInstallLocation, _bundle); if (res != null) - contextXmlUrl = res.getURL(); + { + contextXmlUri = res.getURI(); + } } } } } - if (contextXmlUrl == null) + if (contextXmlUri == null) return; // Apply it just as the standard jetty ContextProvider would do - LOG.info("Applying " + contextXmlUrl + " to " + _webApp); + LOG.info("Applying " + contextXmlUri + " to " + _webApp); - XmlConfiguration xmlConfiguration = new XmlConfiguration(contextXmlUrl); + XmlConfiguration xmlConfiguration = new XmlConfiguration(contextXmlUri); WebAppClassLoader.runWithServerClassAccess(()-> { HashMap properties = new HashMap<>(); diff --git a/jetty-quickstart/src/main/java/org/eclipse/jetty/quickstart/PreconfigureQuickStartWar.java b/jetty-quickstart/src/main/java/org/eclipse/jetty/quickstart/PreconfigureQuickStartWar.java index 639bb6f225da..a412cdd063f0 100644 --- a/jetty-quickstart/src/main/java/org/eclipse/jetty/quickstart/PreconfigureQuickStartWar.java +++ b/jetty-quickstart/src/main/java/org/eclipse/jetty/quickstart/PreconfigureQuickStartWar.java @@ -105,7 +105,7 @@ public static void preconfigure(Resource war, Resource dir, Resource xml) throws { if (xml.isDirectory() || !xml.toString().toLowerCase(Locale.ENGLISH).endsWith(".xml")) error("Bad context.xml: "+xml); - XmlConfiguration xmlConfiguration = new XmlConfiguration(xml.getURL()); + XmlConfiguration xmlConfiguration = new XmlConfiguration(xml.getURI()); xmlConfiguration.configure(webapp); } webapp.setResourceBase(dir.getFile().getAbsolutePath()); diff --git a/jetty-runner/src/main/java/org/eclipse/jetty/runner/Runner.java b/jetty-runner/src/main/java/org/eclipse/jetty/runner/Runner.java index 227abe271341..76ad8c155b28 100644 --- a/jetty-runner/src/main/java/org/eclipse/jetty/runner/Runner.java +++ b/jetty-runner/src/main/java/org/eclipse/jetty/runner/Runner.java @@ -20,9 +20,12 @@ import java.io.IOException; import java.io.PrintStream; +import java.net.MalformedURLException; +import java.net.URI; import java.net.URL; import java.net.URLClassLoader; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Locale; @@ -97,7 +100,7 @@ public class Runner */ public class Classpath { - private List _classpath = new ArrayList<>(); + private List _classpath = new ArrayList<>(); public void addJars (Resource lib) throws IOException { @@ -123,8 +126,7 @@ public void addJars (Resource lib) throws IOException if (lowerCasePath.endsWith(".jar") || lowerCasePath.endsWith(".zip")) { - URL url = item.getURL(); - _classpath.add(url); + _classpath.add(item.getURI()); } } } @@ -136,13 +138,13 @@ public void addPath (Resource path) { if (path == null || !path.exists()) throw new IllegalStateException ("No such path: "+path); - _classpath.add(path.getURL()); + _classpath.add(path.getURI()); } - public URL[] asArray () + public URI[] asArray () { - return _classpath.toArray(new URL[_classpath.size()]); + return _classpath.toArray(new URI[0]); } } @@ -325,7 +327,7 @@ else if (args[i].startsWith("--")) for (String cfg : _configFiles) { try (Resource resource = Resource.newResource(cfg)) { - XmlConfiguration xmlConfiguration = new XmlConfiguration(resource.getURL()); + XmlConfiguration xmlConfiguration = new XmlConfiguration(resource.getURI()); xmlConfiguration.configure(_server); } } @@ -430,7 +432,7 @@ else if (args[i].startsWith("--")) if (!ctx.isDirectory() && ctx.toString().toLowerCase(Locale.ENGLISH).endsWith(".xml")) { // It is a context config file - XmlConfiguration xmlConfiguration = new XmlConfiguration(ctx.getURL()); + XmlConfiguration xmlConfiguration = new XmlConfiguration(ctx.getURI()); xmlConfiguration.getIdMap().put("Server", _server); ContextHandler handler = (ContextHandler) xmlConfiguration.configure(); if (contextPathSet) @@ -522,21 +524,37 @@ public void run() throws Exception _server.join(); } + private URL toURL(URI uri) + { + try + { + return uri.toURL(); + } + catch (MalformedURLException e) + { + throw new RuntimeException(e); + } + } + /** * Establish a classloader with custom paths (if any) */ protected void initClassLoader() { - URL[] paths = _classpath.asArray(); + URL[] paths = Arrays.stream(_classpath.asArray()).map(this::toURL).toArray(URL[]::new); - if (_classLoader==null && paths !=null && paths.length > 0) + if (_classLoader == null && paths.length > 0) { - ClassLoader context=Thread.currentThread().getContextClassLoader(); + ClassLoader context = Thread.currentThread().getContextClassLoader(); - if (context==null) - _classLoader=new URLClassLoader(paths); + if (context == null) + { + _classLoader = new URLClassLoader(paths); + } else - _classLoader=new URLClassLoader(paths, context); + { + _classLoader = new URLClassLoader(paths, context); + } Thread.currentThread().setContextClassLoader(_classLoader); } diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/ResourceCacheTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/ResourceCacheTest.java index 64ea154c011f..2091db68934c 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/ResourceCacheTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/ResourceCacheTest.java @@ -18,10 +18,8 @@ package org.eclipse.jetty.server; -import java.io.BufferedReader; import java.io.File; import java.io.FileOutputStream; -import java.io.InputStreamReader; import java.io.OutputStream; import org.eclipse.jetty.http.CompressedContentFormat; @@ -290,19 +288,6 @@ public void testNoextension() throws Exception assertEquals(getContent(cache, "four"), "4 - four (no extension)"); } - - static String getContent(Resource r, String path) throws Exception - { - StringBuilder buffer = new StringBuilder(); - String line = null; - try (BufferedReader br = new BufferedReader(new InputStreamReader(r.addPath(path).getURL().openStream()))) - { - while((line=br.readLine())!=null) - buffer.append(line); - } - return buffer.toString(); - } - static String getContent(CachedContentFactory rc, String path) throws Exception { HttpContent content = rc.getContent(path, rc.getMaxCachedFileSize()); diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/resource/EmptyResource.java b/jetty-util/src/main/java/org/eclipse/jetty/util/resource/EmptyResource.java index 247495925c3d..a0e27673f7ec 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/resource/EmptyResource.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/resource/EmptyResource.java @@ -22,7 +22,7 @@ import java.io.IOException; import java.io.InputStream; import java.net.MalformedURLException; -import java.net.URL; +import java.net.URI; import java.nio.channels.ReadableByteChannel; /** @@ -74,7 +74,7 @@ public long length() } @Override - public URL getURL() + public URI getURI() { return null; } diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/resource/JarFileResource.java b/jetty-util/src/main/java/org/eclipse/jetty/util/resource/JarFileResource.java index 406781fa8cad..e41fc0246c31 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/resource/JarFileResource.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/resource/JarFileResource.java @@ -46,17 +46,11 @@ public class JarFileResource extends JarResource private String _path; private boolean _exists; - /* -------------------------------------------------------- */ - protected JarFileResource(URL url) - { - super(url); - } - /* ------------------------------------------------------------ */ protected JarFileResource(URL url, boolean useCaches) { super(url, useCaches); - } + } /* ------------------------------------------------------------ */ @Override @@ -377,24 +371,6 @@ public long length() return -1; } - - /** - * Take a Resource that possibly might use URLConnection caching - * and turn it into one that doesn't. - * @param resource the JarFileResource to obtain without URLConnection caching. - * @return the non-caching resource - */ - public static Resource getNonCachingResource (Resource resource) - { - if (!(resource instanceof JarFileResource)) - return resource; - - JarFileResource oldResource = (JarFileResource)resource; - - JarFileResource newResource = new JarFileResource(oldResource.getURL(), false); - return newResource; - } - /** * Check if this jar:file: resource is contained in the * named resource. Eg jar:file:///a/b/c/foo.jar!/x.html isContainedIn file:///a/b/c/foo.jar diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/resource/JarResource.java b/jetty-util/src/main/java/org/eclipse/jetty/util/resource/JarResource.java index 199141c57c78..6bbb547047bc 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/resource/JarResource.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/resource/JarResource.java @@ -144,7 +144,7 @@ public void copyTo(File directory) if(LOG.isDebugEnabled()) LOG.debug("Extract "+this+" to "+directory); - String urlString = this.getURL().toExternalForm().trim(); + String urlString = this.getURI().toASCIIString().trim(); int endOfJarUrl = urlString.indexOf("!/"); int startOfJarUrl = (endOfJarUrl >= 0?4:0); diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/resource/PathResource.java b/jetty-util/src/main/java/org/eclipse/jetty/util/resource/PathResource.java index beeb6a91bcd6..a14b8b618b20 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/resource/PathResource.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/resource/PathResource.java @@ -408,19 +408,6 @@ public URI getURI() return this.uri; } - @Override - public URL getURL() - { - try - { - return path.toUri().toURL(); - } - catch (MalformedURLException e) - { - return null; - } - } - @Override public int hashCode() { diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/resource/Resource.java b/jetty-util/src/main/java/org/eclipse/jetty/util/resource/Resource.java index 3da6137ec8ff..93d6da92cee1 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/resource/Resource.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/resource/Resource.java @@ -349,35 +349,13 @@ public static boolean isContainedIn (Resource r, Resource containingResource) th */ public abstract long length(); - - /* ------------------------------------------------------------ */ - /** - * URL representing the resource. - * - * @return an URL representing the given resource - * @deprecated use {{@link #getURI()}.toURL() instead. - */ - @Deprecated - public abstract URL getURL(); - /* ------------------------------------------------------------ */ /** * URI representing the resource. * * @return an URI representing the given resource */ - public URI getURI() - { - try - { - return getURL().toURI(); - } - catch(Exception e) - { - throw new RuntimeException(e); - } - } - + public abstract URI getURI(); /* ------------------------------------------------------------ */ /** diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/resource/ResourceCollection.java b/jetty-util/src/main/java/org/eclipse/jetty/util/resource/ResourceCollection.java index ebdbdb8a7028..9413dd621eed 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/resource/ResourceCollection.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/resource/ResourceCollection.java @@ -22,7 +22,7 @@ import java.io.IOException; import java.io.InputStream; import java.net.MalformedURLException; -import java.net.URL; +import java.net.URI; import java.nio.channels.ReadableByteChannel; import java.util.ArrayList; import java.util.Arrays; @@ -380,16 +380,16 @@ public String getName() } @Override - public URL getURL() + public URI getURI() { assertResourcesSet(); for (Resource r : _resources) { - URL url = r.getURL(); - if (url != null) + URI uri = r.getURI(); + if (uri != null) { - return url; + return uri; } } return null; diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/resource/URLResource.java b/jetty-util/src/main/java/org/eclipse/jetty/util/resource/URLResource.java index 97733627a032..34caee778631 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/resource/URLResource.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/resource/URLResource.java @@ -22,10 +22,11 @@ import java.io.IOException; import java.io.InputStream; import java.net.MalformedURLException; +import java.net.URI; +import java.net.URISyntaxException; import java.net.URL; import java.net.URLConnection; import java.nio.channels.ReadableByteChannel; -import java.security.Permission; import org.eclipse.jetty.util.URIUtil; import org.eclipse.jetty.util.log.Log; @@ -154,12 +155,19 @@ public long length() /* ------------------------------------------------------------ */ /** - * Returns an URL representing the given resource + * Returns a URI representing the given resource */ @Override - public URL getURL() + public URI getURI() { - return _url; + try + { + return _url.toURI(); + } + catch (URISyntaxException e) + { + throw new RuntimeException(e); + } } /* ------------------------------------------------------------ */ diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/resource/FileSystemResourceTest.java b/jetty-util/src/test/java/org/eclipse/jetty/util/resource/FileSystemResourceTest.java index 2ee07c5d5d5a..999d479fb17a 100644 --- a/jetty-util/src/test/java/org/eclipse/jetty/util/resource/FileSystemResourceTest.java +++ b/jetty-util/src/test/java/org/eclipse/jetty/util/resource/FileSystemResourceTest.java @@ -578,26 +578,6 @@ public void testGetURI(Class resourceClass) throws Exception } } - @SuppressWarnings("deprecation") - @ParameterizedTest - @MethodSource("fsResourceProvider") - public void testGetURL(Class resourceClass) throws Exception - { - Path dir = workDir.getEmptyPathDir(); - Files.createDirectories(dir); - - Path file = dir.resolve("foo"); - Files.createFile(file); - - URL expected = file.toUri().toURL(); - - try (Resource base = newResource(resourceClass, dir.toFile())) - { - Resource foo = base.addPath("foo"); - assertThat("getURL",foo.getURL(),is(expected)); - } - } - @ParameterizedTest @MethodSource("fsResourceProvider") public void testList(Class resourceClass) throws Exception diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/resource/ResourceCollectionTest.java b/jetty-util/src/test/java/org/eclipse/jetty/util/resource/ResourceCollectionTest.java index f6fa4e80afa4..610c9b2c56f7 100644 --- a/jetty-util/src/test/java/org/eclipse/jetty/util/resource/ResourceCollectionTest.java +++ b/jetty-util/src/test/java/org/eclipse/jetty/util/resource/ResourceCollectionTest.java @@ -20,6 +20,7 @@ import java.io.BufferedReader; import java.io.File; +import java.io.InputStream; import java.io.InputStreamReader; import java.nio.file.Path; @@ -31,8 +32,8 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; -import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -158,7 +159,7 @@ private void assertThrowIllegalStateException(ResourceCollection coll) assertThrows(IllegalStateException.class, coll::getFile); assertThrows(IllegalStateException.class, coll::getInputStream); assertThrows(IllegalStateException.class, coll::getReadableByteChannel); - assertThrows(IllegalStateException.class, coll::getURL); + assertThrows(IllegalStateException.class, coll::getURI); assertThrows(IllegalStateException.class, coll::getName); assertThrows(IllegalStateException.class, coll::isDirectory); assertThrows(IllegalStateException.class, coll::lastModified); @@ -239,12 +240,17 @@ public void testCopyTo() throws Exception static String getContent(Resource r, String path) throws Exception { + Resource resource = r.addPath(path); StringBuilder buffer = new StringBuilder(); - String line; - try (BufferedReader br = new BufferedReader(new InputStreamReader(r.addPath(path).getURL().openStream()))) + try (InputStream in = resource.getInputStream(); + InputStreamReader reader = new InputStreamReader(in); + BufferedReader br = new BufferedReader(reader)) { - while((line=br.readLine())!=null) + String line; + while ((line = br.readLine()) != null) + { buffer.append(line); + } } return buffer.toString(); } diff --git a/jetty-webapp/src/test/java/org/eclipse/jetty/webapp/OrderingTest.java b/jetty-webapp/src/test/java/org/eclipse/jetty/webapp/OrderingTest.java index f7b33ae96913..76a684e4497e 100644 --- a/jetty-webapp/src/test/java/org/eclipse/jetty/webapp/OrderingTest.java +++ b/jetty-webapp/src/test/java/org/eclipse/jetty/webapp/OrderingTest.java @@ -18,18 +18,11 @@ package org.eclipse.jetty.webapp; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.empty; -import static org.hamcrest.Matchers.is; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.fail; - import java.io.File; import java.io.IOException; import java.io.InputStream; import java.net.MalformedURLException; -import java.net.URL; +import java.net.URI; import java.nio.channels.ReadableByteChannel; import java.util.ArrayList; import java.util.List; @@ -37,6 +30,13 @@ import org.eclipse.jetty.util.resource.Resource; import org.junit.jupiter.api.Test; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.empty; +import static org.hamcrest.Matchers.is; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.fail; + /** * OrderingTest */ @@ -112,7 +112,7 @@ public String getName() } @Override - public URL getURL() + public URI getURI() { return null; } diff --git a/jetty-xml/src/main/java/org/eclipse/jetty/xml/XmlConfiguration.java b/jetty-xml/src/main/java/org/eclipse/jetty/xml/XmlConfiguration.java index 2b758624d8cc..d9061ec3aa5a 100644 --- a/jetty-xml/src/main/java/org/eclipse/jetty/xml/XmlConfiguration.java +++ b/jetty-xml/src/main/java/org/eclipse/jetty/xml/XmlConfiguration.java @@ -29,6 +29,7 @@ import java.lang.reflect.Modifier; import java.net.InetAddress; import java.net.MalformedURLException; +import java.net.URI; import java.net.URL; import java.net.UnknownHostException; import java.nio.file.Path; @@ -191,6 +192,23 @@ public XmlConfiguration(URL configuration) throws SAXException, IOException } } + /** + * Reads and parses the XML configuration file. + * + * @param configuration the URI of the XML configuration + * @throws IOException if the configuration could not be read + * @throws SAXException if the configuration could not be parsed + */ + public XmlConfiguration(URI configuration) throws SAXException, IOException + { + synchronized (__parser) + { + _url=configuration.toURL(); + setConfig(__parser.parse(configuration.toString())); + _dtd=__parser.getDTD(); + } + } + /** * Reads and parses the XML configuration string. * diff --git a/tests/test-quickstart/src/test/java/org/eclipse/jetty/quickstart/QuickStartTest.java b/tests/test-quickstart/src/test/java/org/eclipse/jetty/quickstart/QuickStartTest.java index a8d7a56ae1d0..b5d378ad0f3f 100644 --- a/tests/test-quickstart/src/test/java/org/eclipse/jetty/quickstart/QuickStartTest.java +++ b/tests/test-quickstart/src/test/java/org/eclipse/jetty/quickstart/QuickStartTest.java @@ -74,7 +74,7 @@ public void testStandardTestWar() throws Exception if (contextXml != null) { // System.err.println("Applying "+contextXml); - XmlConfiguration xmlConfiguration = new XmlConfiguration(contextXml.getURL()); + XmlConfiguration xmlConfiguration = new XmlConfiguration(contextXml.getURI()); xmlConfiguration.configure(webapp); } @@ -123,7 +123,7 @@ public void testSpecWar() throws Exception if (contextXml != null) { // System.err.println("Applying "+contextXml); - XmlConfiguration xmlConfiguration = new XmlConfiguration(contextXml.getURL()); + XmlConfiguration xmlConfiguration = new XmlConfiguration(contextXml.getURI()); xmlConfiguration.configure(webapp); } diff --git a/tests/test-quickstart/src/test/java/org/eclipse/jetty/quickstart/Quickstart.java b/tests/test-quickstart/src/test/java/org/eclipse/jetty/quickstart/Quickstart.java index 68d52e52f951..c6c2a0a22fed 100644 --- a/tests/test-quickstart/src/test/java/org/eclipse/jetty/quickstart/Quickstart.java +++ b/tests/test-quickstart/src/test/java/org/eclipse/jetty/quickstart/Quickstart.java @@ -49,7 +49,7 @@ public static void main(String... args) throws Exception if (contextXml != null) { // System.err.println("Applying "+contextXml); - XmlConfiguration xmlConfiguration = new XmlConfiguration(contextXml.getURL()); + XmlConfiguration xmlConfiguration = new XmlConfiguration(contextXml.getURI()); xmlConfiguration.configure(webapp); }