Upgraded jetty to jarkarta servlet spec

This commit is contained in:
Willem Cazander 2024-12-14 23:05:34 +01:00
parent 7d217c28d0
commit 4952761c16
8 changed files with 102 additions and 55 deletions

View file

@ -39,7 +39,6 @@ public class WarpCoreReactor implements WarpReact {
} }
public List<WarpReactPlasma> listChilds(WarpReactPlasma slot) { public List<WarpReactPlasma> listChilds(WarpReactPlasma slot) {
Objects.requireNonNull(slot);
List<WarpReactPlasma> result = new ArrayList<>(); List<WarpReactPlasma> result = new ArrayList<>();
synchronized (slots) { synchronized (slots) {
for (WarpReactPlasma slug : slots.keySet()) { for (WarpReactPlasma slug : slots.keySet()) {

View file

@ -21,7 +21,8 @@
</root> </root>
<!-- Package opens. --> <!-- Package opens. -->
<logger level="DEBUG" name="love.distributedrebirth.no2all.react.warp"/> <logger level="DEBUG" name="love.distributedrebirth.nx01.warp.core"/>
<logger level="DEBUG" name="love.distributedrebirth.nx01.zerofungus"/>
<!-- Package limits. --> <!-- Package limits. -->
<logger level="INFO" name="org.eclipse.jetty"/> <logger level="INFO" name="org.eclipse.jetty"/>

View file

@ -5,7 +5,12 @@ import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.logging.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.bridge.SLF4JBridgeHandler;
import ch.qos.logback.core.status.NopStatusListener;
import love.distributedrebirth.nx01.no2all.react.nostr.client.NoStrRtsClient; import love.distributedrebirth.nx01.no2all.react.nostr.client.NoStrRtsClient;
import love.distributedrebirth.nx01.no2all.react.nostr.server.NoStrRtsServer; import love.distributedrebirth.nx01.no2all.react.nostr.server.NoStrRtsServer;
import love.distributedrebirth.nx01.no2all.react.nostr.server.relay.NoStrRtsServerRelay; import love.distributedrebirth.nx01.no2all.react.nostr.server.relay.NoStrRtsServerRelay;
@ -16,7 +21,6 @@ import love.distributedrebirth.nx01.no2all.react.wire.server.No2AllRtsServerLog;
import love.distributedrebirth.nx01.warp.core.WarpCoreReactor; import love.distributedrebirth.nx01.warp.core.WarpCoreReactor;
import love.distributedrebirth.nx01.warp.core.WarpCoreSpeedMonitor; import love.distributedrebirth.nx01.warp.core.WarpCoreSpeedMonitor;
import love.distributedrebirth.nx01.zerofungus.server.service.ZFunRtsConfigJetty; import love.distributedrebirth.nx01.zerofungus.server.service.ZFunRtsConfigJetty;
import love.distributedrebirth.nx01.zerofungus.server.service.ZFunRtsConfigLogger;
import love.distributedrebirth.nx01.zerofungus.server.service.ZFunRtsInitJdbc; import love.distributedrebirth.nx01.zerofungus.server.service.ZFunRtsInitJdbc;
public enum ZeroFungus /* implements BãßBȍőnAbacusInstanceMBeanʸᴰ<ZeroFungus> */ { public enum ZeroFungus /* implements BãßBȍőnAbacusInstanceMBeanʸᴰ<ZeroFungus> */ {
@ -24,6 +28,7 @@ public enum ZeroFungus /* implements BãßBȍőnAbacusInstanceMBeanʸᴰ<ZeroFun
private WarpCoreReactor foei = new WarpCoreReactor(); private WarpCoreReactor foei = new WarpCoreReactor();
private List<ZFunRtsConfigJetty> jetties = new ArrayList<>(); private List<ZFunRtsConfigJetty> jetties = new ArrayList<>();
private static final Logger logger = Logger.getLogger(ZeroFungus.class.getName());
public static void main(String[] args) { public static void main(String[] args) {
Iterator<String> arguments = Arrays.asList(args).iterator(); Iterator<String> arguments = Arrays.asList(args).iterator();
@ -31,6 +36,7 @@ public enum ZeroFungus /* implements BãßBȍőnAbacusInstanceMBeanʸᴰ<ZeroFun
// todo move // todo move
new File("logs").mkdir(); new File("logs").mkdir();
setupLogging();
// config jetty // config jetty
INSTANCE.jetties.clear(); INSTANCE.jetties.clear();
@ -43,14 +49,42 @@ public enum ZeroFungus /* implements BãßBȍőnAbacusInstanceMBeanʸᴰ<ZeroFun
INSTANCE.start(); INSTANCE.start();
} }
public WarpCoreReactor getWarpCore() {
return foei;
}
private static void setupLogging() {
if (System.getProperty("logback.configurationFile") == null) {
String logConfig = null;
if (System.getProperty("java.class.path").contains("classes")) {
logConfig = "conf/logback-server-console.xml";
} else {
logConfig = "conf/logback-server.xml";
}
System.setProperty("logback.configurationFile", logConfig);
}
if (System.getProperty("logback.statusListenerClass") == null) {
System.setProperty("logback.statusListenerClass",NopStatusListener.class.getName());
}
org.slf4j.Logger logger2 = LoggerFactory.getLogger(ZeroFungus.class);
logger2.info("Logging configured.");
SLF4JBridgeHandler.removeHandlersForRootLogger();
SLF4JBridgeHandler.install();
logger.info(" ╦┬ ┬╦ ╦═╗┌─┐╦ ╦┬╦═╗┌─┐╔╦╗");
logger.info(" ║│ │║ ╠╦╝├┤ ║║║│╠╦╝├┤ ║║");
logger.info("╚╝└─┘╩═╝ ╩╚═└─┘╚╩╝┴╩╚═└─┘═╩╝");
//https://patorjk.com/software/taag
// Calvin S
}
public void stop() { public void stop() {
jetties.forEach(v -> v.stop()); jetties.forEach(v -> v.stop());
// foei.fire(No2AllReactWarpCore.DILITHIUM, new EjectWrapCoreShutdown()); // foei.fire(No2AllReactWarpCore.DILITHIUM, new EjectWrapCoreShutdown());
} }
public void start() { public void start() {
// setup logger + warp monitor // debug warp monitor
foei.load(new ZFunRtsConfigLogger());
foei.load(new WarpCoreSpeedMonitor()); foei.load(new WarpCoreSpeedMonitor());
// add websocket wire support + log // add websocket wire support + log

View file

@ -19,6 +19,7 @@ import org.eclipse.jetty.webapp.Configuration;
import org.eclipse.jetty.webapp.WebAppContext; import org.eclipse.jetty.webapp.WebAppContext;
import org.eclipse.jetty.webapp.WebInfConfiguration; import org.eclipse.jetty.webapp.WebInfConfiguration;
import org.eclipse.jetty.websocket.server.config.JettyWebSocketServletContainerInitializer; import org.eclipse.jetty.websocket.server.config.JettyWebSocketServletContainerInitializer;
import org.h2.server.web.JakartaWebServlet;
import love.distributedrebirth.nx01.no2all.react.wire.server.No2AllActServer; import love.distributedrebirth.nx01.no2all.react.wire.server.No2AllActServer;
import love.distributedrebirth.nx01.no2all.react.wire.server.No2AllRtsServer; import love.distributedrebirth.nx01.no2all.react.wire.server.No2AllRtsServer;
@ -29,6 +30,7 @@ import love.distributedrebirth.nx01.warp.core.react.WarpReactPlasmaPulse;
import love.distributedrebirth.nx01.warp.core.react.WarpReactTypeScript; import love.distributedrebirth.nx01.warp.core.react.WarpReactTypeScript;
import love.distributedrebirth.nx01.warp.core.space.WarpSpaceAntimatterInducer; import love.distributedrebirth.nx01.warp.core.space.WarpSpaceAntimatterInducer;
import love.distributedrebirth.nx01.zerofungus.server.web.RedirectServlet; import love.distributedrebirth.nx01.zerofungus.server.web.RedirectServlet;
import love.distributedrebirth.nx01.zerofungus.server.web.WarpCorePlasmaInspectorServlet;
public final class ZFunRtsConfigJetty implements WarpReactTypeScript { public final class ZFunRtsConfigJetty implements WarpReactTypeScript {
@ -70,8 +72,11 @@ public final class ZFunRtsConfigJetty implements WarpReactTypeScript {
}); });
logger.info("Add H2 console on: /debug/jdbc/console"); logger.info("Add H2 console on: /debug/jdbc/console");
// TODO: upgrade jetty, H2 has added "JakartaWebServlet" context.addServlet(JakartaWebServlet.class, "/debug/jdbc/console/*");
context.addServlet("org.h2.server.web.WebServlet", "/debug/jdbc/console/*");
logger.info("Add plasma inspector on: /debug/warpcore/inspector");
context.addServlet(WarpCorePlasmaInspectorServlet.class, "/debug/warpcore/inspector");
context.addServlet(RedirectServlet.class, "/test"); context.addServlet(RedirectServlet.class, "/test");

View file

@ -1,44 +0,0 @@
package love.distributedrebirth.nx01.zerofungus.server.service;
import java.util.logging.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.bridge.SLF4JBridgeHandler;
import ch.qos.logback.core.status.NopStatusListener;
import love.distributedrebirth.nx01.warp.core.react.WarpReactPlasma;
import love.distributedrebirth.nx01.warp.core.react.WarpReactPlasmaPulse;
import love.distributedrebirth.nx01.warp.core.react.WarpReactTypeScript;
import love.distributedrebirth.nx01.warp.core.space.WarpSpaceAntimatterInducer;
public class ZFunRtsConfigLogger implements WarpReactTypeScript {
public static final WarpReactPlasma API = WarpReactPlasma.ofClass(ZFunRtsConfigLogger.class);
private static final Logger logger = Logger.getLogger(ZFunRtsConfigLogger.class.getName());
@Override
public void onEvent(WarpReactPlasmaPulse<WarpSpaceAntimatterInducer> signal) {
if (System.getProperty("logback.configurationFile") == null) {
String logConfig = null;
if (System.getProperty("java.class.path").contains("classes")) {
logConfig = "conf/logback-server-console.xml";
} else {
logConfig = "conf/logback-server.xml";
}
System.setProperty("logback.configurationFile", logConfig);
}
if (System.getProperty("logback.statusListenerClass") == null) {
System.setProperty("logback.statusListenerClass",NopStatusListener.class.getName());
}
org.slf4j.Logger logger2 = LoggerFactory.getLogger(ZFunRtsConfigLogger.class);
logger2.info("Logging configured.");
SLF4JBridgeHandler.removeHandlersForRootLogger();
SLF4JBridgeHandler.install();
logger.info(" ╦┬ ┬╦ ╦═╗┌─┐╦ ╦┬╦═╗┌─┐╔╦╗");
logger.info(" ║│ │║ ╠╦╝├┤ ║║║│╠╦╝├┤ ║║");
logger.info("╚╝└─┘╩═╝ ╩╚═└─┘╚╩╝┴╩╚═└─┘═╩╝");
//https://patorjk.com/software/taag
// Calvin S
}
}

View file

@ -2,9 +2,9 @@ package love.distributedrebirth.nx01.zerofungus.server.web;
import java.io.IOException; import java.io.IOException;
import javax.servlet.http.HttpServlet; import jakarta.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import jakarta.servlet.http.HttpServletResponse;
public class RedirectServlet extends HttpServlet { public class RedirectServlet extends HttpServlet {

View file

@ -0,0 +1,52 @@
package love.distributedrebirth.nx01.zerofungus.server.web;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import love.distributedrebirth.nx01.warp.core.WarpCorePlasmaIntermixChamber;
import love.distributedrebirth.nx01.warp.core.WarpCoreReactor;
import love.distributedrebirth.nx01.warp.core.react.WarpReactPlasma;
import love.distributedrebirth.nx01.zerofungus.server.ZeroFungus;
public class WarpCorePlasmaInspectorServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
response.setContentType("text/xml");
response.setCharacterEncoding("utf-8");
PrintWriter out = response.getWriter();
WarpCoreReactor reactor = ZeroFungus.INSTANCE.getWarpCore();
List<WarpReactPlasma> slots = reactor.listChilds(null);
out.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
out.println("<reactor>\n");
for (WarpReactPlasma slot : slots) {
WarpCorePlasmaIntermixChamber contract = reactor.getSlotContract(slot);
out.println("\t<slot path=\"" + slot.getSlotPath() + "\">\n");
printClaims(out, "in", contract.getSlotTypesIn());
printClaims(out, "out", contract.getSlotTypesOut());
out.println("</slot>\n");
}
out.println("\t</reactor>\n");
out.flush();
}
private void printClaims(PrintWriter out, String tag, List<Class<?>> clazzes) {
if (clazzes.isEmpty()) {
return;
}
out.println("\t\t<claim-"+tag+">\n");
for (Class<?> cls : clazzes) {
out.print("\t\t\t<claim-type>");
out.print(cls);
out.println("</claim-type>\n");
}
out.println("\t\t</claim-"+tag+">\n");
}
}

View file

@ -10,7 +10,7 @@
<properties> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.build.sourceVersion>11</project.build.sourceVersion> <project.build.sourceVersion>11</project.build.sourceVersion>
<jetty.version>10.0.20</jetty.version> <jetty.version>11.0.24</jetty.version>
<metamodel.version>5.3.6</metamodel.version> <metamodel.version>5.3.6</metamodel.version>
<logback.version>1.2.10</logback.version> <logback.version>1.2.10</logback.version>
<slf4j.version>2.0.7</slf4j.version> <slf4j.version>2.0.7</slf4j.version>