diff --git a/build.gradle b/build.gradle index 58897a5..41b8f3a 100644 --- a/build.gradle +++ b/build.gradle @@ -29,7 +29,7 @@ repositories { } dependencies { implementation( - [group: 'org.apache.httpcomponents', name: 'httpclient', version: "4.5.14"], + [group: 'org.apache.httpcomponents.client5', name: 'httpclient5', version: '5.3'], [group: 'com.fasterxml.jackson.datatype', name: 'jackson-datatype-jsr310', version: "2.15.2"], [group: 'org.yaml', name: 'snakeyaml', version: "2.2"], ) @@ -41,7 +41,7 @@ dependencies { // use logger only in test implementation in order to have a minimal set of dependencies in main source [group: 'org.slf4j', name: 'slf4j-api', version: "2.0.9"], [group: 'org.junit.jupiter', name: 'junit-jupiter', version: "5.10.0"], - [group: 'ch.qos.logback', name: 'logback-classic', version: "1.4.11"], + [group: 'ch.qos.logback', name: 'logback-classic', version: '1.4.12'], [group: 'org.assertj', name: 'assertj-core', version: "3.24.2"] ) } diff --git a/src/main/java/group/msg/jpowermonitor/measurement/lhm/LibreHardwareMonitorReader.java b/src/main/java/group/msg/jpowermonitor/measurement/lhm/LibreHardwareMonitorReader.java index 39302a8..2d0e5c5 100644 --- a/src/main/java/group/msg/jpowermonitor/measurement/lhm/LibreHardwareMonitorReader.java +++ b/src/main/java/group/msg/jpowermonitor/measurement/lhm/LibreHardwareMonitorReader.java @@ -9,10 +9,9 @@ import group.msg.jpowermonitor.config.PathElement; import group.msg.jpowermonitor.dto.DataPoint; import lombok.NonNull; -import org.apache.http.HttpResponse; -import org.apache.http.client.HttpClient; -import org.apache.http.client.methods.HttpGet; -import org.apache.http.impl.client.HttpClientBuilder; +import org.apache.hc.client5.http.classic.HttpClient; +import org.apache.hc.client5.http.classic.methods.HttpGet; +import org.apache.hc.client5.http.impl.classic.HttpClientBuilder; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -49,15 +48,16 @@ public LibreHardwareMonitorReader(JPowerMonitorConfig config) { public @NotNull List measure() throws JPowerMonitorException { try { LocalDateTime time = LocalDateTime.now(); - HttpResponse response = client.execute(new HttpGet(lhmConfig.getUrl())); - ObjectMapper objectMapper = new ObjectMapper(); - DataElem root = objectMapper.readValue(response.getEntity().getContent(), DataElem.class); - List result = new ArrayList<>(); - for (PathElement pathElement : lhmConfig.getPaths()) { - DataPoint dp = createDataPoint(root, pathElement, time); - result.add(dp); - } - return result; + return client.execute(new HttpGet(lhmConfig.getUrl()), response -> { + ObjectMapper objectMapper = new ObjectMapper(); + DataElem root = objectMapper.readValue(response.getEntity().getContent(), DataElem.class); + List result = new ArrayList<>(); + for (PathElement pathElement : lhmConfig.getPaths()) { + DataPoint dp = createDataPoint(root, pathElement, time); + result.add(dp); + } + return result; + }); } catch (IOException e) { throw new JPowerMonitorException("Unable to reach Libre Hardware Monitor at url: " + lhmConfig.getUrl() + "!", e); } @@ -67,12 +67,13 @@ public LibreHardwareMonitorReader(JPowerMonitorConfig config) { public @NotNull DataPoint measureFirstConfiguredPath() throws JPowerMonitorException { try { LocalDateTime time = LocalDateTime.now(); - HttpResponse response = client.execute(new HttpGet(lhmConfig.getUrl())); - ObjectMapper objectMapper = new ObjectMapper(); - DataElem root = objectMapper.readValue(response.getEntity().getContent(), DataElem.class); - // config assures that getPaths is not null and has at least one element! - PathElement pathElement = lhmConfig.getPaths().get(0); - return createDataPoint(root, pathElement, time); + return client.execute(new HttpGet(lhmConfig.getUrl()), response -> { + ObjectMapper objectMapper = new ObjectMapper(); + DataElem root = objectMapper.readValue(response.getEntity().getContent(), DataElem.class); + // config assures that getPaths is not null and has at least one element! + PathElement pathElement = lhmConfig.getPaths().get(0); + return createDataPoint(root, pathElement, time); + }); } catch (IOException e) { throw new JPowerMonitorException("Unable to reach Libre Hardware Monitor at url: " + lhmConfig.getUrl() + "!", e); }