Issue #1676 - Removing Deprecated Resource.getURL()
Signed-off-by: Joakim Erdfelt <joakim.erdfelt@gmail.com>
This commit is contained in:
parent
ce3f6634b5
commit
5658bf96f6
|
@ -127,7 +127,7 @@ public class SelectiveJarResource extends JarResource
|
||||||
if (!exists())
|
if (!exists())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
String urlString = this.getURL().toExternalForm().trim();
|
String urlString = this.getURI().toASCIIString().trim();
|
||||||
int endOfJarUrl = urlString.indexOf("!/");
|
int endOfJarUrl = urlString.indexOf("!/");
|
||||||
int startOfJarUrl = (endOfJarUrl >= 0?4:0);
|
int startOfJarUrl = (endOfJarUrl >= 0?4:0);
|
||||||
|
|
||||||
|
|
|
@ -19,30 +19,24 @@
|
||||||
package org.eclipse.jetty.osgi.boot;
|
package org.eclipse.jetty.osgi.boot;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.net.URI;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.security.PrivilegedExceptionAction;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Dictionary;
|
import java.util.Dictionary;
|
||||||
import java.util.Enumeration;
|
import java.util.Enumeration;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
import org.eclipse.jetty.annotations.AnnotationConfiguration;
|
|
||||||
import org.eclipse.jetty.deploy.App;
|
import org.eclipse.jetty.deploy.App;
|
||||||
import org.eclipse.jetty.deploy.AppProvider;
|
import org.eclipse.jetty.deploy.AppProvider;
|
||||||
import org.eclipse.jetty.deploy.DeploymentManager;
|
import org.eclipse.jetty.deploy.DeploymentManager;
|
||||||
import org.eclipse.jetty.osgi.boot.internal.serverfactory.ServerInstanceWrapper;
|
import org.eclipse.jetty.osgi.boot.internal.serverfactory.ServerInstanceWrapper;
|
||||||
import org.eclipse.jetty.osgi.boot.internal.webapp.OSGiWebappClassLoader;
|
import org.eclipse.jetty.osgi.boot.internal.webapp.OSGiWebappClassLoader;
|
||||||
import org.eclipse.jetty.osgi.boot.utils.BundleFileLocatorHelperFactory;
|
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.server.handler.ContextHandler;
|
||||||
import org.eclipse.jetty.util.Loader;
|
|
||||||
import org.eclipse.jetty.util.component.AbstractLifeCycle;
|
import org.eclipse.jetty.util.component.AbstractLifeCycle;
|
||||||
import org.eclipse.jetty.util.log.Log;
|
import org.eclipse.jetty.util.log.Log;
|
||||||
import org.eclipse.jetty.util.log.Logger;
|
import org.eclipse.jetty.util.log.Logger;
|
||||||
import org.eclipse.jetty.util.resource.JarResource;
|
import org.eclipse.jetty.util.resource.JarResource;
|
||||||
import org.eclipse.jetty.util.resource.Resource;
|
import org.eclipse.jetty.util.resource.Resource;
|
||||||
import org.eclipse.jetty.webapp.Configuration;
|
|
||||||
import org.eclipse.jetty.webapp.WebAppClassLoader;
|
import org.eclipse.jetty.webapp.WebAppClassLoader;
|
||||||
import org.eclipse.jetty.webapp.WebAppContext;
|
import org.eclipse.jetty.webapp.WebAppContext;
|
||||||
import org.eclipse.jetty.xml.XmlConfiguration;
|
import org.eclipse.jetty.xml.XmlConfiguration;
|
||||||
|
@ -380,11 +374,17 @@ public abstract class AbstractWebAppProvider extends AbstractLifeCycle implement
|
||||||
|
|
||||||
Thread.currentThread().setContextClassLoader(_webApp.getClassLoader());
|
Thread.currentThread().setContextClassLoader(_webApp.getClassLoader());
|
||||||
|
|
||||||
|
URI contextXmlUri = null;
|
||||||
|
|
||||||
//TODO replace this with getting the InputStream so we don't cache in URL
|
//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
|
//Try looking for a context xml file in META-INF with a specific name
|
||||||
URL contextXmlUrl = _bundle.getEntry("/META-INF/jetty-webapp-context.xml");
|
URL url = _bundle.getEntry("/META-INF/jetty-webapp-context.xml");
|
||||||
|
if(url != null)
|
||||||
if (contextXmlUrl == 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
|
//Didn't find specially named file, try looking for a property that names a context xml file to use
|
||||||
if (_properties != null)
|
if (_properties != null)
|
||||||
|
@ -401,18 +401,20 @@ public abstract class AbstractWebAppProvider extends AbstractLifeCycle implement
|
||||||
jettyHome = System.getProperty(OSGiServerConstants.JETTY_HOME);
|
jettyHome = System.getProperty(OSGiServerConstants.JETTY_HOME);
|
||||||
Resource res = findFile(filename, jettyHome, overrideBundleInstallLocation, _bundle);
|
Resource res = findFile(filename, jettyHome, overrideBundleInstallLocation, _bundle);
|
||||||
if (res != null)
|
if (res != null)
|
||||||
contextXmlUrl = res.getURL();
|
{
|
||||||
|
contextXmlUri = res.getURI();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (contextXmlUrl == null)
|
if (contextXmlUri == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Apply it just as the standard jetty ContextProvider would do
|
// 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(()->
|
WebAppClassLoader.runWithServerClassAccess(()->
|
||||||
{
|
{
|
||||||
HashMap<String,String> properties = new HashMap<>();
|
HashMap<String,String> properties = new HashMap<>();
|
||||||
|
|
|
@ -105,7 +105,7 @@ public class PreconfigureQuickStartWar
|
||||||
{
|
{
|
||||||
if (xml.isDirectory() || !xml.toString().toLowerCase(Locale.ENGLISH).endsWith(".xml"))
|
if (xml.isDirectory() || !xml.toString().toLowerCase(Locale.ENGLISH).endsWith(".xml"))
|
||||||
error("Bad context.xml: "+xml);
|
error("Bad context.xml: "+xml);
|
||||||
XmlConfiguration xmlConfiguration = new XmlConfiguration(xml.getURL());
|
XmlConfiguration xmlConfiguration = new XmlConfiguration(xml.getURI());
|
||||||
xmlConfiguration.configure(webapp);
|
xmlConfiguration.configure(webapp);
|
||||||
}
|
}
|
||||||
webapp.setResourceBase(dir.getFile().getAbsolutePath());
|
webapp.setResourceBase(dir.getFile().getAbsolutePath());
|
||||||
|
|
|
@ -20,9 +20,12 @@ package org.eclipse.jetty.runner;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.PrintStream;
|
import java.io.PrintStream;
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URI;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLClassLoader;
|
import java.net.URLClassLoader;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
@ -97,7 +100,7 @@ public class Runner
|
||||||
*/
|
*/
|
||||||
public class Classpath
|
public class Classpath
|
||||||
{
|
{
|
||||||
private List<URL> _classpath = new ArrayList<>();
|
private List<URI> _classpath = new ArrayList<>();
|
||||||
|
|
||||||
public void addJars (Resource lib) throws IOException
|
public void addJars (Resource lib) throws IOException
|
||||||
{
|
{
|
||||||
|
@ -123,8 +126,7 @@ public class Runner
|
||||||
if (lowerCasePath.endsWith(".jar") ||
|
if (lowerCasePath.endsWith(".jar") ||
|
||||||
lowerCasePath.endsWith(".zip"))
|
lowerCasePath.endsWith(".zip"))
|
||||||
{
|
{
|
||||||
URL url = item.getURL();
|
_classpath.add(item.getURI());
|
||||||
_classpath.add(url);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -136,13 +138,13 @@ public class Runner
|
||||||
{
|
{
|
||||||
if (path == null || !path.exists())
|
if (path == null || !path.exists())
|
||||||
throw new IllegalStateException ("No such path: "+path);
|
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 @@ public class Runner
|
||||||
for (String cfg : _configFiles)
|
for (String cfg : _configFiles)
|
||||||
{
|
{
|
||||||
try (Resource resource = Resource.newResource(cfg)) {
|
try (Resource resource = Resource.newResource(cfg)) {
|
||||||
XmlConfiguration xmlConfiguration = new XmlConfiguration(resource.getURL());
|
XmlConfiguration xmlConfiguration = new XmlConfiguration(resource.getURI());
|
||||||
xmlConfiguration.configure(_server);
|
xmlConfiguration.configure(_server);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -430,7 +432,7 @@ public class Runner
|
||||||
if (!ctx.isDirectory() && ctx.toString().toLowerCase(Locale.ENGLISH).endsWith(".xml"))
|
if (!ctx.isDirectory() && ctx.toString().toLowerCase(Locale.ENGLISH).endsWith(".xml"))
|
||||||
{
|
{
|
||||||
// It is a context config file
|
// It is a context config file
|
||||||
XmlConfiguration xmlConfiguration = new XmlConfiguration(ctx.getURL());
|
XmlConfiguration xmlConfiguration = new XmlConfiguration(ctx.getURI());
|
||||||
xmlConfiguration.getIdMap().put("Server", _server);
|
xmlConfiguration.getIdMap().put("Server", _server);
|
||||||
ContextHandler handler = (ContextHandler) xmlConfiguration.configure();
|
ContextHandler handler = (ContextHandler) xmlConfiguration.configure();
|
||||||
if (contextPathSet)
|
if (contextPathSet)
|
||||||
|
@ -522,21 +524,37 @@ public class Runner
|
||||||
_server.join();
|
_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)
|
* Establish a classloader with custom paths (if any)
|
||||||
*/
|
*/
|
||||||
protected void initClassLoader()
|
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)
|
if (context == null)
|
||||||
_classLoader=new URLClassLoader(paths);
|
{
|
||||||
|
_classLoader = new URLClassLoader(paths);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
_classLoader=new URLClassLoader(paths, context);
|
{
|
||||||
|
_classLoader = new URLClassLoader(paths, context);
|
||||||
|
}
|
||||||
|
|
||||||
Thread.currentThread().setContextClassLoader(_classLoader);
|
Thread.currentThread().setContextClassLoader(_classLoader);
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,10 +18,8 @@
|
||||||
|
|
||||||
package org.eclipse.jetty.server;
|
package org.eclipse.jetty.server;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
|
|
||||||
import org.eclipse.jetty.http.CompressedContentFormat;
|
import org.eclipse.jetty.http.CompressedContentFormat;
|
||||||
|
@ -290,19 +288,6 @@ public class ResourceCacheTest
|
||||||
assertEquals(getContent(cache, "four"), "4 - four (no extension)");
|
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
|
static String getContent(CachedContentFactory rc, String path) throws Exception
|
||||||
{
|
{
|
||||||
HttpContent content = rc.getContent(path, rc.getMaxCachedFileSize());
|
HttpContent content = rc.getContent(path, rc.getMaxCachedFileSize());
|
||||||
|
|
|
@ -22,7 +22,7 @@ import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
import java.net.URI;
|
||||||
import java.nio.channels.ReadableByteChannel;
|
import java.nio.channels.ReadableByteChannel;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -74,7 +74,7 @@ public class EmptyResource extends Resource
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public URL getURL()
|
public URI getURI()
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,17 +46,11 @@ public class JarFileResource extends JarResource
|
||||||
private String _path;
|
private String _path;
|
||||||
private boolean _exists;
|
private boolean _exists;
|
||||||
|
|
||||||
/* -------------------------------------------------------- */
|
|
||||||
protected JarFileResource(URL url)
|
|
||||||
{
|
|
||||||
super(url);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ------------------------------------------------------------ */
|
/* ------------------------------------------------------------ */
|
||||||
protected JarFileResource(URL url, boolean useCaches)
|
protected JarFileResource(URL url, boolean useCaches)
|
||||||
{
|
{
|
||||||
super(url, useCaches);
|
super(url, useCaches);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ------------------------------------------------------------ */
|
/* ------------------------------------------------------------ */
|
||||||
@Override
|
@Override
|
||||||
|
@ -377,24 +371,6 @@ public class JarFileResource extends JarResource
|
||||||
return -1;
|
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
|
* Check if this jar:file: resource is contained in the
|
||||||
* named resource. Eg <code>jar:file:///a/b/c/foo.jar!/x.html</code> isContainedIn <code>file:///a/b/c/foo.jar</code>
|
* named resource. Eg <code>jar:file:///a/b/c/foo.jar!/x.html</code> isContainedIn <code>file:///a/b/c/foo.jar</code>
|
||||||
|
|
|
@ -144,7 +144,7 @@ public class JarResource extends URLResource
|
||||||
if(LOG.isDebugEnabled())
|
if(LOG.isDebugEnabled())
|
||||||
LOG.debug("Extract "+this+" to "+directory);
|
LOG.debug("Extract "+this+" to "+directory);
|
||||||
|
|
||||||
String urlString = this.getURL().toExternalForm().trim();
|
String urlString = this.getURI().toASCIIString().trim();
|
||||||
int endOfJarUrl = urlString.indexOf("!/");
|
int endOfJarUrl = urlString.indexOf("!/");
|
||||||
int startOfJarUrl = (endOfJarUrl >= 0?4:0);
|
int startOfJarUrl = (endOfJarUrl >= 0?4:0);
|
||||||
|
|
||||||
|
|
|
@ -408,19 +408,6 @@ public class PathResource extends Resource
|
||||||
return this.uri;
|
return this.uri;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public URL getURL()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
return path.toUri().toURL();
|
|
||||||
}
|
|
||||||
catch (MalformedURLException e)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode()
|
public int hashCode()
|
||||||
{
|
{
|
||||||
|
|
|
@ -349,35 +349,13 @@ public abstract class Resource implements ResourceFactory, Closeable
|
||||||
*/
|
*/
|
||||||
public abstract long length();
|
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.
|
* URI representing the resource.
|
||||||
*
|
*
|
||||||
* @return an URI representing the given resource
|
* @return an URI representing the given resource
|
||||||
*/
|
*/
|
||||||
public URI getURI()
|
public abstract URI getURI();
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
return getURL().toURI();
|
|
||||||
}
|
|
||||||
catch(Exception e)
|
|
||||||
{
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* ------------------------------------------------------------ */
|
/* ------------------------------------------------------------ */
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -22,7 +22,7 @@ import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
import java.net.URI;
|
||||||
import java.nio.channels.ReadableByteChannel;
|
import java.nio.channels.ReadableByteChannel;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
@ -380,16 +380,16 @@ public class ResourceCollection extends Resource
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public URL getURL()
|
public URI getURI()
|
||||||
{
|
{
|
||||||
assertResourcesSet();
|
assertResourcesSet();
|
||||||
|
|
||||||
for (Resource r : _resources)
|
for (Resource r : _resources)
|
||||||
{
|
{
|
||||||
URL url = r.getURL();
|
URI uri = r.getURI();
|
||||||
if (url != null)
|
if (uri != null)
|
||||||
{
|
{
|
||||||
return url;
|
return uri;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -22,10 +22,11 @@ import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URI;
|
||||||
|
import java.net.URISyntaxException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLConnection;
|
import java.net.URLConnection;
|
||||||
import java.nio.channels.ReadableByteChannel;
|
import java.nio.channels.ReadableByteChannel;
|
||||||
import java.security.Permission;
|
|
||||||
|
|
||||||
import org.eclipse.jetty.util.URIUtil;
|
import org.eclipse.jetty.util.URIUtil;
|
||||||
import org.eclipse.jetty.util.log.Log;
|
import org.eclipse.jetty.util.log.Log;
|
||||||
|
@ -154,12 +155,19 @@ public class URLResource extends Resource
|
||||||
|
|
||||||
/* ------------------------------------------------------------ */
|
/* ------------------------------------------------------------ */
|
||||||
/**
|
/**
|
||||||
* Returns an URL representing the given resource
|
* Returns a URI representing the given resource
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public URL getURL()
|
public URI getURI()
|
||||||
{
|
{
|
||||||
return _url;
|
try
|
||||||
|
{
|
||||||
|
return _url.toURI();
|
||||||
|
}
|
||||||
|
catch (URISyntaxException e)
|
||||||
|
{
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ------------------------------------------------------------ */
|
/* ------------------------------------------------------------ */
|
||||||
|
|
|
@ -578,26 +578,6 @@ public class FileSystemResourceTest
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
@ParameterizedTest
|
|
||||||
@MethodSource("fsResourceProvider")
|
|
||||||
public void testGetURL(Class<PathResource> 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
|
@ParameterizedTest
|
||||||
@MethodSource("fsResourceProvider")
|
@MethodSource("fsResourceProvider")
|
||||||
public void testList(Class<PathResource> resourceClass) throws Exception
|
public void testList(Class<PathResource> resourceClass) throws Exception
|
||||||
|
|
|
@ -20,6 +20,7 @@ package org.eclipse.jetty.util.resource;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
|
||||||
|
@ -31,8 +32,8 @@ import org.eclipse.jetty.util.IO;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.api.extension.ExtendWith;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
|
|
||||||
import static org.hamcrest.MatcherAssert.assertThat;
|
|
||||||
import static org.hamcrest.CoreMatchers.is;
|
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.assertEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
@ -158,7 +159,7 @@ public class ResourceCollectionTest
|
||||||
assertThrows(IllegalStateException.class, coll::getFile);
|
assertThrows(IllegalStateException.class, coll::getFile);
|
||||||
assertThrows(IllegalStateException.class, coll::getInputStream);
|
assertThrows(IllegalStateException.class, coll::getInputStream);
|
||||||
assertThrows(IllegalStateException.class, coll::getReadableByteChannel);
|
assertThrows(IllegalStateException.class, coll::getReadableByteChannel);
|
||||||
assertThrows(IllegalStateException.class, coll::getURL);
|
assertThrows(IllegalStateException.class, coll::getURI);
|
||||||
assertThrows(IllegalStateException.class, coll::getName);
|
assertThrows(IllegalStateException.class, coll::getName);
|
||||||
assertThrows(IllegalStateException.class, coll::isDirectory);
|
assertThrows(IllegalStateException.class, coll::isDirectory);
|
||||||
assertThrows(IllegalStateException.class, coll::lastModified);
|
assertThrows(IllegalStateException.class, coll::lastModified);
|
||||||
|
@ -239,12 +240,17 @@ public class ResourceCollectionTest
|
||||||
|
|
||||||
static String getContent(Resource r, String path) throws Exception
|
static String getContent(Resource r, String path) throws Exception
|
||||||
{
|
{
|
||||||
|
Resource resource = r.addPath(path);
|
||||||
StringBuilder buffer = new StringBuilder();
|
StringBuilder buffer = new StringBuilder();
|
||||||
String line;
|
try (InputStream in = resource.getInputStream();
|
||||||
try (BufferedReader br = new BufferedReader(new InputStreamReader(r.addPath(path).getURL().openStream())))
|
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);
|
buffer.append(line);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return buffer.toString();
|
return buffer.toString();
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,18 +18,11 @@
|
||||||
|
|
||||||
package org.eclipse.jetty.webapp;
|
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.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
import java.net.URI;
|
||||||
import java.nio.channels.ReadableByteChannel;
|
import java.nio.channels.ReadableByteChannel;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -37,6 +30,13 @@ import java.util.List;
|
||||||
import org.eclipse.jetty.util.resource.Resource;
|
import org.eclipse.jetty.util.resource.Resource;
|
||||||
import org.junit.jupiter.api.Test;
|
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
|
* OrderingTest
|
||||||
*/
|
*/
|
||||||
|
@ -112,7 +112,7 @@ public class OrderingTest
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public URL getURL()
|
public URI getURI()
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,6 +29,7 @@ import java.lang.reflect.Method;
|
||||||
import java.lang.reflect.Modifier;
|
import java.lang.reflect.Modifier;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URI;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
@ -191,6 +192,23 @@ public class XmlConfiguration
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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.
|
* Reads and parses the XML configuration string.
|
||||||
*
|
*
|
||||||
|
|
|
@ -74,7 +74,7 @@ public class QuickStartTest
|
||||||
if (contextXml != null)
|
if (contextXml != null)
|
||||||
{
|
{
|
||||||
// System.err.println("Applying "+contextXml);
|
// System.err.println("Applying "+contextXml);
|
||||||
XmlConfiguration xmlConfiguration = new XmlConfiguration(contextXml.getURL());
|
XmlConfiguration xmlConfiguration = new XmlConfiguration(contextXml.getURI());
|
||||||
xmlConfiguration.configure(webapp);
|
xmlConfiguration.configure(webapp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -123,7 +123,7 @@ public class QuickStartTest
|
||||||
if (contextXml != null)
|
if (contextXml != null)
|
||||||
{
|
{
|
||||||
// System.err.println("Applying "+contextXml);
|
// System.err.println("Applying "+contextXml);
|
||||||
XmlConfiguration xmlConfiguration = new XmlConfiguration(contextXml.getURL());
|
XmlConfiguration xmlConfiguration = new XmlConfiguration(contextXml.getURI());
|
||||||
xmlConfiguration.configure(webapp);
|
xmlConfiguration.configure(webapp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -49,7 +49,7 @@ public class Quickstart
|
||||||
if (contextXml != null)
|
if (contextXml != null)
|
||||||
{
|
{
|
||||||
// System.err.println("Applying "+contextXml);
|
// System.err.println("Applying "+contextXml);
|
||||||
XmlConfiguration xmlConfiguration = new XmlConfiguration(contextXml.getURL());
|
XmlConfiguration xmlConfiguration = new XmlConfiguration(contextXml.getURI());
|
||||||
xmlConfiguration.configure(webapp);
|
xmlConfiguration.configure(webapp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue