aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.junit.http/src
diff options
context:
space:
mode:
authorDavid Ostrovsky <david@ostrovsky.org>2024-05-05 10:56:32 +0200
committerMatthias Sohn <matthias.sohn@sap.com>2024-05-08 02:47:05 +0200
commit026d46de13eb2321c18045469f27b065ba107ff5 (patch)
tree7b81ca681d8ea1e7818aa8da313f510440dd1626 /org.eclipse.jgit.junit.http/src
parenta31580f459b0ae24b51c519ce71ad728ff156c8f (diff)
downloadjgit-026d46de13eb2321c18045469f27b065ba107ff5.tar.gz
jgit-026d46de13eb2321c18045469f27b065ba107ff5.zip
Bump jetty version to 12.0.9 and servlet-api to 6.0next
Bug: jgit-41 Change-Id: Ib3e42581db2dd88043a1a67d606795501b8019f4
Diffstat (limited to 'org.eclipse.jgit.junit.http/src')
-rw-r--r--org.eclipse.jgit.junit.http/src/org/eclipse/jgit/junit/http/AccessEvent.java46
-rw-r--r--org.eclipse.jgit.junit.http/src/org/eclipse/jgit/junit/http/AppServer.java18
-rw-r--r--org.eclipse.jgit.junit.http/src/org/eclipse/jgit/junit/http/HttpTestCase.java3
-rw-r--r--org.eclipse.jgit.junit.http/src/org/eclipse/jgit/junit/http/SimpleHttpServer.java4
-rw-r--r--org.eclipse.jgit.junit.http/src/org/eclipse/jgit/junit/http/TestRequestLog.java48
5 files changed, 57 insertions, 62 deletions
diff --git a/org.eclipse.jgit.junit.http/src/org/eclipse/jgit/junit/http/AccessEvent.java b/org.eclipse.jgit.junit.http/src/org/eclipse/jgit/junit/http/AccessEvent.java
index 3d4f379243..36da539e8d 100644
--- a/org.eclipse.jgit.junit.http/src/org/eclipse/jgit/junit/http/AccessEvent.java
+++ b/org.eclipse.jgit.junit.http/src/org/eclipse/jgit/junit/http/AccessEvent.java
@@ -11,12 +11,14 @@
package org.eclipse.jgit.junit.http;
import java.util.Collections;
-import java.util.Enumeration;
import java.util.Map;
import java.util.TreeMap;
+import org.eclipse.jetty.http.HttpField;
+import org.eclipse.jetty.http.HttpURI;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.Response;
+import org.eclipse.jetty.util.Fields;
/**
* A single request made through {@link org.eclipse.jgit.junit.http.AppServer}.
@@ -24,7 +26,7 @@ import org.eclipse.jetty.server.Response;
public class AccessEvent {
private final String method;
- private final String uri;
+ private final HttpURI uri;
private final Map<String, String> requestHeaders;
@@ -36,9 +38,9 @@ public class AccessEvent {
AccessEvent(Request req) {
method = req.getMethod();
- uri = req.getRequestURI();
+ uri = req.getHttpURI();
requestHeaders = cloneHeaders(req);
- parameters = clone(req.getParameterMap());
+ parameters = cloneParameters(req);
}
void setResponse(Response rsp) {
@@ -48,11 +50,10 @@ public class AccessEvent {
private static Map<String, String> cloneHeaders(Request req) {
Map<String, String> r = new TreeMap<>();
- Enumeration hn = req.getHeaderNames();
- while (hn.hasMoreElements()) {
- String key = (String) hn.nextElement();
+ for (HttpField f : req.getHeaders()) {
+ String key = f.getName();
if (!r.containsKey(key)) {
- r.put(key, req.getHeader(key));
+ r.put(key, f.getValue());
}
}
return Collections.unmodifiableMap(r);
@@ -60,20 +61,29 @@ public class AccessEvent {
private static Map<String, String> cloneHeaders(Response rsp) {
Map<String, String> r = new TreeMap<>();
- Enumeration<String> hn = rsp.getHttpFields().getFieldNames();
- while (hn.hasMoreElements()) {
- String key = hn.nextElement();
+ for (HttpField f : rsp.getHeaders()) {
+ String key = f.getName();
if (!r.containsKey(key)) {
- Enumeration<String> v = rsp.getHttpFields().getValues(key);
- r.put(key, v.nextElement());
+ r.put(key, f.getValue());
}
}
return Collections.unmodifiableMap(r);
}
- @SuppressWarnings("unchecked")
- private static Map<String, String[]> clone(Map parameterMap) {
- return new TreeMap<>(parameterMap);
+ private static Map<String, String[]> cloneParameters(Request req) {
+ Map<String, String[]> r = new TreeMap<>();
+
+ Fields fields;
+ try {
+ fields = Request.getParameters(req);
+ for (String n : fields.getNames()) {
+ r.put(n, fields.getValues(n).toArray(new String[0]));
+ }
+ } catch (Exception e) {
+ throw new RuntimeException("Failed to extract request parameters",
+ e);
+ }
+ return r;
}
/**
@@ -91,7 +101,7 @@ public class AccessEvent {
* @return path of the file on the server, e.g. {@code /git/HEAD}.
*/
public String getPath() {
- return uri;
+ return uri.getPath();
}
/**
@@ -151,7 +161,7 @@ public class AccessEvent {
StringBuilder b = new StringBuilder();
b.append(method);
b.append(' ');
- b.append(uri);
+ b.append(uri.getPath());
if (!parameters.isEmpty()) {
b.append('?');
boolean first = true;
diff --git a/org.eclipse.jgit.junit.http/src/org/eclipse/jgit/junit/http/AppServer.java b/org.eclipse.jgit.junit.http/src/org/eclipse/jgit/junit/http/AppServer.java
index de4535ab52..76e437bc3d 100644
--- a/org.eclipse.jgit.junit.http/src/org/eclipse/jgit/junit/http/AppServer.java
+++ b/org.eclipse.jgit.junit.http/src/org/eclipse/jgit/junit/http/AppServer.java
@@ -27,10 +27,12 @@ import java.util.Locale;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
+import org.eclipse.jetty.ee10.servlet.ServletContextHandler;
+import org.eclipse.jetty.ee10.servlet.security.ConstraintMapping;
+import org.eclipse.jetty.ee10.servlet.security.ConstraintSecurityHandler;
import org.eclipse.jetty.security.AbstractLoginService;
import org.eclipse.jetty.security.Authenticator;
-import org.eclipse.jetty.security.ConstraintMapping;
-import org.eclipse.jetty.security.ConstraintSecurityHandler;
+import org.eclipse.jetty.security.Constraint;
import org.eclipse.jetty.security.RolePrincipal;
import org.eclipse.jetty.security.UserPrincipal;
import org.eclipse.jetty.security.authentication.BasicAuthenticator;
@@ -42,8 +44,6 @@ import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector;
import org.eclipse.jetty.server.SslConnectionFactory;
import org.eclipse.jetty.server.handler.ContextHandlerCollection;
-import org.eclipse.jetty.servlet.ServletContextHandler;
-import org.eclipse.jetty.util.security.Constraint;
import org.eclipse.jetty.util.security.Password;
import org.eclipse.jetty.util.ssl.SslContextFactory;
import org.eclipse.jgit.transport.URIish;
@@ -243,6 +243,7 @@ public class AppServer {
* path of the context; use "/" for the root context if binding
* to the root is desired.
* @return the context to add servlets into.
+ * @since 7.0
*/
public ServletContextHandler addContext(String path) {
assertNotYetSetUp();
@@ -264,6 +265,7 @@ public class AppServer {
* @param methods
* the methods
* @return servlet context handler
+ * @since 7.0
*/
public ServletContextHandler authBasic(ServletContextHandler ctx,
String... methods) {
@@ -305,10 +307,10 @@ public class AppServer {
private ConstraintMapping createConstraintMapping() {
ConstraintMapping cm = new ConstraintMapping();
- cm.setConstraint(new Constraint());
- cm.getConstraint().setAuthenticate(true);
- cm.getConstraint().setDataConstraint(Constraint.DC_NONE);
- cm.getConstraint().setRoles(new String[] { authRole });
+ Constraint constraint = new Constraint.Builder()
+ .authorization(Constraint.Authorization.SPECIFIC_ROLE)
+ .roles(new String[] { authRole }).build();
+ cm.setConstraint(constraint);
cm.setPathSpec("/*");
return cm;
}
diff --git a/org.eclipse.jgit.junit.http/src/org/eclipse/jgit/junit/http/HttpTestCase.java b/org.eclipse.jgit.junit.http/src/org/eclipse/jgit/junit/http/HttpTestCase.java
index 8a4d363709..f399471b39 100644
--- a/org.eclipse.jgit.junit.http/src/org/eclipse/jgit/junit/http/HttpTestCase.java
+++ b/org.eclipse.jgit.junit.http/src/org/eclipse/jgit/junit/http/HttpTestCase.java
@@ -21,7 +21,7 @@ import java.util.HashSet;
import java.util.List;
import java.util.Set;
-import org.eclipse.jetty.servlet.ServletContextHandler;
+import org.eclipse.jetty.ee10.servlet.ServletContextHandler;
import org.eclipse.jgit.internal.storage.file.FileRepository;
import org.eclipse.jgit.junit.LocalDiskRepositoryTestCase;
import org.eclipse.jgit.junit.TestRepository;
@@ -109,6 +109,7 @@ public abstract class HttpTestCase extends LocalDiskRepositoryTestCase {
* @return the warnings (if any) from the last execution
* @throws URISyntaxException
* if URI is invalid
+ * @since 7.0
*/
protected URIish toURIish(ServletContextHandler app, String name)
throws URISyntaxException {
diff --git a/org.eclipse.jgit.junit.http/src/org/eclipse/jgit/junit/http/SimpleHttpServer.java b/org.eclipse.jgit.junit.http/src/org/eclipse/jgit/junit/http/SimpleHttpServer.java
index 790a6eb657..bce41383d1 100644
--- a/org.eclipse.jgit.junit.http/src/org/eclipse/jgit/junit/http/SimpleHttpServer.java
+++ b/org.eclipse.jgit.junit.http/src/org/eclipse/jgit/junit/http/SimpleHttpServer.java
@@ -15,8 +15,8 @@ import java.net.URISyntaxException;
import jakarta.servlet.http.HttpServletRequest;
-import org.eclipse.jetty.servlet.ServletContextHandler;
-import org.eclipse.jetty.servlet.ServletHolder;
+import org.eclipse.jetty.ee10.servlet.ServletContextHandler;
+import org.eclipse.jetty.ee10.servlet.ServletHolder;
import org.eclipse.jgit.errors.RepositoryNotFoundException;
import org.eclipse.jgit.http.server.GitServlet;
import org.eclipse.jgit.lib.Repository;
diff --git a/org.eclipse.jgit.junit.http/src/org/eclipse/jgit/junit/http/TestRequestLog.java b/org.eclipse.jgit.junit.http/src/org/eclipse/jgit/junit/http/TestRequestLog.java
index 799decafa6..7a71951dbd 100644
--- a/org.eclipse.jgit.junit.http/src/org/eclipse/jgit/junit/http/TestRequestLog.java
+++ b/org.eclipse.jgit.junit.http/src/org/eclipse/jgit/junit/http/TestRequestLog.java
@@ -10,25 +10,22 @@
package org.eclipse.jgit.junit.http;
-import java.io.IOException;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
import java.util.concurrent.Semaphore;
-import jakarta.servlet.DispatcherType;
-import jakarta.servlet.ServletException;
-import jakarta.servlet.http.HttpServletRequest;
-import jakarta.servlet.http.HttpServletResponse;
-
+import org.eclipse.jetty.server.Handler.Wrapper;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.Response;
-import org.eclipse.jetty.server.handler.HandlerWrapper;
+import org.eclipse.jetty.util.Callback;
/** Logs request made through {@link AppServer}. */
-class TestRequestLog extends HandlerWrapper {
+class TestRequestLog extends Wrapper {
private static final int MAX = 16;
- private final List<AccessEvent> events = new ArrayList<>();
+ private final List<AccessEvent> events = Collections
+ .synchronizedList(new ArrayList<>());
private final Semaphore active = new Semaphore(MAX, true);
@@ -43,10 +40,7 @@ class TestRequestLog extends HandlerWrapper {
continue;
}
}
-
- synchronized (events) {
- events.clear();
- }
+ events.clear();
} finally {
active.release(MAX);
}
@@ -63,19 +57,15 @@ class TestRequestLog extends HandlerWrapper {
continue;
}
}
-
- synchronized (events) {
- return events;
- }
+ return Collections.unmodifiableList(new ArrayList<>(events));
} finally {
active.release(MAX);
}
}
@Override
- public void handle(String target, Request baseRequest,
- HttpServletRequest request, HttpServletResponse response)
- throws IOException, ServletException {
+ public boolean handle(Request request, Response response, Callback callback)
+ throws Exception {
try {
for (;;) {
try {
@@ -86,21 +76,13 @@ class TestRequestLog extends HandlerWrapper {
}
}
- AccessEvent event = null;
- if (DispatcherType.REQUEST
- .equals(baseRequest.getDispatcherType())) {
- event = new AccessEvent((Request) request);
- synchronized (events) {
- events.add(event);
- }
- }
+ AccessEvent event = new AccessEvent(request);
+ events.add(event);
- super.handle(target, baseRequest, request, response);
-
- if (event != null) {
- event.setResponse((Response) response);
- }
+ boolean result = super.handle(request, response, callback);
+ event.setResponse(response);
+ return result;
} finally {
active.release();
}