work on web application with j2html

This commit is contained in:
Jörg Prante 2023-07-10 19:46:33 +02:00
parent d38f2d351e
commit c5da201308
2 changed files with 8 additions and 7 deletions

View file

@ -15,8 +15,6 @@ import org.xbib.net.http.HttpHeaderNames;
import org.xbib.net.http.HttpHeaderValues;
import org.xbib.net.http.HttpResponseStatus;
import org.xbib.net.http.HttpVersion;
import org.xbib.net.http.j2html.J2HtmlResourceHandler;
import org.xbib.net.http.j2html.J2HtmlService;
import org.xbib.net.http.server.application.web.WebApplication;
import org.xbib.net.http.server.domain.BaseHttpDomain;
import org.xbib.net.http.server.domain.BaseHttpSecurityDomain;
@ -155,6 +153,7 @@ public final class Bootstrap {
.build();
HttpRouter httpRouter = BaseHttpRouter.builder()
.setPrefix("/")
.setHandler(400, new GroovyHttpStatusHandler(HttpResponseStatus.BAD_REQUEST, "Bad request", "400.gtpl"))
.setHandler(401, new GroovyHttpStatusHandler(HttpResponseStatus.UNAUTHORIZED, "Unauthorized", "401.gtpl"))
.setHandler(403, new GroovyHttpStatusHandler(HttpResponseStatus.FORBIDDEN, "Forbidden", "403.gtpl"))
@ -176,11 +175,6 @@ public final class Bootstrap {
.setHandler(new ClassLoaderResourceHandler(Bootstrap.class.getClassLoader(), "META-INF/resources/"))
.build())
.addService(httpService)
.addService(J2HtmlService.builder()
.setPrefix("/j2html")
.setPath("glob:**")
.setHandler(new J2HtmlResourceHandler())
.build())
.addService(GroovyTemplateService.builder()
.setTemplateName("index.gtpl")
.setSecurityDomain(securityDomain)

View file

@ -1,6 +1,7 @@
package org.xbib.net.http.server.application.web.j2html;
import org.xbib.net.Attributes;
import org.xbib.net.Resource;
import org.xbib.net.http.j2html.J2HtmlResourceHandler;
import org.xbib.net.http.server.application.Application;
import org.xbib.net.http.server.resource.HtmlTemplateResourceHandler;
@ -17,12 +18,18 @@ import static j2html.TagCreator.pre;
public class InternalServerErrorHandler extends J2HtmlResourceHandler {
@Override
protected Resource createResource(HttpRouterContext httpRouterContext) throws IOException {
return new InternalServerErrorResource(this, httpRouterContext);
}
protected static class InternalServerErrorResource extends J2HtmlResource {
protected InternalServerErrorResource(HtmlTemplateResourceHandler templateResourceHandler, HttpRouterContext httpRouterContext) throws IOException {
super(templateResourceHandler, httpRouterContext);
}
@Override
protected String render(Application application, Attributes attributes) {
String message = attributes.get(String.class, "_message");
Throwable throwable = attributes.get(Throwable.class, "_throwable");