Added ZilLaLa servlet filter

This commit is contained in:
Willem Cazander 2024-12-19 19:31:20 +01:00
parent 597d69b0a7
commit e2ded94f91
5 changed files with 144 additions and 33 deletions

View file

@ -44,8 +44,8 @@ import love.distributedrebirth.nx01.warp.fault.sitra.ZilLaLaManyfestoSectionGoal
public class ReportSitraFaultWarpVersion implements SitraManifestReportProvider { public class ReportSitraFaultWarpVersion implements SitraManifestReportProvider {
private static final String GOAL_SCORE = ZilLaLaManyfestoSectionGoal.BIMBAMBOO.spaceCadet(ZilLaLaManyfestoSectionChampionsLeague.BIMBAMBOO_MAVEN); 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_GROUP_ID = "love.distributedrebirth.nx01";
private final static String WARP_FAULT_ARTIFACT_ID = "bassboon-warp-fault"; 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_VERSION_PROPERTY_KEY = "version";
private final static String POM_PROPERTIES_RESOURCE = "/META-INF/maven/" + WARP_FAULT_GROUP_ID + "/" + WARP_FAULT_ARTIFACT_ID + "/pom.properties"; private final static String POM_PROPERTIES_RESOURCE = "/META-INF/maven/" + WARP_FAULT_GROUP_ID + "/" + WARP_FAULT_ARTIFACT_ID + "/pom.properties";

View file

@ -30,6 +30,7 @@ package love.distributedrebirth.nx01.zerofungus.server.service;
import java.io.IOException; import java.io.IOException;
import java.net.URL; import java.net.URL;
import java.util.Collections; import java.util.Collections;
import java.util.EnumSet;
import java.util.List; import java.util.List;
import java.util.logging.Logger; 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.eclipse.jetty.websocket.server.config.JettyWebSocketServletContainerInitializer;
import org.h2.server.web.JakartaWebServlet; import org.h2.server.web.JakartaWebServlet;
import jakarta.servlet.DispatcherType;
import love.distributedrebirth.nx01.no2all.react.wire.server.No2AllActServer; import love.distributedrebirth.nx01.no2all.react.wire.server.No2AllActServer;
import love.distributedrebirth.nx01.no2all.wire.jetty.JettyWireServerEndpoint; import love.distributedrebirth.nx01.no2all.wire.jetty.JettyWireServerEndpoint;
import love.distributedrebirth.nx01.warp.core.react.WarpReact; 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.ZeroFungus;
import love.distributedrebirth.nx01.zerofungus.server.web.RedirectServlet; import love.distributedrebirth.nx01.zerofungus.server.web.RedirectServlet;
import love.distributedrebirth.nx01.zerofungus.server.web.WarpCorePlasmaInspectorServlet; import love.distributedrebirth.nx01.zerofungus.server.web.WarpCorePlasmaInspectorServlet;
import love.distributedrebirth.nx01.zerofungus.server.web.ZilLaLaFaultFilter;
/// @author للَّٰهِilLצسُو /// @author للَّٰهِilLצسُو
/// @version ©Δ 仙上主天 /// @version ©Δ 仙上主天
@ -99,7 +102,9 @@ public final class ZFunRtsConfigJetty implements WarpReactTypeScript {
wsHyper = new JettyWireServerEndpoint(wsContainer, "/ws/hyper"); wsHyper = new JettyWireServerEndpoint(wsContainer, "/ws/hyper");
wsNether = new JettyWireServerEndpoint(wsContainer, "/ws/nether"); wsNether = new JettyWireServerEndpoint(wsContainer, "/ws/nether");
}); });
context.addFilter(ZilLaLaFaultFilter.class, "/debug/*", EnumSet.of(DispatcherType.REQUEST));
logger.info("Add H2 console on: /debug/jdbc/console"); logger.info("Add H2 console on: /debug/jdbc/console");
context.addServlet(JakartaWebServlet.class, "/debug/jdbc/console/*"); context.addServlet(JakartaWebServlet.class, "/debug/jdbc/console/*");

View file

