do not use config loader or config logger in BaseApplicationBuilder

This commit is contained in:
Jörg Prante 2024-03-25 10:04:49 +01:00
parent 5d7dfc041d
commit ea799e7a87
6 changed files with 0 additions and 160 deletions

View file

@ -1,4 +0,0 @@
The htmlflow project is not enabled for Java modules.
Maybe the dependencies are wrong. The asm-parent pom dependency can not be a module.

View file

@ -1,4 +0,0 @@
dependencies {
api project(':net-http-server')
api libs.htmlflow
}

View file

@ -1,8 +0,0 @@
module org.xbib.net.http.htmlflow {
exports org.xbib.net.http.htmlflow;
requires org.xbib.net;
requires org.xbib.net.http;
requires org.xbib.net.http.server;
requires org.xbib.config;
requires java.logging;
}

View file

@ -1,60 +0,0 @@
package org.xbib.net.http.htmlflow;
import org.xbib.net.Attributes;
import org.xbib.net.Resource;
import org.xbib.net.buffer.DataBuffer;
import org.xbib.net.http.HttpResponseStatus;
import org.xbib.net.http.server.application.Application;
import org.xbib.net.http.server.resource.HtmlTemplateResource;
import org.xbib.net.http.server.resource.HtmlTemplateResourceHandler;
import org.xbib.net.http.server.route.HttpRouterContext;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.util.logging.Level;
import java.util.logging.Logger;
import static org.xbib.net.http.HttpHeaderNames.CONTENT_TYPE;
public class HtmlFlowResourceHandler extends HtmlTemplateResourceHandler {
public HtmlFlowResourceHandler(Path root, String suffix, String indexFileName) {
super(root, suffix, indexFileName);
}
@Override
protected Resource createResource(HttpRouterContext httpRouterContext) throws IOException {
return new HtmlFlowResource(this, httpRouterContext);
}
protected static class HtmlFlowResource extends HtmlTemplateResource {
private static final Logger logger = Logger.getLogger(HtmlFlowResource.class.getName());
protected HtmlFlowResource(HtmlTemplateResourceHandler templateResourceHandler, HttpRouterContext httpRouterContext) throws IOException {
super(templateResourceHandler, httpRouterContext);
}
@Override
public void render(HttpRouterContext context) throws IOException {
Application application = context.getAttributes().get(Application.class, "application");
if (application == null) {
logger.log(Level.WARNING, "application is null");
return;
}
DataBuffer dataBuffer = context.getDataBufferFactory().allocateBuffer();
dataBuffer.write(render(application, context.getAttributes()), StandardCharsets.UTF_8);
HttpResponseStatus httpResponseStatus = context.getAttributes().get(HttpResponseStatus.class, "_status", HttpResponseStatus.OK);
context.status(httpResponseStatus)
.header("cache-control", "no-cache") // override default must-revalidate behavior
.header("content-length", Integer.toString(dataBuffer.writePosition()))
.header(CONTENT_TYPE, "text/html; charset=" + StandardCharsets.UTF_8.displayName())
.body(dataBuffer);
}
protected String render(Application application, Attributes attributes) {
return null;
}
}
}

View file

@ -1,15 +0,0 @@
package org.xbib.net.http.htmlflow;
import org.xbib.net.http.server.service.BaseHttpService;
import org.xbib.net.http.server.service.BaseHttpServiceBuilder;
public class HtmlFlowService extends BaseHttpService {
protected HtmlFlowService(BaseHttpServiceBuilder builder) {
super(builder);
}
public static HtmlFlowServiceBuilder builder() {
return new HtmlFlowServiceBuilder();
}
}

View file

@ -1,69 +0,0 @@
package org.xbib.net.http.htmlflow;
import org.xbib.net.ParameterDefinition;
import org.xbib.net.http.HttpMethod;
import org.xbib.net.http.server.HttpHandler;
import org.xbib.net.http.server.domain.HttpSecurityDomain;
import org.xbib.net.http.server.service.BaseHttpServiceBuilder;
import java.nio.file.Path;
public class HtmlFlowServiceBuilder extends BaseHttpServiceBuilder {
protected Path prefix;
protected String suffix;
public HtmlFlowServiceBuilder() {
super();
this.prefix = null;
}
@Override
public HtmlFlowServiceBuilder setPath(String path) {
super.setPath(path);
return this;
}
@Override
public HtmlFlowServiceBuilder setMethod(HttpMethod... httpMethod) {
super.setMethod(httpMethod);
return this;
}
@Override
public HtmlFlowServiceBuilder setHandler(HttpHandler... handler) {
super.setHandler(handler);
return this;
}
@Override
public HtmlFlowServiceBuilder setParameterDefinition(ParameterDefinition... parameterDefinition) {
super.setParameterDefinition(parameterDefinition);
return this;
}
@Override
public HtmlFlowServiceBuilder setSecurityDomain(HttpSecurityDomain securityDomain) {
super.setSecurityDomain(securityDomain);
return this;
}
public HtmlFlowServiceBuilder setPrefix(Path prefix) {
this.prefix = prefix;
return this;
}
public HtmlFlowServiceBuilder setSuffix(String suffix) {
this.suffix = suffix;
return this;
}
public HtmlFlowService build() {
if (this.handlers == null) {
HttpHandler httpHandler = new HtmlFlowResourceHandler(prefix, suffix, "index.java");
setHandler(httpHandler);
}
return new HtmlFlowService(this);
}
}