diff --git a/core/src/main/java/net/adoptopenjdk/icedteaweb/resources/downloader/BaseResourceDownloader.java b/core/src/main/java/net/adoptopenjdk/icedteaweb/resources/downloader/BaseResourceDownloader.java index 36145a1d7..f21a6fa98 100644 --- a/core/src/main/java/net/adoptopenjdk/icedteaweb/resources/downloader/BaseResourceDownloader.java +++ b/core/src/main/java/net/adoptopenjdk/icedteaweb/resources/downloader/BaseResourceDownloader.java @@ -132,6 +132,7 @@ private CompletableFuture downloadFrom(final URL url) { } private Resource tryDownloading(final URL downloadFrom) throws IOException { + ensureRequestInterval(); DownloadDetails downloadDetails = null; try (final CloseableConnection connection = getDownloadConnection(downloadFrom)) { downloadDetails = getDownloadDetails(connection); @@ -158,23 +159,33 @@ private Resource tryDownloading(final URL downloadFrom) throws IOException { } } + private void ensureRequestInterval() { + final int httpsRequestInterval = getTimeValue(ConfigurationConstants.KEY_HTTPCONNECTION_REQUEST_INTERVAL); + if (httpsRequestInterval > 0) { + try { + Thread.sleep(httpsRequestInterval); + } catch (InterruptedException ignored) { + } + } + } + private CloseableConnection getDownloadConnection(final URL location) throws IOException { final Map requestProperties = new HashMap<>(); requestProperties.put(ACCEPT_ENCODING_HEADER, PACK_200_OR_GZIP); - return ConnectionFactory.openConnection(location, HttpMethod.GET, requestProperties, getTimeoutValue(ConfigurationConstants.KEY_HTTPCONNECTION_CONNECT_TIMEOUT), getTimeoutValue(ConfigurationConstants.KEY_HTTPCONNECTION_READ_TIMEOUT)); + return ConnectionFactory.openConnection(location, HttpMethod.GET, requestProperties, getTimeValue(ConfigurationConstants.KEY_HTTPCONNECTION_CONNECT_TIMEOUT), getTimeValue(ConfigurationConstants.KEY_HTTPCONNECTION_READ_TIMEOUT)); } - private int getTimeoutValue(final String key) { - int timeout = 0; + private int getTimeValue(final String key) { + int timeValue = 0; final String value = JNLPRuntime.getConfiguration().getProperty(key); if (value != null && value.trim().length() != 0) { try { - timeout = Integer.valueOf(value); + timeValue = Integer.valueOf(value); } catch (NumberFormatException e) { LOG.error("Could not parse {} with value '{}' - reason {}", key, value, e.getMessage()); } } - return timeout; + return timeValue; } private long tryDownloading(final DownloadDetails downloadDetails) throws IOException { diff --git a/core/src/main/java/net/sourceforge/jnlp/config/ConfigurationConstants.java b/core/src/main/java/net/sourceforge/jnlp/config/ConfigurationConstants.java index 9cabc8082..8d106d25c 100644 --- a/core/src/main/java/net/sourceforge/jnlp/config/ConfigurationConstants.java +++ b/core/src/main/java/net/sourceforge/jnlp/config/ConfigurationConstants.java @@ -305,4 +305,5 @@ public interface ConfigurationConstants { */ String KEY_HTTPCONNECTION_CONNECT_TIMEOUT = "deployment.connection.connectTimeout"; String KEY_HTTPCONNECTION_READ_TIMEOUT = "deployment.connection.readTimeout"; + String KEY_HTTPCONNECTION_REQUEST_INTERVAL = "deployment.connection.request.interval"; } diff --git a/core/src/main/java/net/sourceforge/jnlp/runtime/JNLPRuntime.java b/core/src/main/java/net/sourceforge/jnlp/runtime/JNLPRuntime.java index e6baa022e..375f4db03 100644 --- a/core/src/main/java/net/sourceforge/jnlp/runtime/JNLPRuntime.java +++ b/core/src/main/java/net/sourceforge/jnlp/runtime/JNLPRuntime.java @@ -673,6 +673,22 @@ public static LaunchHandler getDefaultLaunchHandler() { return handler; } + /** + * Returns the Security Dialog Message Handler. + * @return SecurityDialogMessageHandler + */ + public static SecurityDialogMessageHandler getSecurityDialogMessageHandler() { + return securityDialogMessageHandler; + } + + /** + * Sets the Security Dialog Message Handler. + * @param securityDialogMessageHandler handler for Security Dialog messages + */ + public static void setSecurityDialogMessageHandler(final SecurityDialogMessageHandler securityDialogMessageHandler) { + JNLPRuntime.securityDialogMessageHandler = securityDialogMessageHandler; + } + /** * Sets the default download indicator. *