Skip to content

Commit

Permalink
Merge pull request #943 from AdoptOpenJDK/http_connection_interval
Browse files Browse the repository at this point in the history
OWS-627: fix SSLHandshake in some cases
  • Loading branch information
sclassen authored May 24, 2024
2 parents 5d4a707 + b57b044 commit d833d1d
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ private CompletableFuture<Resource> 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);
Expand All @@ -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<String, String> 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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
16 changes: 16 additions & 0 deletions core/src/main/java/net/sourceforge/jnlp/runtime/JNLPRuntime.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down

0 comments on commit d833d1d

Please sign in to comment.