Skip to content

Commit c4d1217

Browse files
committed
[feature] Update from Jetty 11 to Jetty 12
1 parent adaa276 commit c4d1217

48 files changed

Lines changed: 944 additions & 534 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

exist-core/pom.xml

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -430,19 +430,6 @@
430430
<version>${aspectj.version}</version>
431431
</dependency>
432432

433-
<dependency>
434-
<groupId>org.eclipse.jetty</groupId>
435-
<artifactId>jetty-jaas</artifactId>
436-
<version>${jetty.version}</version>
437-
<scope>runtime</scope>
438-
<exclusions>
439-
<exclusion>
440-
<!-- conflicts with antlr 2.7.7 -->
441-
<groupId>org.apache.servicemix.bundles</groupId>
442-
<artifactId>org.apache.servicemix.bundles.antlr</artifactId>
443-
</exclusion>
444-
</exclusions>
445-
</dependency>
446433
<dependency>
447434
<groupId>org.eclipse.jetty</groupId>
448435
<artifactId>jetty-http</artifactId>
@@ -628,16 +615,16 @@
628615
removed. Unfortunately, at this time, it is required for
629616
Monex's Remote Console to function.
630617
-->
631-
<groupId>org.eclipse.jetty</groupId>
632-
<artifactId>jetty-annotations</artifactId>
618+
<groupId>org.eclipse.jetty.ee10</groupId>
619+
<artifactId>jetty-ee10-annotations</artifactId>
633620
</dependency>
634621
<dependency>
635-
<groupId>org.eclipse.jetty</groupId>
636-
<artifactId>jetty-servlet</artifactId>
622+
<groupId>org.eclipse.jetty.ee10</groupId>
623+
<artifactId>jetty-ee10-servlet</artifactId>
637624
</dependency>
638625
<dependency>
639-
<groupId>org.eclipse.jetty</groupId>
640-
<artifactId>jetty-webapp</artifactId>
626+
<groupId>org.eclipse.jetty.ee10</groupId>
627+
<artifactId>jetty-ee10-webapp</artifactId>
641628
</dependency>
642629
<dependency>
643630
<groupId>org.eclipse.jetty</groupId>
@@ -1039,10 +1026,9 @@ The BaseX Team. The original license statement is also included below.]]></pream
10391026
<ignoredUnusedDeclaredDependency>org.xmlresolver:xmlresolver:jar:${xmlresolver.version}</ignoredUnusedDeclaredDependency>
10401027
<ignoredUnusedDeclaredDependency>org.exist-db.thirdparty.org.eclipse.wst.xml:xpath2:jar:1.2.0</ignoredUnusedDeclaredDependency>
10411028
<ignoredUnusedDeclaredDependency>edu.princeton.cup:java-cup:jar:10k</ignoredUnusedDeclaredDependency>
1042-
<ignoredUnusedDeclaredDependency>org.eclipse.jetty:jetty-jaas:jar:${jetty.version}</ignoredUnusedDeclaredDependency>
10431029
<ignoredUnusedDeclaredDependency>org.eclipse.jetty:jetty-deploy:jar:${jetty.version}</ignoredUnusedDeclaredDependency>
10441030
<ignoredUnusedDeclaredDependency>org.eclipse.jetty:jetty-jmx:jar:${jetty.version}</ignoredUnusedDeclaredDependency>
1045-
<ignoredUnusedDeclaredDependency>org.eclipse.jetty:jetty-annotations:jar:${jetty.version}</ignoredUnusedDeclaredDependency>
1031+
<ignoredUnusedDeclaredDependency>org.eclipse.jetty:jetty-ee10-annotations:jar:${jetty.version}</ignoredUnusedDeclaredDependency>
10461032
<ignoredUnusedDeclaredDependency>org.eclipse.jetty:jetty-security:jar:${jetty.version}</ignoredUnusedDeclaredDependency>
10471033
<ignoredUnusedDeclaredDependency>${project.groupId}:exist-jetty-config:jar:${project.version}</ignoredUnusedDeclaredDependency>
10481034
</ignoredUnusedDeclaredDependencies>

