From 83638c44759d8d8dcbc3d6b14a6c63edec6e6f82 Mon Sep 17 00:00:00 2001 From: janakmulani Date: Fri, 24 May 2024 12:26:47 +0530 Subject: [PATCH 1/2] OWS-627: fix SSLHandshake in some cases --- .../downloader/BaseResourceDownloader.java | 15 ++++++++++----- .../jnlp/config/ConfigurationConstants.java | 1 + .../sourceforge/jnlp/runtime/JNLPRuntime.java | 16 ++++++++++++++++ 3 files changed, 27 insertions(+), 5 deletions(-) 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..ab0af94df 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,11 @@ private CompletableFuture downloadFrom(final URL url) { } private Resource tryDownloading(final URL downloadFrom) throws IOException { + try { + final int httpsRequestInterval = getTimeValue(ConfigurationConstants.KEY_HTTPCONNECTION_REQUEST_INTERVAL); + Thread.sleep(httpsRequestInterval); + } catch (InterruptedException ie) { + } DownloadDetails downloadDetails = null; try (final CloseableConnection connection = getDownloadConnection(downloadFrom)) { downloadDetails = getDownloadDetails(connection); @@ -161,20 +166,20 @@ private Resource tryDownloading(final URL downloadFrom) throws IOException { 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. * From b57b044cc6ff004d9aff847fc4ba5439d5cc3603 Mon Sep 17 00:00:00 2001 From: Stephan Classen Date: Fri, 24 May 2024 09:29:04 +0200 Subject: [PATCH 2/2] extract method --- .../downloader/BaseResourceDownloader.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) 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 ab0af94df..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,11 +132,7 @@ private CompletableFuture downloadFrom(final URL url) { } private Resource tryDownloading(final URL downloadFrom) throws IOException { - try { - final int httpsRequestInterval = getTimeValue(ConfigurationConstants.KEY_HTTPCONNECTION_REQUEST_INTERVAL); - Thread.sleep(httpsRequestInterval); - } catch (InterruptedException ie) { - } + ensureRequestInterval(); DownloadDetails downloadDetails = null; try (final CloseableConnection connection = getDownloadConnection(downloadFrom)) { downloadDetails = getDownloadDetails(connection); @@ -163,6 +159,16 @@ 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);