[java-opensaml] branch main updated: OSJ-376 - Metrics reporter fails to close HTTP response

Scott Cantor cantor.2 at osu.edu
Mon Mar 13 13:01:48 UTC 2023


This is an automated email from the git hooks/post-receive script.

scantor pushed a commit to branch main
in repository java-opensaml.

View the commit online:
http://git.shibboleth.net/view/?p=java-opensaml.git;a=commit;h=d9525530012f04bf08e736b69301dded732d5f9d

The following commit(s) were added to refs/heads/main by this push:
     new d95255300 OSJ-376 - Metrics reporter fails to close HTTP response
d95255300 is described below

commit d9525530012f04bf08e736b69301dded732d5f9d
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Mon Mar 13 09:00:54 2023 -0400

    OSJ-376 - Metrics reporter fails to close HTTP response
    
    https://shibboleth.atlassian.net/browse/OSJ-376
---
 .../opensaml/core/metrics/impl/HTTPReporter.java   | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/opensaml-core-impl/src/main/java/org/opensaml/core/metrics/impl/HTTPReporter.java b/opensaml-core-impl/src/main/java/org/opensaml/core/metrics/impl/HTTPReporter.java
index ec5e03f3a..fe64f5938 100644
--- a/opensaml-core-impl/src/main/java/org/opensaml/core/metrics/impl/HTTPReporter.java
+++ b/opensaml-core-impl/src/main/java/org/opensaml/core/metrics/impl/HTTPReporter.java
@@ -32,9 +32,9 @@ import org.apache.hc.client5.http.classic.HttpClient;
 import org.apache.hc.client5.http.classic.methods.HttpPost;
 import org.apache.hc.client5.http.entity.EntityBuilder;
 import org.apache.hc.client5.http.protocol.HttpClientContext;
+import org.apache.hc.core5.http.ClassicHttpResponse;
 import org.apache.hc.core5.http.ContentType;
 import org.apache.hc.core5.http.HttpRequest;
-import org.apache.hc.core5.http.HttpResponse;
 import org.apache.hc.core5.http.HttpStatus;
 import org.opensaml.security.httpclient.HttpClientSecurityParameters;
 import org.opensaml.security.httpclient.HttpClientSecuritySupport;
@@ -266,13 +266,13 @@ public class HTTPReporter extends ScheduledReporter implements InitializableComp
                 entityBuilder.setBinary(output.toByteArray());
                 httpRequest.setEntity(entityBuilder.build());
 
-                final HttpResponse response = httpClient.executeOpen(null, httpRequest, httpContext);
-                HttpClientSecuritySupport.checkTLSCredentialEvaluated(httpContext, httpRequest.getScheme());
-                
-                if (response.getCode() == HttpStatus.SC_OK) {
-                    log.debug("Metrics delivered successfully to collector");
-                } else {
-                    log.error("Collector responded with HTTP status {}", response.getCode());
+                try (final ClassicHttpResponse response = httpClient.executeOpen(null, httpRequest, httpContext)) {
+                    HttpClientSecuritySupport.checkTLSCredentialEvaluated(httpContext, httpRequest.getScheme());
+                    if (response.getCode() == HttpStatus.SC_OK) {
+                        log.debug("Metrics delivered successfully to collector");
+                    } else {
+                        log.error("Collector responded with HTTP status {}", response.getCode());
+                    }
                 }
             } catch (final IOException e) {
                 log.error("Error sending metric registry to collection point {}", collectorURL, e);
@@ -282,9 +282,9 @@ public class HTTPReporter extends ScheduledReporter implements InitializableComp
     
     /** {@inheritDoc} */
     @Override
-    public void report(final SortedMap<String, Gauge> gauges, final SortedMap<String, Counter> counters,
-            final SortedMap<String, Histogram> histograms, final SortedMap<String, Meter> meters,
-            final SortedMap<String, Timer> timers) {
+    public void report(@SuppressWarnings("rawtypes") final SortedMap<String, Gauge> gauges,
+            final SortedMap<String, Counter> counters, final SortedMap<String, Histogram> histograms,
+            final SortedMap<String, Meter> meters, final SortedMap<String, Timer> timers) {
         throw new UnsupportedOperationException("The per-metric report method should never be called.");
     }
 

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the commits mailing list