IVY-735 Don't force existing implementations of URLHandler to understand timeout constraints feature which was recently introduced

This commit is contained in:
Jaikiran Pai 2018-02-08 10:42:34 +05:30
parent 82ad5b0416
commit ae27582d1b
15 changed files with 216 additions and 146 deletions

View File

@ -57,6 +57,7 @@ import org.apache.ivy.util.cli.OptionBuilder;
import org.apache.ivy.util.cli.ParseException;
import org.apache.ivy.util.filter.FilterHelper;
import org.apache.ivy.util.url.CredentialsStore;
import org.apache.ivy.util.url.TimeoutConstrainedURLHandler;
import org.apache.ivy.util.url.URLHandler;
import org.apache.ivy.util.url.URLHandlerDispatcher;
import org.apache.ivy.util.url.URLHandlerRegistry;
@ -573,7 +574,7 @@ public final class Main {
CredentialsStore.INSTANCE.addCredentials(realm, host, username, passwd);
URLHandlerDispatcher dispatcher = new URLHandlerDispatcher();
URLHandler httpHandler = URLHandlerRegistry.getHttp();
TimeoutConstrainedURLHandler httpHandler = URLHandlerRegistry.getHttp();
dispatcher.setDownloader("http", httpHandler);
dispatcher.setDownloader("https", httpHandler);
URLHandlerRegistry.setDefault(dispatcher);

View File

@ -30,6 +30,7 @@ import org.apache.ivy.core.settings.IvySettings;
import org.apache.ivy.core.settings.IvyVariableContainer;
import org.apache.ivy.util.Message;
import org.apache.ivy.util.url.CredentialsStore;
import org.apache.ivy.util.url.TimeoutConstrainedURLHandler;
import org.apache.ivy.util.url.URLHandler;
import org.apache.ivy.util.url.URLHandlerDispatcher;
import org.apache.ivy.util.url.URLHandlerRegistry;
@ -387,7 +388,7 @@ public class IvyAntSettings extends DataType {
CredentialsStore.INSTANCE.addCredentials(getRealm(), getHost(), getUsername(), getPasswd());
URLHandlerDispatcher dispatcher = new URLHandlerDispatcher();
URLHandler httpHandler = URLHandlerRegistry.getHttp();
TimeoutConstrainedURLHandler httpHandler = URLHandlerRegistry.getHttp();
dispatcher.setDownloader("http", httpHandler);
dispatcher.setDownloader("https", httpHandler);
URLHandlerRegistry.setDefault(dispatcher);

View File

@ -324,7 +324,7 @@ public class IvySettings implements SortEngineSettings, PublishEngineSettings, P
try {
URL url = new URL("http://ant.apache.org/ivy/repository.properties");
Message.verbose("configuring repositories with " + url);
props.load(URLHandlerRegistry.getDefault().openStream(url, null));
props.load(URLHandlerRegistry.getDefault().openStream(url));
configured = true;
} catch (Exception ex) {
Message.verbose("unable to use remote repository configuration", ex);

View File

@ -152,7 +152,7 @@ public class XmlSettingsParser extends DefaultHandler {
this.settings = settingsUrl;
InputStream stream = null;
try {
stream = URLHandlerRegistry.getDefault().openStream(settingsUrl, null);
stream = URLHandlerRegistry.getDefault().openStream(settingsUrl);
InputSource inSrc = new InputSource(stream);
inSrc.setSystemId(settingsUrl.toExternalForm());
SAXParserFactory.newInstance().newSAXParser().parse(settingsUrl.toExternalForm(), this);

View File

@ -119,7 +119,7 @@ public class PomReader {
public PomReader(final URL descriptorURL, final Resource res) throws IOException, SAXException {
InputStream stream = new AddDTDFilterInputStream(
URLHandlerRegistry.getDefault().openStream(descriptorURL, null));
URLHandlerRegistry.getDefault().openStream(descriptorURL));
InputSource source = new InputSource(stream);
source.setSystemId(XMLHelper.toSystemId(descriptorURL));
try {

View File

@ -27,6 +27,8 @@ import java.net.URL;
import org.apache.ivy.core.settings.TimeoutConstraint;
import org.apache.ivy.plugins.repository.LocalizableResource;
import org.apache.ivy.plugins.repository.Resource;
import org.apache.ivy.util.url.TimeoutConstrainedURLHandler;
import org.apache.ivy.util.url.URLHandler;
import org.apache.ivy.util.url.URLHandler.URLInfo;
import org.apache.ivy.util.url.URLHandlerRegistry;
@ -73,7 +75,13 @@ public class URLResource implements LocalizableResource {
}
private void init() {
final URLInfo info = URLHandlerRegistry.getDefault().getURLInfo(url, this.timeoutConstraint);
final URLHandler handler = URLHandlerRegistry.getDefault();
final URLInfo info;
if (handler instanceof TimeoutConstrainedURLHandler) {
info = ((TimeoutConstrainedURLHandler) handler).getURLInfo(this.url, this.timeoutConstraint);
} else {
info = handler.getURLInfo(this.url);
}
contentLength = info.getContentLength();
lastModified = info.getLastModified();
exists = info.isReachable();
@ -107,7 +115,11 @@ public class URLResource implements LocalizableResource {
}
public InputStream openStream() throws IOException {
return URLHandlerRegistry.getDefault().openStream(url, null);
final URLHandler handler = URLHandlerRegistry.getDefault();
if (handler instanceof TimeoutConstrainedURLHandler) {
return ((TimeoutConstrainedURLHandler) handler).openStream(this.url, this.timeoutConstraint);
}
return handler.openStream(this.url);
}
public File getFile() {

View File

@ -18,6 +18,8 @@
package org.apache.ivy.util;
import org.apache.ivy.core.settings.TimeoutConstraint;
import org.apache.ivy.util.url.TimeoutConstrainedURLHandler;
import org.apache.ivy.util.url.URLHandler;
import org.apache.ivy.util.url.URLHandlerRegistry;
import java.io.BufferedInputStream;
@ -200,12 +202,22 @@ public final class FileUtil {
public static void copy(final URL src, final File dest, final CopyProgressListener listener,
final TimeoutConstraint timeoutConstraint) throws IOException {
URLHandlerRegistry.getDefault().download(src, dest, listener, timeoutConstraint);
final URLHandler handler = URLHandlerRegistry.getDefault();
if (handler instanceof TimeoutConstrainedURLHandler) {
((TimeoutConstrainedURLHandler) handler).download(src, dest, listener, timeoutConstraint);
return;
}
handler.download(src, dest, listener);
}
public static void copy(final File src, final URL dest, final CopyProgressListener listener,
final TimeoutConstraint timeoutConstraint) throws IOException {
URLHandlerRegistry.getDefault().upload(src, dest, listener, timeoutConstraint);
final URLHandler handler = URLHandlerRegistry.getDefault();
if (handler instanceof TimeoutConstrainedURLHandler) {
((TimeoutConstrainedURLHandler) handler).upload(src, dest, listener, timeoutConstraint);
return;
}
handler.upload(src, dest, listener);
}
public static void copy(InputStream src, File dest, CopyProgressListener l) throws IOException {

View File

@ -118,7 +118,7 @@ public abstract class XMLHelper {
public static void parse(URL xmlURL, URL schema, DefaultHandler handler, LexicalHandler lHandler)
throws SAXException, IOException, ParserConfigurationException {
InputStream xmlStream = URLHandlerRegistry.getDefault().openStream(xmlURL, null);
InputStream xmlStream = URLHandlerRegistry.getDefault().openStream(xmlURL);
try {
InputSource inSrc = new InputSource(xmlStream);
inSrc.setSystemId(toSystemId(xmlURL));
@ -148,7 +148,7 @@ public abstract class XMLHelper {
InputStream schemaStream = null;
try {
if (schema != null) {
schemaStream = URLHandlerRegistry.getDefault().openStream(schema, null);
schemaStream = URLHandlerRegistry.getDefault().openStream(schema);
}
SAXParser parser = XMLHelper.newSAXParser(schema, schemaStream, loadExternalDtds);

View File

@ -33,7 +33,7 @@ import java.util.zip.InflaterInputStream;
import org.apache.ivy.Ivy;
import org.apache.ivy.core.settings.TimeoutConstraint;
public abstract class AbstractURLHandler implements URLHandler {
public abstract class AbstractURLHandler implements TimeoutConstrainedURLHandler {
private static final Pattern ESCAPE_PATTERN = Pattern.compile("%25([0-9a-fA-F][0-9a-fA-F])");

View File

@ -111,14 +111,14 @@ public class ApacheURLLister {
}
URLHandler urlHandler = URLHandlerRegistry.getDefault();
URLInfo urlInfo = urlHandler.getURLInfo(url, null);
URLInfo urlInfo = urlHandler.getURLInfo(url);
if (urlInfo == URLHandler.UNAVAILABLE) {
return urlList; // not found => return empty list
}
// here, urlInfo is valid
String charset = urlInfo.getBodyCharset();
InputStream contentStream = urlHandler.openStream(url, null);
InputStream contentStream = urlHandler.openStream(url);
BufferedReader r = null;
if (charset == null) {
r = new BufferedReader(new InputStreamReader(contentStream));

View File

@ -0,0 +1,127 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.ivy.util.url;
import org.apache.ivy.core.settings.TimeoutConstraint;
import org.apache.ivy.util.CopyProgressListener;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
/**
* A enhanced version of {@link URLHandler} which respects {@link TimeoutConstraint}s on
* the operations dealing with download, upload, reachability checks etc...
*/
public interface TimeoutConstrainedURLHandler extends URLHandler {
/**
* Returns true if the passed <code>URL</code> is reachable. Else returns false. Uses the
* passed <code>timeoutConstraint</code> for determining the connectivity to the URL.
* <p>
* Please use {@link #getURLInfo(URL, TimeoutConstraint)} if more one information about the
* <code>url</code> is needed
* </p>
*
* @param url The URL to access
* @param timeoutConstraint The connectivity timeout constraints. Can be null, in which case
* the timeouts are implementation specific
* @return boolean
* @since 2.5
*/
boolean isReachable(URL url, TimeoutConstraint timeoutConstraint);
/**
* Returns the number of bytes of data that's available for the resource at the passed
* <code>url</code>. Returns 0 if the passed <code>url</code> isn't reachable
*
* @param url The URL to access
* @param timeoutConstraint The connectivity timeout constraints. Can be null, in which case
* the timeouts are implementation specific
* @return long
* @since 2.5
*/
long getContentLength(URL url, TimeoutConstraint timeoutConstraint);
/**
* Returns the last modified timestamp of the resource accessible at the passed
* <code>url</code>.
* <p>
* Please use {@link #getURLInfo(URL, TimeoutConstraint)} if more one information about the
* <code>url</code> is needed
* </p>
*
* @param url The URL to access
* @param timeoutConstraint The connectivity timeout constraints. Can be null, in which case
* the timeouts are implementation specific
* @return long
* @since 2.5
*/
long getLastModified(URL url, TimeoutConstraint timeoutConstraint);
/**
* Returns the {@link URLInfo} extracted from the given url, or {@link #UNAVAILABLE} when the
* url is not reachable. Never returns null.
*
* @param url The URL for which the information is to be retrieved
* @param timeoutConstraint The connectivity timeout constraints. Can be null, in which case
* the timeouts are implementation specific
* @return URLInfo
* @since 2.5
*/
URLInfo getURLInfo(URL url, TimeoutConstraint timeoutConstraint);
/**
* Opens and returns an {@link InputStream} to the passed <code>url</code>.
*
* @param url The URL to which an {@link InputStream} has to be opened
* @param timeoutConstraint The connectivity timeout constraints. Can be null, in which case
* the timeouts are implementation specific
* @return InputStream
* @throws IOException if something goes wrong
* @since 2.5
*/
InputStream openStream(URL url, TimeoutConstraint timeoutConstraint) throws IOException;
/**
* Downloads the resource available at <code>src</code> to the target <code>dest</code>
*
* @param src The source URL to download the resource from
* @param dest The destination {@link File} to download the resource to
* @param listener The listener that will be notified of the download progress
* @param timeoutConstraint The connectivity timeout constraints. Can be null, in which case
* the timeouts are implementation specific
* @throws IOException if something goes wrong
* @since 2.5
*/
void download(URL src, File dest, CopyProgressListener listener, TimeoutConstraint timeoutConstraint) throws IOException;
/**
* Uploads the <code>src</code> {@link File} to the target <code>dest</code> {@link URL}
*
* @param src The source {@link File} to upload
* @param dest The target URL where the {@link File} has to be uploaded
* @param listener The listener that will be notified of the upload progress
* @param timeoutConstraint The connectivity timeout constraints. Can be null, in which case
* the timeouts are implementation specific
* @throws IOException if something goes wrong
* @since 2.5
*/
void upload(File src, URL dest, CopyProgressListener listener, TimeoutConstraint timeoutConstraint) throws IOException;
}

View File

@ -17,7 +17,6 @@
*/
package org.apache.ivy.util.url;
import org.apache.ivy.core.settings.TimeoutConstraint;
import org.apache.ivy.util.CopyProgressListener;
import java.io.File;
@ -28,7 +27,11 @@ import java.net.URL;
/**
* This interface is responsible for handling some URL manipulation (stream opening, downloading,
* check reachability, ...).
* <p>
*
* @deprecated Starting 2.5.0, the {@link TimeoutConstrainedURLHandler} is preferred in favour of this interface
*/
@Deprecated
public interface URLHandler {
/**
@ -88,9 +91,7 @@ public interface URLHandler {
*
* @param url the url to check
* @return true if the target is reachable
* @deprecated Use {@link #isReachable(URL, TimeoutConstraint)} instead
*/
@Deprecated
boolean isReachable(URL url);
/**
@ -99,36 +100,16 @@ public interface URLHandler {
* @param url the url to check
* @param timeout the timeout in milliseconds
* @return true if the target is reachable
* @deprecated Use {@link #isReachable(URL, TimeoutConstraint)} instead
*/
@Deprecated
boolean isReachable(URL url, int timeout);
/**
* Returns true if the passed <code>URL</code> is reachable. Else returns false. Uses the
* passed <code>timeoutConstraint</code> for determining the connectivity to the URL.
* <p>
* Please use {@link #getURLInfo(URL, TimeoutConstraint)} if more one information about the
* <code>url</code> is needed
* </p>
*
* @param url The URL to access
* @param timeoutConstraint The connectivity timeout constraints. Can be null, in which case
* the timeouts are implementation specific
* @return boolean
* @since 2.5
*/
boolean isReachable(URL url, TimeoutConstraint timeoutConstraint);
/**
* Please prefer getURLInfo when several infos are needed.
*
* @param url the url to check
* @return the length of the target if the given url is reachable, 0 otherwise. No error code
* in case of http urls.
* @deprecated Use {@link #getContentLength(URL, TimeoutConstraint)} instead
*/
@Deprecated
long getContentLength(URL url);
/**
@ -137,31 +118,15 @@ public interface URLHandler {
* timeout of zero indicates no timeout
* @return the length of the target if the given url is reachable, 0 otherwise. No error code
* in case of http urls.
* @deprecated Use {@link #getContentLength(URL, TimeoutConstraint)} instead
*/
@Deprecated
long getContentLength(URL url, int timeout);
/**
* Returns the number of bytes of data that's available for the resource at the passed
* <code>url</code>. Returns 0 if the passed <code>url</code> isn't reachable
*
* @param url The URL to access
* @param timeoutConstraint The connectivity timeout constraints. Can be null, in which case
* the timeouts are implementation specific
* @return long
* @since 2.5
*/
long getContentLength(URL url, TimeoutConstraint timeoutConstraint);
/**
* Please prefer getURLInfo when several infos are needed.
*
* @param url the url to check
* @return last modified timestamp of the given url
* @deprecated Use {@link #getLastModified(URL, TimeoutConstraint)} instead
*/
@Deprecated
long getLastModified(URL url);
/**
@ -170,34 +135,14 @@ public interface URLHandler {
* @param url the url to check
* @param timeout the timeout in milliseconds
* @return last modified timestamp of the given url
* @deprecated Use {@link #getLastModified(URL, TimeoutConstraint)} instead
*/
@Deprecated
long getLastModified(URL url, int timeout);
/**
* Returns the last modified timestamp of the resource accessible at the passed
* <code>url</code>.
* <p>
* Please use {@link #getURLInfo(URL, TimeoutConstraint)} if more one information about the
* <code>url</code> is needed
* </p>
*
* @param url The URL to access
* @param timeoutConstraint The connectivity timeout constraints. Can be null, in which case
* the timeouts are implementation specific
* @return long
* @since 2.5
*/
long getLastModified(URL url, TimeoutConstraint timeoutConstraint);
/**
* @param url The url from which information is retrieved.
* @return The URLInfo extracted from the given url, or {@link #UNAVAILABLE} instance when the
* url is not reachable.
* @deprecated Use {@link #getURLInfo(URL, TimeoutConstraint)} instead
*/
@Deprecated
URLInfo getURLInfo(URL url);
/**
@ -205,89 +150,31 @@ public interface URLHandler {
* @param timeout The timeout in milliseconds.
* @return The URLInfo extracted from the given url, or {@link #UNAVAILABLE} when the url is
* not reachable, never null.
* @deprecated Use {@link #getURLInfo(URL, TimeoutConstraint)} instead
*/
@Deprecated
URLInfo getURLInfo(URL url, int timeout);
/**
* Returns the {@link URLInfo} extracted from the given url, or {@link #UNAVAILABLE} when the
* url is not reachable. Never returns null.
*
* @param url The URL for which the information is to be retrieved
* @param timeoutConstraint The connectivity timeout constraints. Can be null, in which case
* the timeouts are implementation specific
* @return URLInfo
* @since 2.5
*/
URLInfo getURLInfo(URL url, TimeoutConstraint timeoutConstraint);
/**
* @param url ditto
* @return InputStream
* @throws IOException if something goes wrong
* @deprecated Use {@link #openStream(URL, TimeoutConstraint)} instead
*/
@Deprecated
InputStream openStream(URL url) throws IOException;
/**
* Opens and returns an {@link InputStream} to the passed <code>url</code>.
*
* @param url The URL to which an {@link InputStream} has to be opened
* @param timeoutConstraint The connectivity timeout constraints. Can be null, in which case
* the timeouts are implementation specific
* @return InputStream
* @throws IOException if something goes wrong
* @since 2.5
*/
InputStream openStream(URL url, TimeoutConstraint timeoutConstraint) throws IOException;
/**
* @param src URL
* @param src URL
* @param dest File
* @param l CopyProgressListener
* @param l CopyProgressListener
* @throws IOException if something goes wrong
* @deprecated Use {@link #download(URL, File, CopyProgressListener, TimeoutConstraint)} instead
*/
@Deprecated
void download(URL src, File dest, CopyProgressListener l) throws IOException;
/**
* Downloads the resource available at <code>src</code> to the target <code>dest</code>
*
* @param src The source URL to download the resource from
* @param dest The destination {@link File} to download the resource to
* @param listener The listener that will be notified of the download progress
* @param timeoutConstraint The connectivity timeout constraints. Can be null, in which case
* the timeouts are implementation specific
* @throws IOException if something goes wrong
* @since 2.5
*/
void download(URL src, File dest, CopyProgressListener listener, TimeoutConstraint timeoutConstraint) throws IOException;
/**
* @param src File
* @param src File
* @param dest URL
* @param l CopyProgressListener
* @param l CopyProgressListener
* @throws IOException if something goes wrong
* @deprecated Use {@link #upload(File, URL, CopyProgressListener, TimeoutConstraint)} instead
*/
@Deprecated
void upload(File src, URL dest, CopyProgressListener l) throws IOException;
/**
* Uploads the <code>src</code> {@link File} to the target <code>dest</code> {@link URL}
*
* @param src The source {@link File} to upload
* @param dest The target URL where the {@link File} has to be uploaded
* @param listener The listener that will be notified of the upload progress
* @param timeoutConstraint The connectivity timeout constraints. Can be null, in which case
* the timeouts are implementation specific
* @throws IOException if something goes wrong
* @since 2.5
*/
void upload(File src, URL dest, CopyProgressListener listener, TimeoutConstraint timeoutConstraint) throws IOException;
void setRequestMethod(int requestMethod);
}

View File

@ -32,7 +32,7 @@ import java.util.Map;
* and a fallback default {@link URLHandler} for dealing with downloads, uploads and
* general reachability checks
*/
public class URLHandlerDispatcher implements URLHandler {
public class URLHandlerDispatcher implements TimeoutConstrainedURLHandler {
private final Map<String, URLHandler> handlers = new HashMap<>();
private URLHandler defaultHandler = new BasicURLHandler();
@ -52,7 +52,11 @@ public class URLHandlerDispatcher implements URLHandler {
@Override
public boolean isReachable(final URL url, final TimeoutConstraint timeoutConstraint) {
return this.getHandler(url.getProtocol()).isReachable(url, timeoutConstraint);
final URLHandler handler = this.getHandler(url.getProtocol());
if (handler instanceof TimeoutConstrainedURLHandler) {
return ((TimeoutConstrainedURLHandler) handler).isReachable(url, timeoutConstraint);
}
return handler.isReachable(url, timeoutConstraint != null ? timeoutConstraint.getConnectionTimeout() : 0);
}
@Override
@ -67,7 +71,11 @@ public class URLHandlerDispatcher implements URLHandler {
@Override
public long getContentLength(final URL url, final TimeoutConstraint timeoutConstraint) {
return this.getHandler(url.getProtocol()).getContentLength(url, timeoutConstraint);
final URLHandler handler = this.getHandler(url.getProtocol());
if (handler instanceof TimeoutConstrainedURLHandler) {
return ((TimeoutConstrainedURLHandler) handler).getContentLength(url, timeoutConstraint);
}
return handler.getContentLength(url, timeoutConstraint != null ? timeoutConstraint.getConnectionTimeout() : 0);
}
@Override
@ -82,7 +90,11 @@ public class URLHandlerDispatcher implements URLHandler {
@Override
public long getLastModified(final URL url, final TimeoutConstraint timeoutConstraint) {
return this.getHandler(url.getProtocol()).getLastModified(url, timeoutConstraint);
final URLHandler handler = this.getHandler(url.getProtocol());
if (handler instanceof TimeoutConstrainedURLHandler) {
return ((TimeoutConstrainedURLHandler) handler).getLastModified(url, timeoutConstraint);
}
return handler.getLastModified(url, timeoutConstraint != null ? timeoutConstraint.getConnectionTimeout() : 0);
}
@Override
@ -97,7 +109,11 @@ public class URLHandlerDispatcher implements URLHandler {
@Override
public URLInfo getURLInfo(final URL url, final TimeoutConstraint timeoutConstraint) {
return this.getHandler(url.getProtocol()).getURLInfo(url, timeoutConstraint);
final URLHandler handler = this.getHandler(url.getProtocol());
if (handler instanceof TimeoutConstrainedURLHandler) {
return ((TimeoutConstrainedURLHandler) handler).getURLInfo(url, timeoutConstraint);
}
return handler.getURLInfo(url, timeoutConstraint != null ? timeoutConstraint.getConnectionTimeout() : 0);
}
@Override
@ -107,7 +123,11 @@ public class URLHandlerDispatcher implements URLHandler {
@Override
public InputStream openStream(final URL url, final TimeoutConstraint timeoutConstraint) throws IOException {
return this.getHandler(url.getProtocol()).openStream(url, timeoutConstraint);
final URLHandler handler = this.getHandler(url.getProtocol());
if (handler instanceof TimeoutConstrainedURLHandler) {
return ((TimeoutConstrainedURLHandler) handler).openStream(url, timeoutConstraint);
}
return handler.openStream(url);
}
@Override
@ -117,7 +137,12 @@ public class URLHandlerDispatcher implements URLHandler {
@Override
public void download(final URL src, final File dest, final CopyProgressListener listener, final TimeoutConstraint timeoutConstraint) throws IOException {
this.getHandler(src.getProtocol()).download(src, dest, listener, timeoutConstraint);
final URLHandler handler = this.getHandler(src.getProtocol());
if (handler instanceof TimeoutConstrainedURLHandler) {
((TimeoutConstrainedURLHandler) handler).download(src, dest, listener, timeoutConstraint);
return;
}
handler.download(src, dest, listener);
}
@Override
@ -127,7 +152,12 @@ public class URLHandlerDispatcher implements URLHandler {
@Override
public void upload(final File src, final URL dest, final CopyProgressListener listener, final TimeoutConstraint timeoutConstraint) throws IOException {
this.getHandler(dest.getProtocol()).upload(src, dest, listener, timeoutConstraint);
final URLHandler handler = this.getHandler(dest.getProtocol());
if (handler instanceof TimeoutConstrainedURLHandler) {
((TimeoutConstrainedURLHandler) handler).upload(src, dest, listener, timeoutConstraint);
return;
}
handler.upload(src, dest, listener);
}
public void setRequestMethod(int requestMethod) {

View File

@ -44,7 +44,7 @@ public final class URLHandlerRegistry {
*
* @return most accurate http downloader
*/
public static URLHandler getHttp() {
public static TimeoutConstrainedURLHandler getHttp() {
try {
// check for the presence of HttpComponents HttpClient
Class.forName("org.apache.http.client.HttpClient");
@ -53,7 +53,7 @@ public final class URLHandlerRegistry {
// we always use just one instance which is internally registered to be closed
// when the JVM exits
final Field instance = handler.getDeclaredField("DELETE_ON_EXIT_INSTANCE");
return (URLHandler) instance.get(null);
return (TimeoutConstrainedURLHandler) instance.get(null);
} catch (ClassNotFoundException | NoSuchFieldException | IllegalAccessException e) {
Message.verbose("Using JDK backed URL handler for HTTP interaction since the "
+ "Apache HttpComponents HttpClient backed handler couldn't be created due to: "

View File

@ -97,7 +97,7 @@ public class HttpclientURLHandlerTest {
@SuppressWarnings("resource")
@Test
public void testGetURLInfo() throws Exception {
URLHandler handler = new HttpClientHandler();
final TimeoutConstrainedURLHandler handler = new HttpClientHandler();
assertTrue("Default Maven URL must end with '/'", DEFAULT_M2_ROOT.endsWith("/"));
URLInfo info = handler.getURLInfo(new URL(DEFAULT_M2_ROOT
+ "commons-lang/commons-lang/[1.0,3.0[/commons-lang-[1.0,3.0[.pom"), defaultTimeoutConstraint);