Fixing URLResourceFactory
This commit is contained in:
parent
0a95ea2f9c
commit
46ccfa1c9e
|
@ -241,11 +241,6 @@ public interface ResourceFactory
|
|||
ResourceFactoryInternals.RESOURCE_FACTORIES.put(scheme, resource);
|
||||
}
|
||||
|
||||
static void registerUrlResourceFactory(String scheme)
|
||||
{
|
||||
ResourceFactoryInternals.RESOURCE_FACTORIES.put(scheme, new UrlResourceFactory(scheme));
|
||||
}
|
||||
|
||||
static ResourceFactory unregisterResourceFactory(String scheme)
|
||||
{
|
||||
return ResourceFactoryInternals.RESOURCE_FACTORIES.remove(scheme);
|
||||
|
|
|
@ -28,17 +28,13 @@ import org.eclipse.jetty.util.FileID;
|
|||
/**
|
||||
* {@link ResourceFactory} for {@link java.net.URL} based resources.
|
||||
*/
|
||||
class UrlResourceFactory implements ResourceFactory
|
||||
public class URLResourceFactory implements ResourceFactory
|
||||
{
|
||||
private final String supportedProtocol;
|
||||
private int connectTimeout;
|
||||
private boolean useCaches;
|
||||
private int connectTimeout = 1000;
|
||||
private boolean useCaches = true;
|
||||
|
||||
protected UrlResourceFactory(String protocol)
|
||||
public URLResourceFactory()
|
||||
{
|
||||
this.supportedProtocol = protocol;
|
||||
this.connectTimeout = Integer.parseInt(System.getProperty(this.getClass().getName() + ".connectTimeout", "1000"));
|
||||
this.useCaches = Boolean.parseBoolean(System.getProperty(this.getClass().getName() + ".useCaches", "true"));
|
||||
}
|
||||
|
||||
public int getConnectTimeout()
|
||||
|
@ -64,9 +60,6 @@ class UrlResourceFactory implements ResourceFactory
|
|||
@Override
|
||||
public Resource newResource(final URI uri)
|
||||
{
|
||||
if (!uri.getScheme().equalsIgnoreCase(supportedProtocol))
|
||||
throw new IllegalArgumentException("Scheme not support: " + uri.getScheme());
|
||||
|
||||
try
|
||||
{
|
||||
return new URLResource(uri, this.connectTimeout, this.useCaches);
|
||||
|
@ -77,12 +70,6 @@ class UrlResourceFactory implements ResourceFactory
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return String.format("%s@%x[%s]", this.getClass().getName(), this.hashCode(), this.supportedProtocol);
|
||||
}
|
||||
|
||||
private static class URLResource extends Resource
|
||||
{
|
||||
private final URI uri;
|
|
@ -64,7 +64,7 @@ public class ResourceFactoryTest
|
|||
@Test
|
||||
public void testRegisterHttpsUrlFactory()
|
||||
{
|
||||
ResourceFactory.registerUrlResourceFactory("https");
|
||||
ResourceFactory.registerResourceFactory("https", new URLResourceFactory());
|
||||
// Try as a normal String input
|
||||
Resource resource = ResourceFactory.root().newResource("https://webtide.com/");
|
||||
assertThat(resource.getURI(), is(URI.create("https://webtide.com/")));
|
||||
|
|
|
@ -37,7 +37,7 @@ public class UrlResourceFactoryTest
|
|||
@Tag("external")
|
||||
public void testHttps() throws IOException
|
||||
{
|
||||
ResourceFactory.registerResourceFactory("https", new HttpsResourceFactory());
|
||||
ResourceFactory.registerResourceFactory("https", new URLResourceFactory());
|
||||
Resource resource = ResourceFactory.root().newResource(URI.create("https://webtide.com/"));
|
||||
assertThat(resource, notNullValue());
|
||||
assertTrue(resource.exists());
|
||||
|
@ -69,12 +69,4 @@ public class UrlResourceFactoryTest
|
|||
assertFalse(favicon.isDirectory());
|
||||
assertThat(favicon.getFileName(), is("favicon.ico"));
|
||||
}
|
||||
|
||||
public static class HttpsResourceFactory extends UrlResourceFactory
|
||||
{
|
||||
public HttpsResourceFactory()
|
||||
{
|
||||
super("https");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue