From 556ff39bcfadb49124eb9f68e4326c40ef590f70 Mon Sep 17 00:00:00 2001 From: Purva Vyas Date: Tue, 24 May 2022 09:27:33 +0200 Subject: [PATCH] httpClient created as instance variable --- .../contexthandling/services/GitlabApiClient.java | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/smartclide-monitoring/src/main/java/eu/smartclide/contexthandling/services/GitlabApiClient.java b/smartclide-monitoring/src/main/java/eu/smartclide/contexthandling/services/GitlabApiClient.java index b308d81f..b94f9f4a 100644 --- a/smartclide-monitoring/src/main/java/eu/smartclide/contexthandling/services/GitlabApiClient.java +++ b/smartclide-monitoring/src/main/java/eu/smartclide/contexthandling/services/GitlabApiClient.java @@ -40,16 +40,19 @@ public class GitlabApiClient { private static final Logger logger = LoggerFactory.getLogger(GitlabApiClient.class); private static final DateTimeFormatter formatter = DateTimeFormatter.ISO_DATE_TIME; + private static final ZonedDateTime initialSinceDate = ZonedDateTime.of( + 2022, 1, 1, 0, 0, 0, 0, ZoneOffset.UTC); private static final String membershipParam = "&membership=true"; private static final String paginationParam = "&per_page=100"; private static final String refNameParam = "&ref_name="; private static final String sinceParam = "&since="; - private static final ZonedDateTime initialSinceDate = ZonedDateTime.of(2022, 1, 1, 0, 0, 0, 0, ZoneOffset.UTC); private static final String uriPartForBranches = "/repository/branches/"; private static final String uriPartForCommits = "/repository/commits/"; private static final String uriPartForDiff = "/diff/"; private static final String uriPartForProjects = "/api/v4/projects/"; private final String baseUri; + private final HttpClient httpClient = HttpClient.newBuilder().version(HttpClient.Version.HTTP_2) + .connectTimeout(Duration.ofMinutes(5)).build(); private final String uriParams; private ZonedDateTime lastRun = null; @@ -178,11 +181,6 @@ private HttpResponse makeGetCallToGitlab(String uri) { HttpResponse response = null; try { - final HttpClient httpClient = HttpClient.newBuilder() - .version(HttpClient.Version.HTTP_2) - .connectTimeout(Duration.ofMinutes(5)) - .build(); - HttpRequest request = HttpRequest.newBuilder().GET().uri(URI.create(uri)).build(); // receive response from Gitlab