[java-shib-shared] branch main updated: Port tests to Jetty 12.
Scott Cantor
cantor.2 at osu.edu
Tue Apr 8 13:08:50 UTC 2025
This is an automated email from the git hooks/post-receive script.
scantor pushed a commit to branch main
in repository java-shib-shared.
View the commit online:
http://git.shibboleth.net/view/?p=java-shib-shared.git;a=commit;h=53925496c12732f753b3d34fba8bb03d3c851454
The following commit(s) were added to refs/heads/main by this push:
new 53925496 Port tests to Jetty 12.
53925496 is described below
commit 53925496c12732f753b3d34fba8bb03d3c851454
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Tue Apr 8 09:08:47 2025 -0400
Port tests to Jetty 12.
---
shib-networking/pom.xml | 2 +-
.../RequestTimeLimitingHttpClientTest.java | 52 +++++++++++-----------
2 files changed, 27 insertions(+), 27 deletions(-)
diff --git a/shib-networking/pom.xml b/shib-networking/pom.xml
index e63b2490..a153250d 100644
--- a/shib-networking/pom.xml
+++ b/shib-networking/pom.xml
@@ -15,7 +15,7 @@
<packaging>jar</packaging>
<properties>
- <jetty.version>11.0.9</jetty.version>
+ <jetty.version>12.0.19</jetty.version>
<automatic.module.name>net.shibboleth.networking</automatic.module.name>
<checkstyle.configLocation>${project.basedir}/../resources/checkstyle/checkstyle.xml</checkstyle.configLocation>
</properties>
diff --git a/shib-networking/src/test/java/net/shibboleth/shared/httpclient/RequestTimeLimitingHttpClientTest.java b/shib-networking/src/test/java/net/shibboleth/shared/httpclient/RequestTimeLimitingHttpClientTest.java
index 83edf3fe..29d4c3fc 100644
--- a/shib-networking/src/test/java/net/shibboleth/shared/httpclient/RequestTimeLimitingHttpClientTest.java
+++ b/shib-networking/src/test/java/net/shibboleth/shared/httpclient/RequestTimeLimitingHttpClientTest.java
@@ -15,11 +15,11 @@
package net.shibboleth.shared.httpclient;
import java.io.Closeable;
-import java.io.IOException;
import java.net.InetAddress;
import java.net.InterfaceAddress;
import java.net.NetworkInterface;
import java.nio.ByteBuffer;
+import java.nio.charset.StandardCharsets;
import java.time.Duration;
import java.util.ArrayList;
import java.util.Collection;
@@ -38,12 +38,14 @@ import org.apache.hc.client5.http.classic.methods.HttpGet;
import org.apache.hc.client5.http.classic.methods.HttpUriRequest;
import org.apache.hc.client5.http.protocol.HttpClientContext;
import org.apache.hc.core5.http.ClassicHttpResponse;
+import org.eclipse.jetty.http.HttpHeader;
import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.server.Request;
+import org.eclipse.jetty.server.Response;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector;
-import org.eclipse.jetty.server.handler.AbstractHandler;
+import org.eclipse.jetty.util.Callback;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterMethod;
@@ -52,16 +54,15 @@ import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import jakarta.servlet.ServletException;
-import jakarta.servlet.http.HttpServletRequest;
-import jakarta.servlet.http.HttpServletResponse;
import net.shibboleth.shared.collection.CollectionSupport;
import net.shibboleth.shared.collection.Pair;
import net.shibboleth.shared.net.URLBuilder;
import net.shibboleth.shared.primitive.StringSupport;
/**
- *
+ * Unit test for {@link RequestTimeLimitingHttpClient}.
*/
+ at SuppressWarnings("javadoc")
public class RequestTimeLimitingHttpClientTest {
private static final String REQUEST_BASE = "http://localhost:8080/sleep";
@@ -236,7 +237,7 @@ public class RequestTimeLimitingHttpClientTest {
return server;
}
- private static class MappingHandler extends AbstractHandler {
+ private static class MappingHandler extends Handler.Abstract {
private Map<String, Handler> handlers;
@@ -246,27 +247,25 @@ public class RequestTimeLimitingHttpClientTest {
handlers.put("/sleep", new SleepHandler());
}
- public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response)
- throws IOException, ServletException {
-
- if (handlers.containsKey(target)) {
- handlers.get(target).handle(target, baseRequest, request, response);
- } else {
- throw new ServletException("Unmapped target: " + target);
+ /** {@inheritDoc} */
+ @Override
+ public boolean handle(Request request, Response response, Callback callback) throws Exception {
+ final String path = Request.getPathInContext(request);
+ if (handlers.containsKey(path)) {
+ return handlers.get(path).handle(request, response, callback);
}
+ return false;
}
}
- private static class SleepHandler extends AbstractHandler {
- public void handle(
- final String target,
- final Request request,
- final HttpServletRequest servletRequest,
- final HttpServletResponse servletResponse) throws IOException, ServletException {
-
+ private static class SleepHandler extends Handler.Abstract {
+
+ /** {@inheritDoc} */
+ @Override
+ public boolean handle(Request request, Response response, Callback callback) throws Exception {
int seconds = 10; // default
- String secondsStr = StringSupport.trimOrNull(servletRequest.getParameter("seconds"));
+ String secondsStr = StringSupport.trimOrNull(Request.getParameters(request).getValue("seconds"));
if (secondsStr != null) {
seconds = Integer.parseInt(secondsStr);
}
@@ -277,11 +276,12 @@ public class RequestTimeLimitingHttpClientTest {
throw new ServletException("Error during Thread.sleep()", e);
}
- servletResponse.setContentType("text/plain;charset=utf-8");
- servletResponse.setStatus(200);
- request.setHandled(true);
- servletResponse.getWriter().println(String.format("Ok, I just slept for %d seconds", seconds));
- servletResponse.getWriter().flush();
+ response.getHeaders().add(HttpHeader.CONTENT_TYPE, "text/plain;charset=utf-8");
+ response.setStatus(200);
+ response.write(true,
+ ByteBuffer.wrap(String.format("Ok, I just slept for %d seconds\n", seconds).getBytes(StandardCharsets.UTF_8)),
+ callback);
+ return true;
}
}
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list