Skip to content

Commit

Permalink
Update to Apache Http Client 5.3 (#48)
Browse files Browse the repository at this point in the history
Update logback to 1.4.12
  • Loading branch information
earomc authored Jan 12, 2024
1 parent 4cb6883 commit e1a53cb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 21 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
)
Expand All @@ -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"]
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -49,15 +48,16 @@ public LibreHardwareMonitorReader(JPowerMonitorConfig config) {
public @NotNull List<DataPoint> 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<DataPoint> 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<DataPoint> 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);
}
Expand All @@ -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);
}
Expand Down

0 comments on commit e1a53cb

Please sign in to comment.