exist-core/src/main/java/org/exist/http/servlets/HttpServletRequestWrapper.java

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
11
/*
2+
* Copyright (C) 2014 Evolved Binary Ltd
3+
*
4+
* Changes made by Evolved Binary are proprietary and are not Open Source.
5+
*
6+
* NOTE: Parts of this file contain code from The eXist-db Authors.
7+
* The original license header is included below.
8+
*
9+
* ----------------------------------------------------------------------------
10+
*
211
* eXist-db Open Source Native XML Database
312
* Copyright (C) 2001 The eXist-db Authors
413
*
@@ -441,12 +450,6 @@ public boolean isRequestedSessionIdFromURL() {
441450
return request.isRequestedSessionIdFromURL();
442451
}
443452

444-
@Override
445-
@Deprecated
446-
public boolean isRequestedSessionIdFromUrl() {
447-
return request.isRequestedSessionIdFromUrl();
448-
}
449-
450453
@Override
451454
public boolean authenticate(final HttpServletResponse httpServletResponse) throws IOException, ServletException {
452455
return request.authenticate(httpServletResponse);
@@ -572,12 +575,6 @@ public RequestDispatcher getRequestDispatcher(final String name) {
572575
return request.getRequestDispatcher(name);
573576
}
574577

575-
@Override
576-
@Deprecated
577-
public String getRealPath(final String path) {
578-
return request.getSession().getServletContext().getRealPath(path);
579-
}
580-
581578
@Override
582579
public int getRemotePort() {
583580
return request.getRemotePort();
@@ -639,6 +636,21 @@ public void close() throws IOException {
639636
this.cache.close();
640637
}
641638

639+
@Override
640+
public String getProtocolRequestId() {
641+
return request.getProtocolRequestId();
642+
}
643+
644+
@Override
645+
public String getRequestId() {
646+
return request.getRequestId();
647+
}
648+
649+
@Override
650+
public ServletConnection getServletConnection() {
651+
return request.getServletConnection();
652+
}
653+
642654
private static class ServletInputStreamWrapper extends ServletInputStream {
643655
private final CachingFilterInputStream is;
644656

exist-core/src/main/java/org/exist/http/urlrewrite/XQueryURLRewrite.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
11
/*
2+
* Copyright (C) 2014 Evolved Binary Ltd
3+
*
4+
* Changes made by Evolved Binary are proprietary and are not Open Source.
5+
*
6+
* NOTE: Parts of this file contain code from The eXist-db Authors.
7+
* The original license header is included below.
8+
*
9+
* ----------------------------------------------------------------------------
10+
*
211
* eXist-db Open Source Native XML Database
312
* Copyright (C) 2001 The eXist-db Authors
413
*
@@ -1381,12 +1390,6 @@ public void setStatus(final int i) {
13811390
super.setStatus(i);
13821391
}
13831392

1384-
@Override
1385-
public void setStatus(final int i, final String msg) {
1386-
this.status = i;
1387-
super.setStatus(i, msg);
1388-
}
1389-
13901393
@Override
13911394
public void sendError(final int i, final String msg) throws IOException {
13921395
this.status = i;

exist-core/src/main/java/org/exist/jetty/JettyStart.java

Lines changed: 39 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
11
/*
2+
* Copyright (C) 2014 Evolved Binary Ltd
3+
*
4+
* Changes made by Evolved Binary are proprietary and are not Open Source.
5+
*
6+
* NOTE: Parts of this file contain code from The eXist-db Authors.
7+
* The original license header is included below.
8+
*
9+
* ----------------------------------------------------------------------------
10+
*
211
* eXist-db Open Source Native XML Database
312
* Copyright (C) 2001 The eXist-db Authors
413
*
@@ -26,14 +35,12 @@
2635
import org.apache.logging.log4j.Logger;
2736
import org.eclipse.jetty.server.*;
2837
import org.eclipse.jetty.server.handler.ContextHandler;
29-
import org.eclipse.jetty.server.handler.HandlerWrapper;
30-
import org.eclipse.jetty.servlet.ServletContextHandler;
31-
import org.eclipse.jetty.servlet.ServletHolder;
38+
import org.eclipse.jetty.ee10.servlet.ServletContextHandler;
39+
import org.eclipse.jetty.ee10.servlet.ServletHolder;
3240
import org.eclipse.jetty.util.Jetty;
33-
import org.eclipse.jetty.util.MultiException;
3441
import org.eclipse.jetty.util.component.LifeCycle;
35-
import org.eclipse.jetty.util.resource.PathResource;
3642
import org.eclipse.jetty.util.resource.Resource;
43+
import org.eclipse.jetty.util.resource.ResourceFactory;
3744
import org.eclipse.jetty.xml.XmlConfiguration;
3845
import org.exist.SystemProperties;
3946
import org.exist.http.servlets.ExistExtensionServlet;
@@ -254,14 +261,14 @@ public synchronized void run(final String[] args, final Observer observer) {
254261
return;
255262
}
256263

257-
try {
264+
try (final ResourceFactory.Closeable resourceFactory = ResourceFactory.closeable()) {
258265
// load jetty configurations
259266
final List<Path> configFiles = getEnabledConfigFiles(jettyConfig);
260267
final List<Object> configuredObjects = new ArrayList<>();
261268
XmlConfiguration last = null;
262269
for(final Path confFile : configFiles) {
263270
logger.info("[loading jetty configuration : {}]", confFile.toString());
264-
final Resource resource = new PathResource(confFile);
271+
final Resource resource = resourceFactory.newResource(confFile);
265272
final XmlConfiguration configuration = new XmlConfiguration(resource);
266273
if (last != null) {
267274
configuration.getIdMap().putAll(last.getIdMap());
@@ -305,23 +312,14 @@ public synchronized void run(final String[] args, final Observer observer) {
305312
}
306313

307314
//*************************************************************
308-
final List<URI> serverUris = getSeverURIs(server);
309-
if(!serverUris.isEmpty()) {
310-
this.primaryPort = serverUris.get(0).getPort();
311-
312-
}
313-
logger.info("-----------------------------------------------------");
314-
logger.info("Server has started, listening on:");
315-
for(final URI serverUri : serverUris) {
316-
logger.info("{}", serverUri.resolve("/"));
317-
}
318-
315+
final List<URI> serverUris = new ArrayList<>();
319316
logger.info("Configured contexts:");
320317
final LinkedHashSet<Handler> handlers = getAllHandlers(server.getHandler());
321318
for (final Handler handler: handlers) {
322319

323320
if (handler instanceof ContextHandler) {
324321
final ContextHandler contextHandler = (ContextHandler) handler;
322+
serverUris.addAll(getSeverURIs(contextHandler));
325323
logger.info("{} ({})", contextHandler.getContextPath(), contextHandler.getDisplayName());
326324
}
327325

@@ -346,33 +344,21 @@ public synchronized void run(final String[] args, final Observer observer) {
346344
}
347345
}
348346

347+
if (!serverUris.isEmpty()) {
348+
this.primaryPort = serverUris.get(0).getPort();
349+
350+
}
351+
logger.info("-----------------------------------------------------");
352+
logger.info("Server has started, listening on:");
353+
for (final URI serverUri : serverUris) {
354+
logger.info("{}", serverUri.resolve("/"));
355+
}
356+
349357
logger.info("-----------------------------------------------------");
350358

351359
setChanged();
352360
notifyObservers(SIGNAL_STARTED);
353-
354-
} catch (final MultiException e) {
355-
356-
// Mute the BindExceptions
357-
358-
boolean hasBindException = false;
359-
for (final Throwable t : e.getThrowables()) {
360-
if (t instanceof java.net.BindException) {
361-
hasBindException = true;
362-
logger.error("----------------------------------------------------------");
363-
logger.error("ERROR: Could not bind to port because {}", t.getMessage());
364-
logger.error(t.toString());
365-
logger.error("----------------------------------------------------------");
366-
}
367-
}
368361

369-
// If it is another error, print stacktrace
370-
if (!hasBindException) {
371-
e.printStackTrace();
372-
}
373-
setChanged();
374-
notifyObservers(SIGNAL_ERROR);
375-
376362
} catch (final SocketException e) {
377363
logger.error("----------------------------------------------------------");
378364
logger.error("ERROR: Could not bind to port because {}", e.getMessage());
@@ -389,36 +375,25 @@ public synchronized void run(final String[] args, final Observer observer) {
389375
}
390376

391377
private LinkedHashSet<Handler> getAllHandlers(final Handler handler) {
392-
if(handler instanceof HandlerWrapper handlerWrapper) {
393-
final LinkedHashSet<Handler> handlers = new LinkedHashSet<>();
394-
handlers.add(handlerWrapper);
395-
if(handlerWrapper.getHandler() != null) {
396-
handlers.addAll(getAllHandlers(handlerWrapper.getHandler()));
397-
}
398-
return handlers;
399-
400-
} else if(handler instanceof HandlerContainer handlerContainer) {
401-
final LinkedHashSet<Handler> handlers = new LinkedHashSet<>();
402-
handlers.add(handler);
403-
for(final Handler childHandler : handlerContainer.getChildHandlers()) {
404-
handlers.addAll(getAllHandlers(childHandler));
405-
}
406-
return handlers;
407-
378+
final LinkedHashSet<Handler> handlersCollector = new LinkedHashSet<>();
379+
if (handler instanceof Handler.Wrapper handlerWrapper) {
380+
handlersCollector.add(handlerWrapper);
381+
handlersCollector.addAll(handlerWrapper.getDescendants());
382+
} else if (handler instanceof Handler.Container handlerContainer) {
383+
handlersCollector.add(handler);
384+
handlersCollector.addAll(handlerContainer.getDescendants());
408385
} else {
409386
//assuming just Handler
410-
final LinkedHashSet<Handler> handlers = new LinkedHashSet<>();
411-
handlers.add(handler);
412-
return handlers;
387+
handlersCollector.add(handler);
413388
}
389+
return handlersCollector;
414390
}
415391

416392
/**
417393
* See {@link Server#getURI()}
418394
*/
419-
private List<URI> getSeverURIs(final Server server) {
420-
final ContextHandler context = server.getChildHandlerByClass(ContextHandler.class);
421-
return Arrays.stream(server.getConnectors())
395+
private List<URI> getSeverURIs(final ContextHandler context) {
396+
return Arrays.stream(context.getServer().getConnectors())
422397
.filter(connector -> connector instanceof NetworkConnector)
423398
.map(connector -> (NetworkConnector)connector)
424399
.map(networkConnector -> getURI(networkConnector, context))
@@ -440,8 +415,8 @@ private URI getURI(final NetworkConnector networkConnector, final ContextHandler
440415
}
441416

442417
String host = null;
443-
if (context != null && context.getVirtualHosts() != null && context.getVirtualHosts().length > 0) {
444-
host = context.getVirtualHosts()[0];
418+
if (context != null && context.getVirtualHosts() != null && !context.getVirtualHosts().isEmpty()) {
419+
host = context.getVirtualHosts().get(0);
445420
} else {
446421
host = networkConnector.getHost();
447422
}

exist-core/src/main/java/org/exist/jetty/WebAppContext.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
11
/*
2+
* Copyright (C) 2014 Evolved Binary Ltd
3+
*
4+
* Changes made by Evolved Binary are proprietary and are not Open Source.
5+
*
6+
* NOTE: Parts of this file contain code from The eXist-db Authors.
7+
* The original license header is included below.
8+
*
9+
* ----------------------------------------------------------------------------
10+
*
211
* eXist-db Open Source Native XML Database
312
* Copyright (C) 2001 The eXist-db Authors
413
*
@@ -27,7 +36,7 @@
2736
* @author <a href="mailto:shabanovd@gmail.com">Dmitriy Shabanov</a>
2837
*
2938
*/
30-
public class WebAppContext extends org.eclipse.jetty.webapp.WebAppContext {
39+
public class WebAppContext extends org.eclipse.jetty.ee10.webapp.WebAppContext {
3140

3241
@Override
3342
public String toString() {

exist-core/src/test/java/org/exist/xquery/functions/xmldb/DbStoreTest2.java

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
11
/*
2+
* Copyright (C) 2014 Evolved Binary Ltd
3+
*
4+
* Changes made by Evolved Binary are proprietary and are not Open Source.
5+
*
6+
* NOTE: Parts of this file contain code from The eXist-db Authors.
7+
* The original license header is included below.
8+
*
9+
* ----------------------------------------------------------------------------
10+
*
211
* eXist-db Open Source Native XML Database
312
* Copyright (C) 2001 The eXist-db Authors
413
*
@@ -25,8 +34,8 @@
2534
import org.eclipse.jetty.server.Handler;
2635
import org.eclipse.jetty.server.Server;
2736
import org.eclipse.jetty.server.handler.DefaultHandler;
28-
import org.eclipse.jetty.server.handler.HandlerList;
2937
import org.eclipse.jetty.server.handler.ResourceHandler;
38+
import org.eclipse.jetty.util.resource.ResourceFactory;
3039
import org.exist.test.ExistXmldbEmbeddedServer;
3140
import org.exist.xmldb.concurrent.DBUtils;
3241
import org.junit.*;
@@ -93,16 +102,14 @@ public static void beforeClass() throws Exception {
93102

94103
jettyServer = new Server(jettyPort);
95104
final ResourceHandler resource_handler = new ResourceHandler();
96-
resource_handler.setDirectoriesListed(true);
97-
final String dir = jettyRootDir.toAbsolutePath().toFile().getCanonicalPath();
98-
resource_handler.setResourceBase(dir);
99-
100-
final HandlerList handlers = new HandlerList();
101-
handlers.setHandlers(new Handler[]{resource_handler, new DefaultHandler()});
102-
103-
jettyServer.setHandler(handlers);
104-
jettyServer.start();
105+
resource_handler.setDirAllowed(true);
106+
try (final ResourceFactory.Closeable resourceFactory = ResourceFactory.closeable()) {
107+
resource_handler.setBaseResource(resourceFactory.newResource(jettyRootDir));
108+
final Handler.Sequence handlers = new Handler.Sequence(resource_handler, new DefaultHandler());
105109

110+
jettyServer.setHandler(handlers);
111+
jettyServer.start();
112+
}
106113
}
107114

108115
@AfterClass

0 commit comments

Comments
 (0)