Skip to content

Commit

Permalink
Close response in AasClient.
Browse files Browse the repository at this point in the history
  • Loading branch information
kenwenzel committed Nov 5, 2024
1 parent adb70a0 commit 3f0674a
Showing 1 changed file with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@
import net.enilink.komma.core.URIs;
import net.enilink.vocab.rdf.RDF;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.Closeable;
import java.io.IOException;
Expand All @@ -27,6 +28,8 @@
import java.util.function.Supplier;

public class AasClient implements Closeable {
private static Logger logger = LoggerFactory.getLogger(AasClient.class);

final String endpoint;
ObjectMapper mapper = new ObjectMapper();
CloseableHttpClient httpClient;
Expand Down Expand Up @@ -73,7 +76,7 @@ protected IExtendedIterator<Record> query(String endpoint, String path, Map<Stri

// sending get request to the endpoint
HttpGet httpGet = createHttpGet(getRequestUri.toString());
HttpResponse response = this.httpClient.execute(httpGet);
var response = this.httpClient.execute(httpGet);
HttpEntity entity = response.getEntity();
try (InputStream content = entity.getContent()) {
if (response.getStatusLine().getStatusCode() != 200) {
Expand Down Expand Up @@ -103,6 +106,14 @@ protected IExtendedIterator<Record> query(String endpoint, String path, Map<Stri
} else {
return WrappedIterator.create(Collections.singleton((Record) nodeToValue(node)).iterator());
}
} finally {
if (response != null) {
try {
response.close();
} catch (IOException ioe) {
logger.error("Error while closing response", ioe);
}
}
}
}

Expand Down

0 comments on commit 3f0674a

Please sign in to comment.