Skip to content

Commit 46469e9

Browse files
committed
Replace javax by jakarta + adapt tests to jetty 11
Signed-off-by: Nicolas Trangosi <nicolas.trangosi@dcbrain.com>
1 parent 2e3d636 commit 46469e9

File tree

8 files changed

+54
-43
lines changed

8 files changed

+54
-43
lines changed

.gitignore

+7
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@
88
.idea
99
*.iml
1010

11+
### STS ###
12+
.apt_generated
13+
.classpath
14+
.factorypath
15+
.project
16+
.settings
17+
1118
target/
1219
simpleclient_pushgateway/mockserver.log
1320
simpleclient_pushgateway/mockserver_request.log

pom.xml

+1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
<module>simpleclient_logback</module>
5858
<module>simpleclient_pushgateway</module>
5959
<module>simpleclient_servlet</module>
60+
<module>simpleclient_servlet_jakarta</module>
6061
<module>simpleclient_spring_web</module>
6162
<module>simpleclient_spring_boot</module>
6263
<module>simpleclient_jetty</module>

simpleclient_servlet_jakarta/pom.xml

+7-7
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99
</parent>
1010

1111
<groupId>io.prometheus</groupId>
12-
<artifactId>simpleclient_servlet</artifactId>
12+
<artifactId>simpleclient_servlet_jakarta</artifactId>
1313
<packaging>bundle</packaging>
1414

15-
<name>Prometheus Java Simpleclient Servlet</name>
15+
<name>Prometheus Java Simpleclient jakarta Servlet</name>
1616
<description>
17-
HTTP servlet exporter for the simpleclient.
17+
HTTP jakarta servlet exporter for the simpleclient.
1818
</description>
1919

2020
<licenses>
@@ -49,9 +49,9 @@
4949
<version>0.10.1-SNAPSHOT</version>
5050
</dependency>
5151
<dependency>
52-
<groupId>javax.servlet</groupId>
53-
<artifactId>javax.servlet-api</artifactId>
54-
<version>3.0.1</version>
52+
<groupId>jakarta.servlet</groupId>
53+
<artifactId>jakarta.servlet-api</artifactId>
54+
<version>5.0.0</version>
5555
<scope>provided</scope>
5656
</dependency>
5757
<!-- Test Dependencies Follow -->
@@ -70,7 +70,7 @@
7070
<dependency>
7171
<groupId>org.eclipse.jetty</groupId>
7272
<artifactId>jetty-servlet</artifactId>
73-
<version>8.1.7.v20120910</version>
73+
<version>11.0.2</version>
7474
<scope>test</scope>
7575
</dependency>
7676
<dependency>

simpleclient_servlet_jakarta/src/main/java/io/prometheus/client/exporter/MetricsServlet.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
import io.prometheus.client.CollectorRegistry;
44
import io.prometheus.client.exporter.common.TextFormat;
55

6-
import javax.servlet.ServletException;
7-
import javax.servlet.http.HttpServlet;
8-
import javax.servlet.http.HttpServletRequest;
9-
import javax.servlet.http.HttpServletResponse;
6+
import jakarta.servlet.ServletException;
7+
import jakarta.servlet.http.HttpServlet;
8+
import jakarta.servlet.http.HttpServletRequest;
9+
import jakarta.servlet.http.HttpServletResponse;
1010
import java.io.BufferedWriter;
1111
import java.io.IOException;
1212
import java.io.Writer;

simpleclient_servlet_jakarta/src/main/java/io/prometheus/client/filter/MetricsFilter.java

+8-8
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
import io.prometheus.client.Counter;
44
import io.prometheus.client.Histogram;
55

6-
import javax.servlet.Filter;
7-
import javax.servlet.FilterChain;
8-
import javax.servlet.FilterConfig;
9-
import javax.servlet.ServletException;
10-
import javax.servlet.ServletRequest;
11-
import javax.servlet.ServletResponse;
12-
import javax.servlet.http.HttpServletRequest;
13-
import javax.servlet.http.HttpServletResponse;
6+
import jakarta.servlet.Filter;
7+
import jakarta.servlet.FilterChain;
8+
import jakarta.servlet.FilterConfig;
9+
import jakarta.servlet.ServletException;
10+
import jakarta.servlet.ServletRequest;
11+
import jakarta.servlet.ServletResponse;
12+
import jakarta.servlet.http.HttpServletRequest;
13+
import jakarta.servlet.http.HttpServletResponse;
1414
import java.io.IOException;
1515

