Skip to content

Commit 5819e00

Browse files
joewizclaude
andcommitted
[feature] Migrate Java code for Jetty 12 and Servlet 6.0
JettyStart.java: Handler model rewrite, ResourceFactory, ee10 packages WebAppContext.java: extends ee10 WebAppContext HttpServletRequestWrapper.java: Servlet 6.0 additions/removals XQueryURLRewrite.java, HttpServletResponseAdapter.java: removed setStatus(int, String) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 605e43a commit 5819e00

File tree

5 files changed

+65
-82
lines changed

5 files changed

+65
-82
lines changed

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

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -441,11 +441,7 @@ public boolean isRequestedSessionIdFromURL() {
441441
return request.isRequestedSessionIdFromURL();
442442
}
443443

444-
@Override
445-
@Deprecated
446-
public boolean isRequestedSessionIdFromUrl() {
447-
return request.isRequestedSessionIdFromUrl();
448-
}
444+
// isRequestedSessionIdFromUrl() removed in Servlet 6.0
449445

450446
@Override
451447
public boolean authenticate(final HttpServletResponse httpServletResponse) throws IOException, ServletException {
@@ -572,11 +568,7 @@ public RequestDispatcher getRequestDispatcher(final String name) {
572568
return request.getRequestDispatcher(name);
573569
}
574570

575-
@Override
576-
@Deprecated
577-
public String getRealPath(final String path) {
578-
return request.getSession().getServletContext().getRealPath(path);
579-
}
571+
// getRealPath(String) removed in Servlet 6.0 — use ServletContext.getRealPath() instead
580572

581573
@Override
582574
public int getRemotePort() {
@@ -633,6 +625,21 @@ public DispatcherType getDispatcherType() {
633625
return request.getDispatcherType();
634626
}
635627

628+
@Override
629+
public String getRequestId() {
630+
return request.getRequestId();
631+
}
632+
633+
@Override
634+
public String getProtocolRequestId() {
635+
return request.getProtocolRequestId();
636+
}
637+
638+
@Override
639+
public ServletConnection getServletConnection() {
640+
return request.getServletConnection();
641+
}
642+
636643
@Override
637644
public void close() throws IOException {
638645
this.is.close();

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1380,11 +1380,7 @@ public void setStatus(final int i) {
13801380
super.setStatus(i);
13811381
}
13821382

1383-
@Override
1384-
public void setStatus(final int i, final String msg) {
1385-
this.status = i;
1386-
super.setStatus(i, msg);
1387-
}
1383+
// setStatus(int, String) removed in Servlet 6.0
13881384

13891385
@Override
13901386
public void sendError(final int i, final String msg) throws IOException {

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

Lines changed: 41 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,12 @@
2626
import org.apache.logging.log4j.Logger;
2727
import org.eclipse.jetty.server.*;
2828
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;
29+
import org.eclipse.jetty.ee10.servlet.ServletContextHandler;
30+
import org.eclipse.jetty.ee10.servlet.ServletHolder;
3231
import org.eclipse.jetty.util.Jetty;
33-
import org.eclipse.jetty.util.MultiException;
3432
import org.eclipse.jetty.util.component.LifeCycle;
35-
import org.eclipse.jetty.util.resource.PathResource;
3633
import org.eclipse.jetty.util.resource.Resource;
34+
import org.eclipse.jetty.util.resource.ResourceFactory;
3735
import org.eclipse.jetty.xml.XmlConfiguration;
3836
import org.exist.SystemProperties;
3937
import org.exist.http.servlets.ExistExtensionServlet;
@@ -68,7 +66,7 @@
6866
/**
6967
* This class provides a main method to start Jetty with eXist. It registers shutdown
7068
* handlers to cleanly shut down the database and the webserver.
71-
*
69+
*
7270
* @author wolf
7371
*/
7472
public class JettyStart extends Observable implements LifeCycle.Listener {
@@ -149,8 +147,6 @@ public synchronized void run(final boolean standalone) {
149147
return jettyPath;
150148
});
151149

152-
System.setProperty("org.eclipse.jetty.util.log.class", "org.eclipse.jetty.util.log.Slf4jLog");
153-
154150
final Path jettyConfig;
155151
if (standalone) {
156152
jettyConfig = Paths.get(jettyProperty).normalize().resolve("etc").resolve(Main.STANDALONE_ENABLED_JETTY_CONFIGS);
@@ -159,7 +155,7 @@ public synchronized void run(final boolean standalone) {
159155
}
160156
run(new String[] { jettyConfig.toAbsolutePath().toString() }, null);
161157
}
162-
158+
163159
public synchronized void run(final String[] args, final Observer observer) {
164160
if (args.length == 0) {
165161
logger.error("No configuration file specified!");
@@ -261,7 +257,7 @@ public synchronized void run(final String[] args, final Observer observer) {
261257
XmlConfiguration last = null;
262258
for(final Path confFile : configFiles) {
263259
logger.info("[loading jetty configuration : {}]", confFile.toString());
264-
final Resource resource = new PathResource(confFile);
260+
final Resource resource = ResourceFactory.root().newResource(confFile);
265261
final XmlConfiguration configuration = new XmlConfiguration(resource);
266262
if (last != null) {
267263
configuration.getIdMap().putAll(last.getIdMap());
@@ -303,7 +299,7 @@ public synchronized void run(final String[] args, final Observer observer) {
303299
allPorts.append(networkConnector.getLocalPort());
304300
}
305301
}
306-
302+
307303
//*************************************************************
308304
final List<URI> serverUris = getSeverURIs(server);
309305
if(!serverUris.isEmpty()) {
@@ -317,9 +313,9 @@ public synchronized void run(final String[] args, final Observer observer) {
317313
}
318314

319315
logger.info("Configured contexts:");
320-
final LinkedHashSet<Handler> handlers = getAllHandlers(server.getHandler());
316+
final List<Handler> handlers = getAllHandlers(server.getHandler());
321317
for (final Handler handler: handlers) {
322-
318+
323319
if (handler instanceof ContextHandler contextHandler) {
324320
logger.info("{} ({})", contextHandler.getContextPath(), contextHandler.getDisplayName());
325321
}
@@ -348,74 +344,53 @@ public synchronized void run(final String[] args, final Observer observer) {
348344

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

367-
// If it is another error, print stacktrace
368-
if (!hasBindException) {
369-
e.printStackTrace();
370-
}
371-
setChanged();
372-
notifyObservers(SIGNAL_ERROR);
373-
374348
} catch (final SocketException e) {
375349
logger.error("----------------------------------------------------------");
376350
logger.error("ERROR: Could not bind to port because {}", e.getMessage());
377351
logger.error(e.toString());
378352
logger.error("----------------------------------------------------------");
379353
setChanged();
380354
notifyObservers(SIGNAL_ERROR);
381-
355+
382356
} catch (final Exception e) {
383-
e.printStackTrace();
357+
if (e instanceof java.net.BindException) {
358+
logger.error("----------------------------------------------------------");
359+
logger.error("ERROR: Could not bind to port because {}", e.getMessage());
360+
logger.error(e.toString());
361+
logger.error("----------------------------------------------------------");
362+
} else {
363+
e.printStackTrace();
364+
}
384365
setChanged();
385366
notifyObservers(SIGNAL_ERROR);
386367
}
387368
}
388369

389-
private LinkedHashSet<Handler> getAllHandlers(final Handler handler) {
390-
if(handler instanceof HandlerWrapper handlerWrapper) {
391-
final LinkedHashSet<Handler> handlers = new LinkedHashSet<>();
392-
handlers.add(handlerWrapper);
393-
if(handlerWrapper.getHandler() != null) {
394-
handlers.addAll(getAllHandlers(handlerWrapper.getHandler()));
395-
}
396-
return handlers;
370+
private List<Handler> getAllHandlers(final Handler handler) {
371+
final List<Handler> handlers = new ArrayList<>();
372+
handlers.add(handler);
397373

398-
} else if(handler instanceof HandlerContainer handlerContainer) {
399-
final LinkedHashSet<Handler> handlers = new LinkedHashSet<>();
400-
handlers.add(handler);
401-
for(final Handler childHandler : handlerContainer.getChildHandlers()) {
374+
if (handler instanceof Handler.Wrapper wrapper) {
375+
if (wrapper.getHandler() != null) {
376+
handlers.addAll(getAllHandlers(wrapper.getHandler()));
377+
}
378+
} else if (handler instanceof Handler.Container container) {
379+
for (final Handler childHandler : container.getHandlers()) {
402380
handlers.addAll(getAllHandlers(childHandler));
403381
}
404-
return handlers;
405-
406-
} else {
407-
//assuming just Handler
408-
final LinkedHashSet<Handler> handlers = new LinkedHashSet<>();
409-
handlers.add(handler);
410-
return handlers;
411382
}
383+
384+
return handlers;
412385
}
413386

414387
/**
415388
* See {@link Server#getURI()}
416389
*/
417390
private List<URI> getSeverURIs(final Server server) {
418-
final ContextHandler context = server.getChildHandlerByClass(ContextHandler.class);
391+
final ContextHandler context = server.getHandler() instanceof Handler.Container container
392+
? container.getDescendant(ContextHandler.class)
393+
: null;
419394
return Arrays.stream(server.getConnectors())
420395
.filter(connector -> connector instanceof NetworkConnector)
421396
.map(connector -> (NetworkConnector)connector)
@@ -438,9 +413,13 @@ private URI getURI(final NetworkConnector networkConnector, final ContextHandler
438413
}
439414

440415
String host = null;
441-
if (context != null && context.getVirtualHosts() != null && context.getVirtualHosts().length > 0) {
442-
host = context.getVirtualHosts()[0];
443-
} else {
416+
if (context != null) {
417+
final List<String> virtualHosts = context.getVirtualHosts();
418+
if (virtualHosts != null && !virtualHosts.isEmpty()) {
419+
host = virtualHosts.getFirst();
420+
}
421+
}
422+
if (host == null) {
444423
host = networkConnector.getHost();
445424
}
446425

@@ -562,9 +541,9 @@ public synchronized void shutdown() {
562541
logger.warn("Unable to remove BrokerPoolsAndJetty.ShutdownHook hook: {}", e.getMessage());
563542
}
564543
});
565-
544+
566545
BrokerPool.stopAll(false);
567-
546+
568547
while (status != STATUS_STOPPED) {
569548
try {
570549
wait();

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,17 @@
2727
* @author <a href="mailto:shabanovd@gmail.com">Dmitriy Shabanov</a>
2828
*
2929
*/
30-
public class WebAppContext extends org.eclipse.jetty.webapp.WebAppContext {
31-
30+
public class WebAppContext extends org.eclipse.jetty.ee10.webapp.WebAppContext {
31+
3232
@Override
3333
public String toString() {
3434
return "eXist-db Open Source Native XML Database";
3535
}
36-
36+
3737
@Override
3838
protected void doStop() throws Exception {
3939
super.doStop();
40-
40+
4141
BrokerPool.stopAll(true);
4242
}
4343

extensions/exquery/restxq/src/main/java/org/exist/extensions/exquery/restxq/impl/adapters/HttpServletResponseAdapter.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ public void setHeader(final String name, final String value) {
5151

5252
@Override
5353
public void setStatus(final HttpStatus status, final String reason) {
54-
response.setStatus(status.getStatus(), reason);
54+
// setStatus(int, String) removed in Servlet 6.0; reason phrase ignored
55+
response.setStatus(status.getStatus());
5556
}
5657

5758
@Override

0 commit comments

Comments
 (0)