@ -27,8 +27,8 @@
package love.distributedrebirth.nx01.zerofungus.server.web; package love.distributedrebirth.nx01.zerofungus.server.web;
import java.io.BufferedWriter;
import java.io.IOException; import java.io.IOException;
import java.io.PrintWriter;
import java.io.Writer; import java.io.Writer;
import java.util.List; 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.warp.core.react.WarpReactPlasma;
import love.distributedrebirth.nx01.zerofungus.server.ZeroFungus; import love.distributedrebirth.nx01.zerofungus.server.ZeroFungus;
/// Prints the plasma slot contracts of the warp core.
///
/// @author للَّٰهِilLצسُو /// @author للَّٰهِilLצسُو
/// @version ©Δ 仙上主天 /// @version ©Δ 仙上主天
public class WarpCorePlasmaInspectorServlet extends HttpServlet { public class WarpCorePlasmaInspectorServlet extends HttpServlet {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@Override @Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
response.setContentType("text/xml"); response.setContentType("text/xml");
response.setCharacterEncoding("utf-8"); response.setCharacterEncoding("utf-8");
PrintWriter out = response.getWriter();
WarpCoreReactor reactor = ZeroFungus.INSTANCE.getWarpCore(); WarpCoreReactor reactor = ZeroFungus.INSTANCE.getWarpCore();
List<WarpReactPlasma> slots = reactor.listChilds(null); List<WarpReactPlasma> slots = reactor.listChilds(null);
ContentWriterInspector writer = new ContentWriterInspector(out, response.getCharacterEncoding()); BufferedWriter out = new BufferedWriter(response.getWriter());
try { try {
ContentWriterInspector writer = new ContentWriterInspector(out, response.getCharacterEncoding());
writer.startDocument(); writer.startDocument();
AttributesImpl atts = new AttributesImpl(); 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); writer.printTagStart(Tag.reactor, atts);
for (WarpReactPlasma slot : slots) { for (WarpReactPlasma slot : slots) {
WarpCorePlasmaIntermixChamber contract = reactor.getSlotContract(slot); printSlotContract(writer, 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);
}
writer.printTagEnd(Tag.reactor); writer.printTagEnd(Tag.reactor);
writer.endDocument(); writer.endDocument();
} catch (SAXException e) { } catch (SAXException e) {
throw new IllegalStateException(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<Class<?>> clazzes) throws SAXException { private void printClaims(ContentWriterInspector writer, Tag tag, List<Class<?>> clazzes) throws SAXException {
if (clazzes.isEmpty()) { if (clazzes.isEmpty()) {
return; return;
} }
writer.printTagStart(tag); writer.printTagStart(tag);
for (Class<?> cls : clazzes) { 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); writer.printTagEnd(tag);
} }
private void printRequireServices(ContentWriterInspector writer, List<Class<?>> clazzes) throws SAXException { private void printRequireServices(ContentWriterInspector writer, List<Class<?>> clazzes) throws SAXException {
if (clazzes.isEmpty()) { if (clazzes.isEmpty()) {
return; return;
@ -108,7 +119,7 @@ public class WarpCorePlasmaInspectorServlet extends HttpServlet {
} }
writer.printTagEnd(Tag.requireServices); writer.printTagEnd(Tag.requireServices);
} }
private void printRequireSlots(ContentWriterInspector writer, List<WarpReactPlasma> slots) throws SAXException { private void printRequireSlots(ContentWriterInspector writer, List<WarpReactPlasma> slots) throws SAXException {
if (slots.isEmpty()) { if (slots.isEmpty()) {
return; return;
@ -119,15 +130,15 @@ public class WarpCorePlasmaInspectorServlet extends HttpServlet {
} }
writer.printTagEnd(Tag.requireSlots); writer.printTagEnd(Tag.requireSlots);
} }
public class ContentWriterInspector extends ContentWriterTagWrapper<Tag,ContentWriterXml> { public class ContentWriterInspector extends ContentWriterTagWrapper<Tag, ContentWriterXml> {
public ContentWriterInspector(Writer out,String encoding) { public ContentWriterInspector(Writer writer, String encoding) {
super(new ContentWriterXml(out, encoding),XMLConstants.XML_SCHEMA_NS_URI, XMLConstants.NULL_NS_URI); super(new ContentWriterXml(writer, encoding), XMLConstants.XML_SCHEMA_NS_URI, XMLConstants.NULL_NS_URI);
} }
} }
public enum Tag { public enum Tag {
reactor,slot,requireSlots,requireSlot,requireServices,requireService,claimIn,claimOut,claimType; reactor, slot, requireSlots, requireSlot, requireServices, requireService, claimIn, claimOut, claimType;
} }
} }

View file

@ -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);
}
}

View file

@ -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