Prep for custom error pages

This commit is contained in:
zzz
2025-06-03 10:04:25 -04:00
parent 9c2cf83dfa
commit bf5792f2ea
3 changed files with 27 additions and 9 deletions

View File

@ -1,16 +1,31 @@
package net.i2p.servlet;
import org.eclipse.jetty.ee8.nested.ErrorHandler;
import java.io.File;
import org.eclipse.jetty.ee8.servlet.ErrorPageErrorHandler;
import net.i2p.I2PAppContext;
/**
* Customize the error page.
*
* @since Jetty 12
*/
public class I2PErrorHandler extends ErrorHandler
public class I2PErrorHandler extends ErrorPageErrorHandler
{
private final File _docroot;
public I2PErrorHandler() {
this(new File(I2PAppContext.getGlobalContext().getConfigDir(), "eepsite/docroot"));
}
public I2PErrorHandler(String docroot) {
this(new File(docroot));
}
public I2PErrorHandler(File docroot) {
super();
_docroot = docroot;
setShowServlet(false);
setShowStacks(false);
}

View File

@ -9,8 +9,11 @@ to serve static html files and images.
-->
<Configure class="org.eclipse.jetty.ee8.servlet.ServletContextHandler">
<New id="baseroot" class="java.lang.String">
<Arg>./eepsite/docroot</Arg>
</New>
<Set name="contextPath">/</Set>
<Set name="baseResourceAsString">./eepsite/docroot/</Set>
<Set name="baseResourceAsString"><Ref refid="baseroot" /></Set>
<Call name="setInitParameter">
<Arg>org.eclipse.jetty.servlet.Default.cacheControl</Arg>
<Arg>max-age=3600,public</Arg>
@ -26,7 +29,9 @@ to serve static html files and images.
</Call>
<Call name="setErrorHandler">
<Arg>
<New class="net.i2p.servlet.I2PErrorHandler" />
<New class="net.i2p.servlet.I2PErrorHandler">
<Arg><Ref refid="baseroot" /></Arg>
</New>
</Arg>
</Call>
</Configure>

View File

@ -32,13 +32,11 @@
-->
<Configure class="org.eclipse.jetty.server.handler.ContextHandler">
<New id="root" class="java.lang.String">
<New id="cgiroot" class="java.lang.String">
<Arg>./eepsite/cgi-bin</Arg>
</New>
<Set name="contextPath">/cgi-bin</Set>
<Set name="baseResourceAsString"><Ref refid="root" /></Set>
<Set name="baseResourceAsString"><Ref refid="cgiroot" /></Set>
<Set name="handler">
<New class="org.eclipse.jetty.server.handler.PathMappingsHandler">
<Call name="addMapping">
@ -50,7 +48,7 @@
<Arg>(https?)://([^/]+)(.*)</Arg>
<!-- host:port ignored since if using a domain socket, but argument must be here -->
<Arg>http://localhost:9000$3</Arg>
<Arg><Ref refid="root" /></Arg>
<Arg><Ref refid="cgiroot" /></Arg>
<Set name="scriptPattern"><Call class="java.util.regex.Pattern" name="compile"><Arg>/cgi-bin(.+)</Arg></Call></Set>
<Set name="fastCGISecure">false</Set>