Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to Apache Http Client 5.3 and update logback to 1.4.12 #48

Merged
merged 1 commit into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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