diff --git a/platform/statistics/uploader/src/com/intellij/internal/statistic/StatisticsEventLogUtil.java b/platform/statistics/uploader/src/com/intellij/internal/statistic/StatisticsEventLogUtil.java index 2245c852b7fd..98f88b40cd92 100644 --- a/platform/statistics/uploader/src/com/intellij/internal/statistic/StatisticsEventLogUtil.java +++ b/platform/statistics/uploader/src/com/intellij/internal/statistic/StatisticsEventLogUtil.java @@ -1,7 +1,7 @@ // Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.internal.statistic; -import org.apache.http.client.HttpClient; +import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClientBuilder; import org.jdom.Element; import org.jdom.JDOMException; @@ -19,7 +19,7 @@ public class StatisticsEventLogUtil { @NonNls public static final String UTF8 = "UTF-8"; @NotNull - public static HttpClient create(@NotNull String userAgent) { + public static CloseableHttpClient create(@NotNull String userAgent) { return HttpClientBuilder.create().setUserAgent(userAgent).build(); } diff --git a/platform/statistics/uploader/src/com/intellij/internal/statistic/service/fus/FUStatisticsWhiteListGroupsService.java b/platform/statistics/uploader/src/com/intellij/internal/statistic/service/fus/FUStatisticsWhiteListGroupsService.java index bae525042a07..4a4299f4c08a 100644 --- a/platform/statistics/uploader/src/com/intellij/internal/statistic/service/fus/FUStatisticsWhiteListGroupsService.java +++ b/platform/statistics/uploader/src/com/intellij/internal/statistic/service/fus/FUStatisticsWhiteListGroupsService.java @@ -9,9 +9,11 @@ import com.intellij.internal.statistic.service.fus.FUSWhitelist.BuildRange; import com.intellij.internal.statistic.service.fus.FUSWhitelist.GroupFilterCondition; import com.intellij.internal.statistic.service.fus.FUSWhitelist.VersionRange; import org.apache.http.*; +import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpHead; import org.apache.http.client.utils.DateUtils; +import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.util.EntityUtils; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -71,8 +73,8 @@ public class FUStatisticsWhiteListGroupsService { if (StatisticsEventLogUtil.isEmptyOrSpaces(serviceUrl)) return null; String content = null; - try { - HttpResponse response = StatisticsEventLogUtil.create(userAgent).execute(new HttpGet(serviceUrl)); + try (CloseableHttpClient client = StatisticsEventLogUtil.create(userAgent); + CloseableHttpResponse response = client.execute(new HttpGet(serviceUrl))) { HttpEntity entity = response.getEntity(); if (entity != null) { content = EntityUtils.toString(entity, StatisticsEventLogUtil.UTF8); @@ -85,18 +87,19 @@ public class FUStatisticsWhiteListGroupsService { } private static long lastModifiedWhitelist(@NotNull String userAgent, @Nullable String serviceUrl) { - try { - if (!StatisticsEventLogUtil.isEmptyOrSpaces(serviceUrl)) { - final HttpResponse response = StatisticsEventLogUtil.create(userAgent).execute(new HttpHead(serviceUrl)); - return Stream.of(response.getHeaders(HttpHeaders.LAST_MODIFIED)). + if (!StatisticsEventLogUtil.isEmptyOrSpaces(serviceUrl)) { + try (CloseableHttpClient client = StatisticsEventLogUtil.create(userAgent); + CloseableHttpResponse response = client.execute(new HttpHead(serviceUrl))) { + Header[] headers = response.getHeaders(HttpHeaders.LAST_MODIFIED); + return Stream.of(headers). map(header -> header.getValue()). filter(Objects::nonNull). map(value -> DateUtils.parseDate(value).getTime()). max(Long::compareTo).orElse(0L); } - } - catch (IOException e) { - //LOG.info(e); + catch (IOException e) { + //LOG.info(e); + } } return 0; }