From 39893162696129c052489ae86983d92a29924939 Mon Sep 17 00:00:00 2001 From: Sebastian Stenzel Date: Fri, 23 Feb 2018 18:21:38 +0100 Subject: [PATCH] replaced org.apache.httpcomponents:httpclient by jdk.incubator.httpclient (will become official standard in jdk10) --- main/pom.xml | 12 ++-- main/ui/pom.xml | 4 -- .../ui/controllers/WelcomeController.java | 66 +++++++------------ 3 files changed, 30 insertions(+), 52 deletions(-) diff --git a/main/pom.xml b/main/pom.xml index 41b13bbf7..082497d00 100644 --- a/main/pom.xml +++ b/main/pom.xml @@ -31,8 +31,7 @@ 2.5 3.6 - 4.5.4 - + 1.0.3 23.6-jre @@ -140,11 +139,6 @@ commons-lang3 ${commons-lang3.version} - - org.apache.httpcomponents - httpclient - ${httpclient.version} - @@ -313,6 +307,10 @@ 9 9 9 + + --add-modules + jdk.incubator.httpclient + diff --git a/main/ui/pom.xml b/main/ui/pom.xml index c5a0980c9..02a9f37c1 100644 --- a/main/ui/pom.xml +++ b/main/ui/pom.xml @@ -62,10 +62,6 @@ org.apache.commons commons-lang3 - - org.apache.httpcomponents - httpclient - diff --git a/main/ui/src/main/java/org/cryptomator/ui/controllers/WelcomeController.java b/main/ui/src/main/java/org/cryptomator/ui/controllers/WelcomeController.java index c2507a6bc..aed401acc 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/controllers/WelcomeController.java +++ b/main/ui/src/main/java/org/cryptomator/ui/controllers/WelcomeController.java @@ -8,11 +8,10 @@ ******************************************************************************/ package org.cryptomator.ui.controllers; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.Reader; +import java.net.URI; import java.net.URL; import java.nio.charset.StandardCharsets; +import java.time.Duration; import java.util.Comparator; import java.util.Map; import java.util.Optional; @@ -22,23 +21,9 @@ import javax.inject.Inject; import javax.inject.Named; import javax.inject.Singleton; -import org.apache.commons.lang3.SystemUtils; -import org.apache.http.client.config.RequestConfig; -import org.apache.http.client.methods.CloseableHttpResponse; -import org.apache.http.client.methods.HttpGet; -import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.impl.client.HttpClientBuilder; -import org.apache.http.impl.client.HttpClients; -import org.cryptomator.common.settings.Settings; -import org.cryptomator.ui.l10n.Localization; -import org.cryptomator.ui.util.AsyncTaskService; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.reflect.TypeToken; - import javafx.application.Application; import javafx.application.Platform; import javafx.event.ActionEvent; @@ -49,6 +34,15 @@ import javafx.scene.control.Hyperlink; import javafx.scene.control.Label; import javafx.scene.control.ProgressIndicator; import javafx.scene.layout.VBox; +import jdk.incubator.http.HttpClient; +import jdk.incubator.http.HttpRequest; +import jdk.incubator.http.HttpResponse; +import org.apache.commons.lang3.SystemUtils; +import org.cryptomator.common.settings.Settings; +import org.cryptomator.ui.l10n.Localization; +import org.cryptomator.ui.util.AsyncTaskService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; @Singleton public class WelcomeController implements ViewController { @@ -114,31 +108,21 @@ public class WelcomeController implements ViewController { checkForUpdatesStatus.setText(localization.getString("welcome.checkForUpdates.label.currentlyChecking")); checkForUpdatesIndicator.setVisible(true); asyncTaskService.asyncTaskOf(() -> { - RequestConfig requestConfig = RequestConfig.custom() // - .setConnectTimeout(5000) // - .setConnectionRequestTimeout(5000) // - .setSocketTimeout(5000) // - .build(); String userAgent = String.format("Cryptomator VersionChecker/%s %s %s (%s)", applicationVersion.orElse("SNAPSHOT"), SystemUtils.OS_NAME, SystemUtils.OS_VERSION, SystemUtils.OS_ARCH); - HttpClientBuilder httpClientBuilder = HttpClients.custom() // - .disableCookieManagement() // - .setDefaultRequestConfig(requestConfig) // - .setUserAgent(userAgent); - LOG.debug("Checking for updates..."); - try (CloseableHttpClient client = httpClientBuilder.build()) { - HttpGet request = new HttpGet("https://api.cryptomator.org/updates/latestVersion.json"); - try (CloseableHttpResponse response = client.execute(request)) { - if (response.getStatusLine().getStatusCode() == 200 && response.getEntity() != null) { - try (InputStream in = response.getEntity().getContent()) { - Gson gson = new GsonBuilder().setLenient().create(); - Reader utf8Reader = new InputStreamReader(in, StandardCharsets.UTF_8); - Map map = gson.fromJson(utf8Reader, new TypeToken>() { - }.getType()); - if (map != null) { - this.compareVersions(map); - } - } - } + HttpClient client = HttpClient.newHttpClient(); + HttpRequest request = HttpRequest.newBuilder() + .GET() + .uri(new URI("https://api.cryptomator.org/updates/latestVersion.json")) + .header("User-Agent", userAgent) + .timeout(Duration.ofSeconds(5)) + .build(); + HttpResponse response = client.send(request, HttpResponse.BodyHandler.asString(StandardCharsets.UTF_8)); + if (response.statusCode() == 200) { + Gson gson = new GsonBuilder().setLenient().create(); + Map map = gson.fromJson(response.body(), new TypeToken>() { + }.getType()); + if (map != null) { + this.compareVersions(map); } } }).andFinally(() -> {