This is an automated email from the ASF dual-hosted git repository.
enapps-enorman pushed a commit to branch master
in repository
https://gitbox.apache.org/repos/asf/sling-org-apache-sling-commons-metrics.git
The following commit(s) were added to refs/heads/master by this push:
new 7ac8164 SLING-13182 migrate to jakarta Servlet (#11)
7ac8164 is described below
commit 7ac8164f399c6ee64149194dc6b4d67c870f7acf
Author: Eric Norman <[email protected]>
AuthorDate: Tue Apr 28 11:49:41 2026 -0700
SLING-13182 migrate to jakarta Servlet (#11)
---
bnd.bnd | 8 +++---
pom.xml | 8 +++---
.../metrics/internal/MetricWebConsolePlugin.java | 32 +++++++++++-----------
.../internal/MetricWebConsolePluginTest.java | 30 ++++++--------------
4 files changed, 32 insertions(+), 46 deletions(-)
diff --git a/bnd.bnd b/bnd.bnd
index 84d7e0e..68aa74b 100644
--- a/bnd.bnd
+++ b/bnd.bnd
@@ -1,14 +1,14 @@
Bundle-DocURL: https://sling.apache.org/documentation/bundles/metrics.html
DynamicImport-Package:\
- javax.servlet,\
- javax.servlet.http,\
+ jakarta.servlet,\
+ jakarta.servlet.http,\
org.apache.commons.io.output,\
org.apache.felix.inventory
Import-Package:\
- javax.servlet;resolution:=optional,\
- javax.servlet.http;resolution:=optional,\
+ jakarta.servlet;resolution:=optional,\
+ jakarta.servlet.http;resolution:=optional,\
org.apache.commons.io.output;resolution:=optional,\
org.apache.felix.inventory;resolution:=optional,\
*
diff --git a/pom.xml b/pom.xml
index afa560e..dd6c14d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -29,7 +29,7 @@
</parent>
<artifactId>org.apache.sling.commons.metrics</artifactId>
- <version>1.2.15-SNAPSHOT</version>
+ <version>2.0.0-SNAPSHOT</version>
<name>Apache Sling Commons Metrics</name>
<description>Integrates Metric library with Sling. Refer to
@@ -57,8 +57,8 @@
<scope>test</scope>
</dependency>
<dependency>
- <groupId>javax.servlet</groupId>
- <artifactId>javax.servlet-api</artifactId>
+ <groupId>jakarta.servlet</groupId>
+ <artifactId>jakarta.servlet-api</artifactId>
<scope>provided</scope>
<optional>true</optional>
</dependency>
@@ -126,7 +126,7 @@
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.testing.sling-mock.junit4</artifactId>
- <version>3.5.4</version>
+ <version>4.0.6</version>
<scope>test</scope>
</dependency>
<dependency>
diff --git
a/src/main/java/org/apache/sling/commons/metrics/internal/MetricWebConsolePlugin.java
b/src/main/java/org/apache/sling/commons/metrics/internal/MetricWebConsolePlugin.java
index 5e4eab2..6b98c5c 100644
---
a/src/main/java/org/apache/sling/commons/metrics/internal/MetricWebConsolePlugin.java
+++
b/src/main/java/org/apache/sling/commons/metrics/internal/MetricWebConsolePlugin.java
@@ -18,11 +18,6 @@
*/
package org.apache.sling.commons.metrics.internal;
-import javax.servlet.Servlet;
-import javax.servlet.http.HttpServlet;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
import java.io.IOException;
import java.io.PrintStream;
import java.io.PrintWriter;
@@ -43,6 +38,10 @@ import com.codahale.metrics.Metric;
import com.codahale.metrics.MetricRegistry;
import com.codahale.metrics.Snapshot;
import com.codahale.metrics.Timer;
+import jakarta.servlet.Servlet;
+import jakarta.servlet.http.HttpServlet;
+import jakarta.servlet.http.HttpServletRequest;
+import jakarta.servlet.http.HttpServletResponse;
import org.apache.commons.io.output.WriterOutputStream;
import org.apache.felix.inventory.Format;
import org.apache.felix.inventory.InventoryPrinter;
@@ -75,19 +74,20 @@ public class MetricWebConsolePlugin extends HttpServlet
*/
public static final String METRIC_REGISTRY_NAME = "name";
- private final Logger log = LoggerFactory.getLogger(getClass());
- private BundleContext context;
- private ServiceTracker<MetricRegistry, MetricRegistry> tracker;
- private ConcurrentMap<ServiceReference, MetricRegistry> registries = new
ConcurrentHashMap<>();
+ private final transient Logger log = LoggerFactory.getLogger(getClass());
+ private final transient BundleContext context;
+ private final transient ServiceTracker<MetricRegistry, MetricRegistry>
tracker;
+ private final transient ConcurrentMap<ServiceReference<MetricRegistry>,
MetricRegistry> registries =
+ new ConcurrentHashMap<>();
- private TimeUnit rateUnit = TimeUnit.SECONDS;
- private TimeUnit durationUnit = TimeUnit.MILLISECONDS;
- private Map<String, TimeUnit> specificDurationUnits =
Collections.emptyMap();
- private Map<String, TimeUnit> specificRateUnits = Collections.emptyMap();
- private MetricTimeUnits timeUnit;
+ private final transient TimeUnit rateUnit = TimeUnit.SECONDS;
+ private final transient TimeUnit durationUnit = TimeUnit.MILLISECONDS;
+ private final transient Map<String, TimeUnit> specificDurationUnits =
Collections.emptyMap();
+ private final transient Map<String, TimeUnit> specificRateUnits =
Collections.emptyMap();
+ private final transient MetricTimeUnits timeUnit;
@Activate
- private void activate(BundleContext context) {
+ public MetricWebConsolePlugin(BundleContext context) {
this.context = context;
this.timeUnit = new MetricTimeUnits(rateUnit, durationUnit,
specificRateUnits, specificDurationUnits);
tracker = new ServiceTracker<>(context, MetricRegistry.class, this);
@@ -422,7 +422,7 @@ public class MetricWebConsolePlugin extends HttpServlet
MetricRegistry getConsolidatedRegistry() {
MetricRegistry registry = new MetricRegistry();
- for (Map.Entry<ServiceReference, MetricRegistry> registryEntry :
registries.entrySet()) {
+ for (Map.Entry<ServiceReference<MetricRegistry>, MetricRegistry>
registryEntry : registries.entrySet()) {
String metricRegistryName = (String)
registryEntry.getKey().getProperty(METRIC_REGISTRY_NAME);
for (Map.Entry<String, Metric> metricEntry :
registryEntry.getValue().getMetrics().entrySet()) {
diff --git
a/src/test/java/org/apache/sling/commons/metrics/internal/MetricWebConsolePluginTest.java
b/src/test/java/org/apache/sling/commons/metrics/internal/MetricWebConsolePluginTest.java
index e328c0b..3b11306 100644
---
a/src/test/java/org/apache/sling/commons/metrics/internal/MetricWebConsolePluginTest.java
+++
b/src/test/java/org/apache/sling/commons/metrics/internal/MetricWebConsolePluginTest.java
@@ -18,17 +18,15 @@
*/
package org.apache.sling.commons.metrics.internal;
-import javax.servlet.http.HttpServletRequest;
-
import java.io.PrintWriter;
import java.io.StringWriter;
-import java.io.Writer;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import com.codahale.metrics.JvmAttributeGaugeSet;
import com.codahale.metrics.MetricRegistry;
+import jakarta.servlet.http.HttpServletRequest;
import org.apache.felix.inventory.Format;
import org.apache.felix.utils.json.JSONParser;
import org.apache.sling.testing.mock.osgi.MockOsgi;
@@ -57,7 +55,7 @@ public class MetricWebConsolePluginTest {
@Rule
public final SlingContext context = new SlingContext();
- private MetricWebConsolePlugin plugin = new MetricWebConsolePlugin();
+ private MetricWebConsolePlugin plugin = new
MetricWebConsolePlugin(context.bundleContext());
private static Map<String, Object> regProps(String name) {
Map<String, Object> props = new HashMap<String, Object>();
@@ -66,7 +64,7 @@ public class MetricWebConsolePluginTest {
}
@Test
- public void consolidatedRegistry() throws Exception {
+ public void consolidatedRegistry() {
MetricRegistry reg1 = new MetricRegistry();
reg1.meter("test1");
context.registerService(MetricRegistry.class, reg1, regProps("foo"));
@@ -105,7 +103,7 @@ public class MetricWebConsolePluginTest {
}
@Test
- public void inventory_text() throws Exception {
+ public void inventory_text() {
MetricRegistry reg1 = new MetricRegistry();
reg1.meter("test1").mark(5);
context.registerService(MetricRegistry.class, reg1, regProps("foo"));
@@ -123,7 +121,7 @@ public class MetricWebConsolePluginTest {
}
@Test
- public void inventory_json() throws Exception {
+ public void inventory_json() {
MetricRegistry reg1 = new MetricRegistry();
reg1.meter("test1").mark(5);
context.registerService(MetricRegistry.class, reg1, regProps("foo"));
@@ -151,11 +149,11 @@ public class MetricWebConsolePluginTest {
activatePlugin();
- plugin.doGet(mock(HttpServletRequest.class), context.response());
+ plugin.doGet(mock(HttpServletRequest.class),
context.jakartaResponse());
try (WebClient client = new WebClient(); ) {
- HtmlPage page =
-
client.loadHtmlCodeIntoCurrentWindow(context.response().getOutputAsString());
+ HtmlPage page = client.loadHtmlCodeIntoCurrentWindow(
+ context.jakartaResponse().getOutputAsString());
assertTable("data-meters", page);
assertTable("data-counters", page);
@@ -176,16 +174,4 @@ public class MetricWebConsolePluginTest {
private void activatePlugin() {
MockOsgi.activate(plugin, context.bundleContext(),
Collections.<String, Object>emptyMap());
}
-
- private static class CloseRecordingWriter extends PrintWriter {
-
- public CloseRecordingWriter(Writer out) {
- super(out);
- }
-
- @Override
- public void close() {
- super.close();
- }
- }
}