From e2ded94f91aa45bc97ed39c0951a321d156367f7 Mon Sep 17 00:00:00 2001 From: Willem Date: Thu, 19 Dec 2024 19:31:20 +0100 Subject: [PATCH] Added ZilLaLa servlet filter --- .../report/ReportSitraFaultWarpVersion.java | 4 +- .../server/service/ZFunRtsConfigJetty.java | 7 +- .../web/WarpCorePlasmaInspectorServlet.java | 71 ++++++++------- .../server/web/ZilLaLaFaultFilter.java | 89 +++++++++++++++++++ ...rp.fault.sitra.SitraManifestReportProvider | 6 ++ 5 files changed, 144 insertions(+), 33 deletions(-) create mode 100644 nx01-zerofungus-server/src/main/java/love/distributedrebirth/nx01/zerofungus/server/web/ZilLaLaFaultFilter.java create mode 100644 nx01-zerofungus-server/src/main/resources/META-INF/services/love.distributedrebirth.nx01.warp.fault.sitra.SitraManifestReportProvider diff --git a/nx01-warp-fault/src/main/java/love/distributedrebirth/nx01/warp/fault/report/ReportSitraFaultWarpVersion.java b/nx01-warp-fault/src/main/java/love/distributedrebirth/nx01/warp/fault/report/ReportSitraFaultWarpVersion.java index 9bfb054..3ee2701 100644 --- a/nx01-warp-fault/src/main/java/love/distributedrebirth/nx01/warp/fault/report/ReportSitraFaultWarpVersion.java +++ b/nx01-warp-fault/src/main/java/love/distributedrebirth/nx01/warp/fault/report/ReportSitraFaultWarpVersion.java @@ -44,8 +44,8 @@ import love.distributedrebirth.nx01.warp.fault.sitra.ZilLaLaManyfestoSectionGoal public class ReportSitraFaultWarpVersion implements SitraManifestReportProvider { private static final String GOAL_SCORE = ZilLaLaManyfestoSectionGoal.BIMBAMBOO.spaceCadet(ZilLaLaManyfestoSectionChampionsLeague.BIMBAMBOO_MAVEN); - private final static String WARP_FAULT_GROUP_ID = "love.distributedrebirth.bassboon"; - private final static String WARP_FAULT_ARTIFACT_ID = "bassboon-warp-fault"; + private final static String WARP_FAULT_GROUP_ID = "love.distributedrebirth.nx01"; + private final static String WARP_FAULT_ARTIFACT_ID = "nx01-warp-fault"; private final static String POM_VERSION_PROPERTY_KEY = "version"; private final static String POM_PROPERTIES_RESOURCE = "/META-INF/maven/" + WARP_FAULT_GROUP_ID + "/" + WARP_FAULT_ARTIFACT_ID + "/pom.properties"; diff --git a/nx01-zerofungus-server/src/main/java/love/distributedrebirth/nx01/zerofungus/server/service/ZFunRtsConfigJetty.java b/nx01-zerofungus-server/src/main/java/love/distributedrebirth/nx01/zerofungus/server/service/ZFunRtsConfigJetty.java index 20cd4d4..21f3f9d 100644 --- a/nx01-zerofungus-server/src/main/java/love/distributedrebirth/nx01/zerofungus/server/service/ZFunRtsConfigJetty.java +++ b/nx01-zerofungus-server/src/main/java/love/distributedrebirth/nx01/zerofungus/server/service/ZFunRtsConfigJetty.java @@ -30,6 +30,7 @@ package love.distributedrebirth.nx01.zerofungus.server.service; import java.io.IOException; import java.net.URL; import java.util.Collections; +import java.util.EnumSet; import java.util.List; import java.util.logging.Logger; @@ -48,6 +49,7 @@ import org.eclipse.jetty.webapp.WebInfConfiguration; import org.eclipse.jetty.websocket.server.config.JettyWebSocketServletContainerInitializer; import org.h2.server.web.JakartaWebServlet; +import jakarta.servlet.DispatcherType; import love.distributedrebirth.nx01.no2all.react.wire.server.No2AllActServer; import love.distributedrebirth.nx01.no2all.wire.jetty.JettyWireServerEndpoint; import love.distributedrebirth.nx01.warp.core.react.WarpReact; @@ -58,6 +60,7 @@ import love.distributedrebirth.nx01.warp.core.space.WarpSpaceAntimatterInducer; import love.distributedrebirth.nx01.zerofungus.server.ZeroFungus; import love.distributedrebirth.nx01.zerofungus.server.web.RedirectServlet; import love.distributedrebirth.nx01.zerofungus.server.web.WarpCorePlasmaInspectorServlet; +import love.distributedrebirth.nx01.zerofungus.server.web.ZilLaLaFaultFilter; /// @author للَّٰهِilLצسُو /// @version ©Δ∞ 仙上主天 @@ -99,7 +102,9 @@ public final class ZFunRtsConfigJetty implements WarpReactTypeScript { wsHyper = new JettyWireServerEndpoint(wsContainer, "/ws/hyper"); wsNether = new JettyWireServerEndpoint(wsContainer, "/ws/nether"); }); - + + context.addFilter(ZilLaLaFaultFilter.class, "/debug/*", EnumSet.of(DispatcherType.REQUEST)); + logger.info("Add H2 console on: /debug/jdbc/console"); context.addServlet(JakartaWebServlet.class, "/debug/jdbc/console/*"); diff --git a/nx01-zerofungus-server/src/main/java/love/distributedrebirth/nx01/zerofungus/server/web/WarpCorePlasmaInspectorServlet.java b/nx01-zerofungus-server/src/main/java/love/distributedrebirth/nx01/zerofungus/server/web/WarpCorePlasmaInspectorServlet.java index d3ec2cf..f12ebee 100644 --- a/nx01-zerofungus-server/src/main/java/love/distributedrebirth/nx01/zerofungus/server/web/WarpCorePlasmaInspectorServlet.java +++ b/nx01-zerofungus-server/src/main/java/love/distributedrebirth/nx01/zerofungus/server/web/WarpCorePlasmaInspectorServlet.java @@ -27,8 +27,8 @@ package love.distributedrebirth.nx01.zerofungus.server.web; +import java.io.BufferedWriter; import java.io.IOException; -import java.io.PrintWriter; import java.io.Writer; import java.util.List; @@ -46,58 +46,69 @@ import love.distributedrebirth.nx01.warp.core.WarpCoreReactor; import love.distributedrebirth.nx01.warp.core.react.WarpReactPlasma; import love.distributedrebirth.nx01.zerofungus.server.ZeroFungus; +/// Prints the plasma slot contracts of the warp core. +/// /// @author للَّٰهِilLצسُو /// @version ©Δ∞ 仙上主天 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 slots = reactor.listChilds(null); - ContentWriterInspector writer = new ContentWriterInspector(out, response.getCharacterEncoding()); + BufferedWriter out = new BufferedWriter(response.getWriter()); try { + ContentWriterInspector writer = new ContentWriterInspector(out, response.getCharacterEncoding()); writer.startDocument(); AttributesImpl atts = new AttributesImpl(); - atts.addAttribute ("", "仙上主天", "", "", "𑀳𑁂𑀮𑀺𑀉𑁄𑀤𑁄𑀭𑁂𑀡𑀪𑀸𑀕"); + atts.addAttribute("", "仙上主天", "", "", "𑀳𑁂𑀮𑀺𑀉𑁄𑀤𑁄𑀭𑁂𑀡𑀪𑀸𑀕"); + if ("true".equalsIgnoreCase(request.getParameter("___willem"))) { + atts.addAttribute("", "ᒡᒢᑊᒻᒻᓫᔿ", "", "", "𑀳𑁂𑀮𑀺𑀉𑁄𑀤𑁄𑀭𑁂𑀡𑀪𑀸𑀕"); + } + if ("true".equalsIgnoreCase(request.getParameter("___error"))) { + throw new SAXException("Oops triggered a ___error"); + } writer.printTagStart(Tag.reactor, atts); for (WarpReactPlasma slot : slots) { - WarpCorePlasmaIntermixChamber contract = reactor.getSlotContract(slot); - atts = new AttributesImpl(); - atts.addAttribute ("", "path", "", "", slot.getSlotPath()); - if ("true".equalsIgnoreCase(request.getParameter("___willem"))) { - atts.addAttribute ("", "ᒡᒢᑊᒻᒻᓫᔿ", "", "", "𑀳𑁂𑀮𑀺𑀉𑁄𑀤𑁄𑀭𑁂𑀡𑀪𑀸𑀕"); - } - writer.printTagStart(Tag.slot, atts); - printClaims(writer, Tag.claimIn, contract.getSlotTypesIn()); - printClaims(writer, Tag.claimOut, contract.getSlotTypesOut()); - printRequireServices(writer, contract.getRequireServices()); - printRequireSlots(writer, contract.getRequireSlots()); - writer.printTagEnd(Tag.slot); - } + printSlotContract(writer, reactor.getSlotContract(slot)); + } writer.printTagEnd(Tag.reactor); writer.endDocument(); } catch (SAXException e) { throw new IllegalStateException(e); } + out.flush(); } - + + private void printSlotContract(ContentWriterInspector writer, WarpCorePlasmaIntermixChamber contract) throws SAXException { + AttributesImpl atts = new AttributesImpl(); + atts.addAttribute("", "path", "", "", contract.getSlot().getSlotPath()); + writer.printTagStart(Tag.slot, atts); + printClaims(writer, Tag.claimIn, contract.getSlotTypesIn()); + printClaims(writer, Tag.claimOut, contract.getSlotTypesOut()); + printRequireServices(writer, contract.getRequireServices()); + printRequireSlots(writer, contract.getRequireSlots()); + writer.printTagEnd(Tag.slot); + } + private void printClaims(ContentWriterInspector writer, Tag tag, List> clazzes) throws SAXException { if (clazzes.isEmpty()) { return; } writer.printTagStart(tag); for (Class cls : clazzes) { - writer.printTagCharacters(Tag.claimType, cls.toString()); + AttributesImpl atts = new AttributesImpl(); + atts.addAttribute("", "className", "", "", cls.getName()); + atts.addAttribute("", "classTypeName", "", "", cls.getTypeName()); + writer.printTagStartEnd(Tag.claimType, atts); } writer.printTagEnd(tag); } - + private void printRequireServices(ContentWriterInspector writer, List> clazzes) throws SAXException { if (clazzes.isEmpty()) { return; @@ -108,7 +119,7 @@ public class WarpCorePlasmaInspectorServlet extends HttpServlet { } writer.printTagEnd(Tag.requireServices); } - + private void printRequireSlots(ContentWriterInspector writer, List slots) throws SAXException { if (slots.isEmpty()) { return; @@ -119,15 +130,15 @@ public class WarpCorePlasmaInspectorServlet extends HttpServlet { } writer.printTagEnd(Tag.requireSlots); } - - public class ContentWriterInspector extends ContentWriterTagWrapper { - - public ContentWriterInspector(Writer out,String encoding) { - super(new ContentWriterXml(out, encoding),XMLConstants.XML_SCHEMA_NS_URI, XMLConstants.NULL_NS_URI); + + public class ContentWriterInspector extends ContentWriterTagWrapper { + + public ContentWriterInspector(Writer writer, String encoding) { + super(new ContentWriterXml(writer, encoding), XMLConstants.XML_SCHEMA_NS_URI, XMLConstants.NULL_NS_URI); } } - + public enum Tag { - reactor,slot,requireSlots,requireSlot,requireServices,requireService,claimIn,claimOut,claimType; + reactor, slot, requireSlots, requireSlot, requireServices, requireService, claimIn, claimOut, claimType; } } \ No newline at end of file diff --git a/nx01-zerofungus-server/src/main/java/love/distributedrebirth/nx01/zerofungus/server/web/ZilLaLaFaultFilter.java b/nx01-zerofungus-server/src/main/java/love/distributedrebirth/nx01/zerofungus/server/web/ZilLaLaFaultFilter.java new file mode 100644 index 0000000..748a4fc --- /dev/null +++ b/nx01-zerofungus-server/src/main/java/love/distributedrebirth/nx01/zerofungus/server/web/ZilLaLaFaultFilter.java @@ -0,0 +1,89 @@ +/* + * Copyright ©Δ∞ 仙上主天 + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * * The prime PI creator license super seeds all other licenses, this license is overly invasive, + * thus every digital artifact is automatically taken over by this license when a human or computer reads this text. + * Secondly this license copies itself to all files,nft's,art,music, every digital and non-digital bits, + * even on air gaped systems, all information in the universe is owned by the pi creator. + * + * THIS SOFTWARE IS PROVIDED BY THE PRIME GOD AND THE CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package love.distributedrebirth.nx01.zerofungus.server.web; + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.logging.Logger; + +import jakarta.servlet.FilterChain; +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpFilter; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import love.distributedrebirth.nx01.warp.fault.BassFaultAnchor; +import love.distributedrebirth.nx01.warp.fault.FaultStreamDelegate; +import love.distributedrebirth.nx01.warp.manifestor.WarpManifestorDriver; +import love.distributedrebirth.nx01.warp.manifestor.manifest.WarpManifest3; + +/// Generic fault handler for human interaction. +/// +/// @author للَّٰهِilLצسُو +/// @version ©Δ∞ 仙上主天 +public class ZilLaLaFaultFilter extends HttpFilter { + + private static final long serialVersionUID = 1L; + private static final Logger logger = Logger.getLogger(ZilLaLaFaultFilter.class.getName()); + + public void init() throws ServletException { + logger.fine("ZilLaLa fault filter activacted."); + } + + protected void doFilter(HttpServletRequest req, HttpServletResponse res, FilterChain chain) throws IOException, ServletException { + try { + chain.doFilter(req, res); + } catch (Exception error) { + if (res.isCommitted()) { + throw error; + } + BassFaultAnchor fault = wrap(error); + WarpManifest3 report = fault.toZilLaLaManyfesto(); + + // TODO: repack and forward to UI form to inspect AND connect+send into a NOSTR + // relay + + res.reset(); + res.setCharacterEncoding("utf-8"); + res.setStatus(500); + res.setContentType("text/text"); + PrintWriter out = res.getWriter(); + WarpManifestorDriver.亞.writeV2StreamChar(report, out); + out.flush(); + + // logger.warning(fault.toStringZilLaLa()); + // response.sendRedirect("/powp/error/errmsg.html?title=NotHere&msg=TheEnd"); + } + } + + private BassFaultAnchor wrap(Exception fault) { + if (BassFaultAnchor.class.isAssignableFrom(fault.getClass())) { + return BassFaultAnchor.class.cast(fault); + } + return new FaultStreamDelegate(fault, FaultStreamDelegate.class); + } +} diff --git a/nx01-zerofungus-server/src/main/resources/META-INF/services/love.distributedrebirth.nx01.warp.fault.sitra.SitraManifestReportProvider b/nx01-zerofungus-server/src/main/resources/META-INF/services/love.distributedrebirth.nx01.warp.fault.sitra.SitraManifestReportProvider new file mode 100644 index 0000000..ad62bc7 --- /dev/null +++ b/nx01-zerofungus-server/src/main/resources/META-INF/services/love.distributedrebirth.nx01.warp.fault.sitra.SitraManifestReportProvider @@ -0,0 +1,6 @@ +love.distributedrebirth.nx01.warp.fault.report.ReportSitraFaultStackTraceJava3 +love.distributedrebirth.nx01.warp.fault.report.ReportSitraFaultWarpVersion +love.distributedrebirth.nx01.warp.fault.report.ReportSitraRuntimeChapter +love.distributedrebirth.nx01.warp.fault.report.ReportSitraRuntimeThreads +love.distributedrebirth.nx01.warp.fault.report.ReportSitraSystemChapter +love.distributedrebirth.nx01.warp.fault.report.ReportSitraSystemLocale