[java-opensaml] branch main updated: OSJ-462 - Metrics PushResporter cannot be initialized

Codeberg noreply at shibboleth.net
Thu Sep 3 13:19:55 UTC 2026


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

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

View the commit online:
https://codeberg.org/Shibboleth/java-opensaml/commit/8cbbe2c7539f6fe0895de4f95882afb3a00d72e0

The following commit(s) were added to refs/heads/main by this push:
     new 8cbbe2c75 OSJ-462 - Metrics PushResporter cannot be initialized
8cbbe2c75 is described below

commit 8cbbe2c7539f6fe0895de4f95882afb3a00d72e0
Author: Scott Cantor <scott at restingparrotsoftware.com>
AuthorDate: Thu Sep 3 09:19:40 2026 -0400

    OSJ-462 - Metrics PushResporter cannot be initialized
    
    https://shibboleth.atlassian.net/browse/OSJ-462
    
    Fixed init handling.
    Added unit test.
    Also added new OnTeardown annotation to stop method.
---
 .../opensaml/core/metrics/impl/HTTPReporter.java   | 26 ++++++++++----
 .../core/metrics/impl/HTTPReporterTest.java        | 40 ++++++++++++++++++++++
 2 files changed, 60 insertions(+), 6 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 1551391c6..0ed15c3fe 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
@@ -51,6 +51,7 @@ import com.fasterxml.jackson.databind.ObjectWriter;
 import com.fasterxml.jackson.databind.SerializationFeature;
 import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
 
+import net.shibboleth.shared.annotation.OnTeardown;
 import net.shibboleth.shared.annotation.ParameterName;
 import net.shibboleth.shared.annotation.constraint.NonnullAfterInit;
 import net.shibboleth.shared.annotation.constraint.NotEmpty;
@@ -171,7 +172,7 @@ public class HTTPReporter extends ScheduledReporter implements InitializableComp
      * @param client client to use
      */
     public void setHttpClient(@Nonnull final HttpClient client) {
-        doSetterPreconditions();
+        checkSetterPreconditions();
         httpClient = Constraint.isNotNull(client, "HttpClient cannot be null");
     }
     
@@ -181,7 +182,7 @@ public class HTTPReporter extends ScheduledReporter implements InitializableComp
      * @param url URL to post data to
      */
     public void setCollectorURL(@Nonnull @NotEmpty final String url) {
-        doSetterPreconditions();
+        checkSetterPreconditions();
         collectorURL = Constraint.isNotNull(StringSupport.trimOrNull(url), "Collector URL cannot be null or empty");
     }
 
@@ -191,7 +192,7 @@ public class HTTPReporter extends ScheduledReporter implements InitializableComp
      * @param params the new client security parameters
      */
     public void setHttpClientSecurityParameters(@Nullable final HttpClientSecurityParameters params) {
-        doSetterPreconditions();
+        checkSetterPreconditions();
         httpClientSecurityParameters = params;
     }
     
@@ -201,17 +202,27 @@ public class HTTPReporter extends ScheduledReporter implements InitializableComp
      * @param format formatting string
      */
     public void setDateTimeFormat(@Nullable @NotEmpty final String format) {
-        doSetterPreconditions();
+        checkSetterPreconditions();
         dateTimeFormat = StringSupport.trimOrNull(format);
     }
     
     /**
      * Helper for a setter method to check the standard preconditions.
      */
-    private final void doSetterPreconditions() {
+    private final void checkSetterPreconditions() {
+        if (isInitialized()) {
+            throw new UninitializedComponentException(
+                    "HTTPReporter has already been initialized.");
+        }
+    }
+
+    /**
+     * Helper for a method to check for component initialization.
+     */
+    private final void checkComponentActive() {
         if (!isInitialized()) {
             throw new UninitializedComponentException(
-                    "HTTPReported has not yet been initialized and cannot be used.");
+                    "HTTPReporter has not yet been initialized and cannot be used.");
         }
     }
     
@@ -239,6 +250,7 @@ public class HTTPReporter extends ScheduledReporter implements InitializableComp
     
     /** {@inheritDoc} */
     @Override
+    @OnTeardown
     public void stop() {
         super.stop();
         httpClient = null;
@@ -248,6 +260,8 @@ public class HTTPReporter extends ScheduledReporter implements InitializableComp
     /** {@inheritDoc} */
     @Override
     public void report() {
+        checkComponentActive();
+        
         synchronized (this) {
             try {
                 final HttpPost httpRequest = new HttpPost(collectorURL);
diff --git a/opensaml-core-impl/src/test/java/org/opensaml/core/metrics/impl/HTTPReporterTest.java b/opensaml-core-impl/src/test/java/org/opensaml/core/metrics/impl/HTTPReporterTest.java
new file mode 100644
index 000000000..a1dcd9bbf
--- /dev/null
+++ b/opensaml-core-impl/src/test/java/org/opensaml/core/metrics/impl/HTTPReporterTest.java
@@ -0,0 +1,40 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.opensaml.core.metrics.impl;
+
+import org.opensaml.core.metrics.MetricsSupport;
+import org.opensaml.core.testing.OpenSAMLInitBaseTestCase;
+import org.testng.annotations.Test;
+
+import net.shibboleth.shared.httpclient.HttpClientBuilder;
+
+/**
+ * Unit test for {@link HTTPReporter}.
+ */
+public class HTTPReporterTest extends OpenSAMLInitBaseTestCase {
+
+    /** Basic test of component's lifecycle. */
+    @Test
+    public void test() throws Exception {
+     
+        final HTTPReporter reporter = new HTTPReporter(MetricsSupport.getMetricRegistry(), "test", null);
+        reporter.setCollectorURL("https://localhost/reporter");
+        reporter.setHttpClient(new HttpClientBuilder().buildClient());
+        reporter.initialize();
+        
+        reporter.stop();
+    }
+    
+}
\ No newline at end of file

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


More information about the commits mailing list