1616
/**

simpleclient_servlet_jakarta/src/test/java/io/prometheus/client/exporter/ExampleBenchmark.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import io.prometheus.client.Gauge;
44
import org.eclipse.jetty.server.Server;
5+
import org.eclipse.jetty.server.ServerConnector;
56
import org.eclipse.jetty.servlet.ServletContextHandler;
67
import org.eclipse.jetty.servlet.ServletHolder;
78

@@ -27,9 +28,9 @@ public static void main(String[] args) throws Exception {
2728
server.setHandler(context);
2829
server.start();
2930
Thread.sleep(1000);
30-
31+
ServerConnector connector = (ServerConnector) server.getConnectors()[0];
3132
byte[] bytes = new byte[8192];
32-
URL url = new URL("http", "localhost", server.getConnectors()[0].getLocalPort(), "/metrics");
33+
URL url = new URL("http", "localhost", connector.getLocalPort(), "/metrics");
3334

3435
long start = System.nanoTime();
3536
for (int i = 0; i < 100; i++) {

simpleclient_servlet_jakarta/src/test/java/io/prometheus/client/exporter/MetricsServletTest.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
import io.prometheus.client.Gauge;
55
import org.junit.Test;
66

7-
import javax.servlet.ServletException;
8-
import javax.servlet.http.HttpServletRequest;
9-
import javax.servlet.http.HttpServletResponse;
7+
import jakarta.servlet.ServletException;
8+
import jakarta.servlet.http.HttpServletRequest;
9+
import jakarta.servlet.http.HttpServletResponse;
1010
import java.io.IOException;
1111
import java.io.PrintWriter;
1212
import java.io.StringWriter;

simpleclient_servlet_jakarta/src/test/java/io/prometheus/client/filter/MetricsFilterTest.java

+21-19
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,18 @@
22

33
import io.prometheus.client.Collector;
44
import io.prometheus.client.CollectorRegistry;
5+
6+
import org.eclipse.jetty.http.HttpMethod;
57
import org.junit.After;
68
import org.junit.Test;
79
import org.mockito.invocation.InvocationOnMock;
810
import org.mockito.stubbing.Answer;
911

10-
import javax.servlet.FilterChain;
11-
import javax.servlet.FilterConfig;
12-
import javax.servlet.ServletResponse;
13-
import javax.servlet.http.HttpServletRequest;
14-
import javax.servlet.http.HttpServletResponse;
12+
import jakarta.servlet.FilterChain;
13+
import jakarta.servlet.FilterConfig;
14+
import jakarta.servlet.ServletResponse;
15+
import jakarta.servlet.http.HttpServletRequest;
16+
import jakarta.servlet.http.HttpServletResponse;
1517
import java.util.Enumeration;
1618

1719
import static org.junit.Assert.assertEquals;
@@ -48,7 +50,7 @@ public void init() throws Exception {
4850
HttpServletRequest req = mock(HttpServletRequest.class);
4951

5052
when(req.getRequestURI()).thenReturn("/foo/bar/baz/bang/zilch/zip/nada");
51-
when(req.getMethod()).thenReturn(HttpMethods.GET);
53+
when(req.getMethod()).thenReturn(HttpMethod.GET.asString());
5254

5355
HttpServletResponse res = mock(HttpServletResponse.class);
5456
FilterChain c = mock(FilterChain.class);
@@ -60,7 +62,7 @@ public void init() throws Exception {
6062
final Double sampleValue = CollectorRegistry.defaultRegistry.getSampleValue(
6163
metricName + "_count",
6264
new String[] { "path", "method" },
63-
new String[] { "/foo/bar/baz/bang", HttpMethods.GET });
65+
new String[] { "/foo/bar/baz/bang", HttpMethod.GET.asString() });
6466
assertNotNull(sampleValue);
6567
assertEquals(1, sampleValue, 0.0001);
6668
}
@@ -71,7 +73,7 @@ public void doFilter() throws Exception {
7173
final String path = "/foo/bar/baz/bang/zilch/zip/nada";
7274

7375
when(req.getRequestURI()).thenReturn(path);
74-
when(req.getMethod()).thenReturn(HttpMethods.GET);
76+
when(req.getMethod()).thenReturn(HttpMethod.GET.asString());
7577

7678
HttpServletResponse res = mock(HttpServletResponse.class);
7779
FilterChain c = mock(FilterChain.class);
@@ -88,7 +90,7 @@ public void doFilter() throws Exception {
8890

8991
final Double sampleValue = CollectorRegistry.defaultRegistry.getSampleValue(name + "_count",
9092
new String[] { "path", "method" },
91-
new String[] { path, HttpMethods.GET });
93+
new String[] { path, HttpMethod.GET.asString() });
9294
assertNotNull(sampleValue);
9395
assertEquals(1, sampleValue, 0.0001);
9496
}
@@ -98,7 +100,7 @@ public void testConstructor() throws Exception {
98100
HttpServletRequest req = mock(HttpServletRequest.class);
99101
final String path = "/foo/bar/baz/bang";
100102
when(req.getRequestURI()).thenReturn(path);
101-
when(req.getMethod()).thenReturn(HttpMethods.POST);
103+
when(req.getMethod()).thenReturn(HttpMethod.POST.asString());
102104

103105
FilterChain c = mock(FilterChain.class);
104106
doAnswer(new Answer<Void>() {
@@ -119,7 +121,7 @@ public Void answer(InvocationOnMock invocationOnMock) throws Throwable {
119121
final Double sum = CollectorRegistry.defaultRegistry.getSampleValue(
120122
"foobar_baz_filter_duration_seconds_sum",
121123
new String[] { "path", "method" },
122-
new String[] { path, HttpMethods.POST });
124+
new String[] { path, HttpMethod.POST.asString() });
123125
assertNotNull(sum);
124126
assertEquals(0.1, sum, 0.01);
125127
}
@@ -129,7 +131,7 @@ public void testBucketsAndName() throws Exception {
129131
HttpServletRequest req = mock(HttpServletRequest.class);
130132
final String path = "/foo/bar/baz/bang";
131133
when(req.getRequestURI()).thenReturn(path);
132-
when(req.getMethod()).thenReturn(HttpMethods.POST);
134+
when(req.getMethod()).thenReturn(HttpMethod.POST.asString());
133135

134136
FilterChain c = mock(FilterChain.class);
135137
doAnswer(new Answer<Void>() {
@@ -153,17 +155,17 @@ public Void answer(InvocationOnMock invocationOnMock) throws Throwable {
153155

154156
final Double sum = CollectorRegistry.defaultRegistry.getSampleValue("foo_sum",
155157
new String[] { "path", "method" },
156-
new String[] { "/foo", HttpMethods.POST });
158+
new String[] { "/foo", HttpMethod.POST.asString() });
157159
assertEquals(0.1, sum, 0.01);
158160

159161
final Double le05 = CollectorRegistry.defaultRegistry.getSampleValue("foo_bucket",
160162
new String[] { "path", "method", "le" },
161-
new String[] { "/foo", HttpMethods.POST, "0.05" });
163+
new String[] { "/foo", HttpMethod.POST.asString(), "0.05" });
162164
assertNotNull(le05);
163165
assertEquals(0, le05, 0.01);
164166
final Double le15 = CollectorRegistry.defaultRegistry.getSampleValue("foo_bucket",
165167
new String[] { "path", "method", "le" },
166-
new String[] { "/foo", HttpMethods.POST, "0.15" });
168+
new String[] { "/foo", HttpMethod.POST.asString(), "0.15" });
167169
assertNotNull(le15);
168170
assertEquals(1, le15, 0.01);
169171

@@ -193,7 +195,7 @@ public Void answer(InvocationOnMock invocationOnMock) throws Throwable {
193195
public void testStatusCode() throws Exception {
194196
HttpServletRequest req = mock(HttpServletRequest.class);
195197
when(req.getRequestURI()).thenReturn("/foo/bar/baz/bang");
196-
when(req.getMethod()).thenReturn(HttpMethods.GET);
198+
when(req.getMethod()).thenReturn(HttpMethod.GET.asString());
197199

198200
HttpServletResponse res = mock(HttpServletResponse.class);
199201
when(res.getStatus()).thenReturn(200);
@@ -209,7 +211,7 @@ public void testStatusCode() throws Exception {
209211
final Double sampleValue = CollectorRegistry.defaultRegistry.getSampleValue(
210212
"foobar_filter_status_total",
211213
new String[] { "path", "method", "status" },
212-
new String[] { "/foo/bar", HttpMethods.GET, "200" });
214+
new String[] { "/foo/bar", HttpMethod.GET.asString(), "200" });
213215
assertNotNull(sampleValue);
214216
assertEquals(1, sampleValue, 0.0001);
215217
}
@@ -218,7 +220,7 @@ public void testStatusCode() throws Exception {
218220
public void testStatusCodeWithNonHttpServletResponse() throws Exception {
219221
HttpServletRequest req = mock(HttpServletRequest.class);
220222
when(req.getRequestURI()).thenReturn("/foo/bar/baz/bang");
221-
when(req.getMethod()).thenReturn(HttpMethods.GET);
223+
when(req.getMethod()).thenReturn(HttpMethod.GET.asString());
222224

223225
ServletResponse res = mock(ServletResponse.class);
224226

@@ -235,7 +237,7 @@ public void testStatusCodeWithNonHttpServletResponse() throws Exception {
235237
new String[] { "path", "method", "status" },
236238
new String[] {
237239
"/foo/bar",
238-
HttpMethods.GET,
240+
HttpMethod.GET.asString(),
239241
MetricsFilter.UNKNOWN_HTTP_STATUS_CODE });
240242
assertNotNull(sampleValue);
241243
assertEquals(1, sampleValue, 0.0001);

0 commit comments

Comments
 (0)