Merge pull request 'feature/rename-to-maze' (#8) from feature/rename-to-maze into master
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
Reviewed-on: #8
This commit is contained in:
commit
90088536ed
18 changed files with 206 additions and 175 deletions
|
@ -26,6 +26,8 @@ steps:
|
|||
environment:
|
||||
REPO_TOKEN:
|
||||
from_secret: repo-token
|
||||
REPO_TOKEN_OSSRH:
|
||||
from_secret: repo-token-ossrh
|
||||
commands:
|
||||
- mvn -s maven-settings.xml deploy -DskipTests=true
|
||||
when:
|
||||
|
@ -41,7 +43,7 @@ steps:
|
|||
username: manuel
|
||||
password:
|
||||
from_secret: docker-token
|
||||
repo: gittr.ch/java/labyrinth
|
||||
repo: gittr.ch/java/a-maze-r
|
||||
tags:
|
||||
- latest
|
||||
dockerfile: docker/Dockerfile
|
||||
|
@ -59,7 +61,7 @@ steps:
|
|||
username: manuel
|
||||
password:
|
||||
from_secret: docker-token
|
||||
repo: gittr.ch/java/labyrinth
|
||||
repo: gittr.ch/java/a-maze-r
|
||||
tags:
|
||||
- latest
|
||||
- ${DRONE_TAG}
|
||||
|
|
|
@ -1,2 +1 @@
|
|||
# labyrinth-server
|
||||
|
||||
# maze-server
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
FROM openjdk:17-slim
|
||||
|
||||
COPY target/labyrinth-server-*.jar /app/
|
||||
COPY target/maze-server-*.jar /app/
|
||||
RUN rm /app/*-sources.jar
|
||||
RUN mv /app/*.jar /app/app.jar
|
||||
|
||||
CMD java -Dfritteli.labyrinth.server.host=0.0.0.0 -Dfritteli.labyrinth.server.port=80 -jar /app/app.jar
|
||||
CMD java -Dfritteli.maze.server.host=0.0.0.0 -Dfritteli.maze.server.port=80 -jar /app/app.jar
|
||||
|
|
|
@ -8,5 +8,10 @@
|
|||
<username>ci</username>
|
||||
<password>${env.REPO_TOKEN}</password>
|
||||
</server>
|
||||
<server>
|
||||
<id>ossrh</id>
|
||||
<username>fritteli</username>
|
||||
<password>${env.REPO_TOKEN_OSSRH}</password>
|
||||
</server>
|
||||
</servers>
|
||||
</settings>
|
||||
|
|
163
pom.xml
163
pom.xml
|
@ -1,31 +1,28 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>ch.fritteli</groupId>
|
||||
<artifactId>fritteli-build-parent</artifactId>
|
||||
<version>2.0.4</version>
|
||||
<version>5.0.0</version>
|
||||
</parent>
|
||||
|
||||
<groupId>ch.fritteli.labyrinth</groupId>
|
||||
<artifactId>labyrinth-server</artifactId>
|
||||
<groupId>ch.fritteli.a-maze-r</groupId>
|
||||
<artifactId>maze-server</artifactId>
|
||||
<version>0.0.7-SNAPSHOT</version>
|
||||
<description>The Labyrinth server, offering a REST endpoint to access the Labyrinth Generator.</description>
|
||||
<url>https://manuel.friedli.info/labyrinth.html</url>
|
||||
|
||||
<properties>
|
||||
<java.source.version>17</java.source.version>
|
||||
<java.target.version>17</java.target.version>
|
||||
<jetbrains-annotations.version>24.0.1</jetbrains-annotations.version>
|
||||
<junit-jupiter.version>5.9.2</junit-jupiter.version>
|
||||
<labyrinth-generator.version>0.0.8</labyrinth-generator.version>
|
||||
<logback.version>1.4.6</logback.version>
|
||||
<lombok.version>1.18.26</lombok.version>
|
||||
<slf4j.version>2.0.7</slf4j.version>
|
||||
<undertow.version>2.3.5.Final</undertow.version>
|
||||
<vavr.version>0.10.4</vavr.version>
|
||||
</properties>
|
||||
<description>The A-Maze-R server, offering a REST endpoint to access the Maze Generator.</description>
|
||||
<url>https://manuel.friedli.info/maze.html</url>
|
||||
<inceptionYear>2022</inceptionYear>
|
||||
|
||||
<licenses>
|
||||
<license>
|
||||
<name>GNU Affero General Public License</name>
|
||||
<url>https://www.gnu.org/licenses/agpl-3.0.html</url>
|
||||
</license>
|
||||
</licenses>
|
||||
|
||||
<developers>
|
||||
<developer>
|
||||
|
@ -43,11 +40,32 @@
|
|||
</developer>
|
||||
</developers>
|
||||
|
||||
<scm>
|
||||
<connection>scm:git:https://gittr.ch/java/maze-server.git</connection>
|
||||
<developerConnection>scm:git:ssh://git@gittr.ch/java/maze-server.git</developerConnection>
|
||||
<url>https://gittr.ch/java/maze-server</url>
|
||||
<tag>HEAD</tag>
|
||||
</scm>
|
||||
|
||||
<distributionManagement>
|
||||
<snapshotRepository>
|
||||
<id>ossrh</id>
|
||||
<name>Sonatype Maven Repository - Snapshots</name>
|
||||
<url>https://s01.oss.sonatype.org/content/repositories/snapshots</url>
|
||||
</snapshotRepository>
|
||||
</distributionManagement>
|
||||
|
||||
<properties>
|
||||
<maze-generator.version>0.1.0</maze-generator.version>
|
||||
<maven-site-plugin.version>4.0.0-M8</maven-site-plugin.version>
|
||||
<undertow.version>2.3.5.Final</undertow.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>ch.fritteli.labyrinth</groupId>
|
||||
<artifactId>labyrinth-generator</artifactId>
|
||||
<version>${labyrinth-generator.version}</version>
|
||||
<groupId>ch.fritteli.a-maze-r</groupId>
|
||||
<artifactId>maze-generator</artifactId>
|
||||
<version>${maze-generator.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.vavr</groupId>
|
||||
|
@ -64,12 +82,10 @@
|
|||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<version>${slf4j.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>ch.qos.logback</groupId>
|
||||
<artifactId>logback-classic</artifactId>
|
||||
<version>${logback.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.undertow</groupId>
|
||||
|
@ -87,16 +103,16 @@
|
|||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.4.1</version>
|
||||
<configuration>
|
||||
<transformers>
|
||||
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
|
||||
<mainClass>ch.fritteli.labyrinth.server.Main</mainClass>
|
||||
<transformer
|
||||
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
|
||||
<mainClass>ch.fritteli.maze.server.Main</mainClass>
|
||||
</transformer>
|
||||
</transformers>
|
||||
<filters>
|
||||
<filter>
|
||||
<artifact>ch.fritteli.labyrinth:labyrinth-generator</artifact>
|
||||
<artifact>ch.fritteli.a-maze-r:maze-generator</artifact>
|
||||
<excludes>
|
||||
<exclude>logback.xml</exclude>
|
||||
</excludes>
|
||||
|
@ -128,52 +144,55 @@
|
|||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-site-plugin</artifactId>
|
||||
<version>4.0.0-M6</version>
|
||||
<version>${maven-site-plugin.version}</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<scm>
|
||||
<connection>scm:git:https://gittr.ch/java/labyrinth-server.git</connection>
|
||||
<developerConnection>scm:git:ssh://git@gittr.ch/java/labyrinth-server.git</developerConnection>
|
||||
<url>https://gittr.ch/java/labyrinth-server</url>
|
||||
<tag>HEAD</tag>
|
||||
</scm>
|
||||
<distributionManagement>
|
||||
<repository>
|
||||
<id>repo.gittr.ch</id>
|
||||
<name>gittr.ch</name>
|
||||
<url>https://repo.gittr.ch/releases/</url>
|
||||
</repository>
|
||||
<snapshotRepository>
|
||||
<id>repo.gittr.ch</id>
|
||||
<name>gittr.ch</name>
|
||||
<url>https://repo.gittr.ch/snapshots/</url>
|
||||
</snapshotRepository>
|
||||
</distributionManagement>
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>repo.gittr.ch.releases</id>
|
||||
<url>https://repo.gittr.ch/releases/</url>
|
||||
<releases>
|
||||
<enabled>true</enabled>
|
||||
<updatePolicy>never</updatePolicy>
|
||||
</releases>
|
||||
<snapshots>
|
||||
<enabled>false</enabled>
|
||||
<updatePolicy>never</updatePolicy>
|
||||
</snapshots>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>repo.gittr.ch.snapshots</id>
|
||||
<url>https://repo.gittr.ch/snapshots/</url>
|
||||
<releases>
|
||||
<enabled>false</enabled>
|
||||
<updatePolicy>never</updatePolicy>
|
||||
</releases>
|
||||
<snapshots>
|
||||
<enabled>true</enabled>
|
||||
<updatePolicy>always</updatePolicy>
|
||||
</snapshots>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<profiles>
|
||||
<profile>
|
||||
<id>release</id>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-source-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>attach-sources</id>
|
||||
<goals>
|
||||
<goal>jar-no-fork</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>attach-javadocs</id>
|
||||
<goals>
|
||||
<goal>jar</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-gpg-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>sign-artifacts</id>
|
||||
<phase>verify</phase>
|
||||
<goals>
|
||||
<goal>sign</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</profile>
|
||||
</profiles>
|
||||
</project>
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package ch.fritteli.labyrinth.server;
|
||||
package ch.fritteli.maze.server;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package ch.fritteli.labyrinth.server;
|
||||
package ch.fritteli.maze.server;
|
||||
|
||||
import lombok.experimental.UtilityClass;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
@ -8,7 +8,7 @@ import lombok.extern.slf4j.Slf4j;
|
|||
public class Main {
|
||||
|
||||
public static void main(String[] args) {
|
||||
LabyrinthServer.createAndStartServer()
|
||||
MazeServer.createAndStartServer()
|
||||
.onFailure(e -> log.error("Failed to create server. Stopping.", e));
|
||||
}
|
||||
}
|
|
@ -1,8 +1,8 @@
|
|||
package ch.fritteli.labyrinth.server;
|
||||
package ch.fritteli.maze.server;
|
||||
|
||||
import ch.fritteli.labyrinth.server.handler.CreateHandler;
|
||||
import ch.fritteli.labyrinth.server.handler.RenderV1Handler;
|
||||
import ch.fritteli.labyrinth.server.handler.RenderV2Handler;
|
||||
import ch.fritteli.maze.server.handler.CreateHandler;
|
||||
import ch.fritteli.maze.server.handler.RenderV1Handler;
|
||||
import ch.fritteli.maze.server.handler.RenderV2Handler;
|
||||
import io.undertow.Undertow;
|
||||
import io.undertow.server.RoutingHandler;
|
||||
import io.vavr.control.Try;
|
||||
|
@ -11,12 +11,12 @@ import lombok.NonNull;
|
|||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@Slf4j
|
||||
public class LabyrinthServer {
|
||||
public class MazeServer {
|
||||
|
||||
@NonNull
|
||||
private final Undertow undertow;
|
||||
|
||||
private LabyrinthServer(@NonNull final ServerConfig config) {
|
||||
private MazeServer(@NonNull final ServerConfig config) {
|
||||
final String hostAddress = config.getAddress().getHostAddress();
|
||||
final int port = config.getPort();
|
||||
log.info("Starting Server at http://{}:{}/", hostAddress, port);
|
||||
|
@ -32,15 +32,15 @@ public class LabyrinthServer {
|
|||
}
|
||||
|
||||
@NonNull
|
||||
public static Try<LabyrinthServer> createAndStartServer() {
|
||||
public static Try<MazeServer> createAndStartServer() {
|
||||
return Try.of(ServerConfig::init)
|
||||
.flatMapTry(LabyrinthServer::createAndStartServer);
|
||||
.flatMapTry(MazeServer::createAndStartServer);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static Try<LabyrinthServer> createAndStartServer(@NonNull final ServerConfig config) {
|
||||
return Try.of(() -> new LabyrinthServer(config))
|
||||
.peek(LabyrinthServer::start);
|
||||
public static Try<MazeServer> createAndStartServer(@NonNull final ServerConfig config) {
|
||||
return Try.of(() -> new MazeServer(config))
|
||||
.peek(MazeServer::start);
|
||||
}
|
||||
|
||||
private void start() {
|
|
@ -1,12 +1,12 @@
|
|||
package ch.fritteli.labyrinth.server;
|
||||
package ch.fritteli.maze.server;
|
||||
|
||||
import ch.fritteli.labyrinth.generator.model.Labyrinth;
|
||||
import ch.fritteli.labyrinth.generator.renderer.html.HTMLRenderer;
|
||||
import ch.fritteli.labyrinth.generator.renderer.json.JsonRenderer;
|
||||
import ch.fritteli.labyrinth.generator.renderer.pdf.PDFRenderer;
|
||||
import ch.fritteli.labyrinth.generator.renderer.text.TextRenderer;
|
||||
import ch.fritteli.labyrinth.generator.serialization.v1.SerializerDeserializerV1;
|
||||
import ch.fritteli.labyrinth.generator.serialization.v2.SerializerDeserializerV2;
|
||||
import ch.fritteli.maze.generator.renderer.html.HTMLRenderer;
|
||||
import ch.fritteli.maze.generator.renderer.json.JsonRenderer;
|
||||
import ch.fritteli.maze.generator.renderer.pdf.PDFRenderer;
|
||||
import ch.fritteli.maze.generator.renderer.text.TextRenderer;
|
||||
import ch.fritteli.maze.generator.serialization.v1.SerializerDeserializerV1;
|
||||
import ch.fritteli.maze.generator.serialization.v2.SerializerDeserializerV2;
|
||||
import ch.fritteli.maze.generator.model.Maze;
|
||||
import io.vavr.collection.List;
|
||||
import io.vavr.collection.Stream;
|
||||
import io.vavr.control.Option;
|
||||
|
@ -20,37 +20,37 @@ import java.util.function.Function;
|
|||
public enum OutputType {
|
||||
TEXT_PLAIN("text/plain; charset=UTF-8",
|
||||
"txt",
|
||||
labyrinth -> TextRenderer.newInstance().render(labyrinth).getBytes(StandardCharsets.UTF_8),
|
||||
maze -> TextRenderer.newInstance().render(maze).getBytes(StandardCharsets.UTF_8),
|
||||
false,
|
||||
"t",
|
||||
"text"),
|
||||
HTML("text/html",
|
||||
"html",
|
||||
labyrinth -> HTMLRenderer.newInstance().render(labyrinth).getBytes(StandardCharsets.UTF_8),
|
||||
maze -> HTMLRenderer.newInstance().render(maze).getBytes(StandardCharsets.UTF_8),
|
||||
false,
|
||||
"h",
|
||||
"html"),
|
||||
JSON("application/json",
|
||||
"json",
|
||||
labyrinth -> JsonRenderer.newInstance().render(labyrinth).getBytes(StandardCharsets.UTF_8),
|
||||
maze -> JsonRenderer.newInstance().render(maze).getBytes(StandardCharsets.UTF_8),
|
||||
false,
|
||||
"j",
|
||||
"json"),
|
||||
JSONFILE("application/json",
|
||||
"json",
|
||||
labyrinth -> JsonRenderer.newInstance().render(labyrinth).getBytes(StandardCharsets.UTF_8),
|
||||
maze -> JsonRenderer.newInstance().render(maze).getBytes(StandardCharsets.UTF_8),
|
||||
true,
|
||||
"s",
|
||||
"jsonfile"),
|
||||
PDF("application/pdf",
|
||||
"pdf",
|
||||
labyrinth -> PDFRenderer.newInstance().render(labyrinth).toByteArray(),
|
||||
maze -> PDFRenderer.newInstance().render(maze).toByteArray(),
|
||||
false,
|
||||
"p",
|
||||
"pdf"),
|
||||
PDFFILE("application/pdf",
|
||||
"pdf",
|
||||
labyrinth -> PDFRenderer.newInstance().render(labyrinth).toByteArray(),
|
||||
maze -> PDFRenderer.newInstance().render(maze).toByteArray(),
|
||||
true,
|
||||
"f",
|
||||
"pdffile"),
|
||||
|
@ -61,7 +61,7 @@ public enum OutputType {
|
|||
"b",
|
||||
"binary"),
|
||||
BINARY_V2("application/octet-stream",
|
||||
"lab2",
|
||||
"maze",
|
||||
SerializerDeserializerV2::serialize,
|
||||
true,
|
||||
"v",
|
||||
|
@ -73,7 +73,7 @@ public enum OutputType {
|
|||
@NonNull
|
||||
private final String fileExtension;
|
||||
@NonNull
|
||||
private final Function<Labyrinth, byte[]> render;
|
||||
private final Function<Maze, byte[]> render;
|
||||
@Getter
|
||||
private final boolean attachment;
|
||||
@Getter
|
||||
|
@ -82,7 +82,7 @@ public enum OutputType {
|
|||
|
||||
OutputType(@NonNull final String contentType,
|
||||
@NonNull final String fileExtension,
|
||||
@NonNull final Function<Labyrinth, byte[]> render,
|
||||
@NonNull final Function<Maze, byte[]> render,
|
||||
final boolean attachment,
|
||||
@NonNull final String... names) {
|
||||
this.contentType = contentType;
|
||||
|
@ -108,7 +108,7 @@ public enum OutputType {
|
|||
}
|
||||
|
||||
@NonNull
|
||||
public byte[] render(@NonNull final Labyrinth labyrinth) {
|
||||
return this.render.apply(labyrinth);
|
||||
public byte[] render(@NonNull final Maze maze) {
|
||||
return this.render.apply(maze);
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package ch.fritteli.labyrinth.server;
|
||||
package ch.fritteli.maze.server;
|
||||
|
||||
import io.vavr.control.Try;
|
||||
import lombok.AccessLevel;
|
||||
|
@ -14,8 +14,8 @@ import java.net.InetAddress;
|
|||
@Slf4j
|
||||
@Value
|
||||
public class ServerConfig {
|
||||
public static final String SYSPROP_HOST = "fritteli.labyrinth.server.host";
|
||||
public static final String SYSPROP_PORT = "fritteli.labyrinth.server.port";
|
||||
public static final String SYSPROP_HOST = "fritteli.maze.server.host";
|
||||
public static final String SYSPROP_PORT = "fritteli.maze.server.port";
|
||||
|
||||
@NonNull
|
||||
InetAddress address;
|
|
@ -1,4 +1,4 @@
|
|||
package ch.fritteli.labyrinth.server.handler;
|
||||
package ch.fritteli.maze.server.handler;
|
||||
|
||||
import io.undertow.server.HttpHandler;
|
||||
import io.undertow.server.HttpServerExchange;
|
|
@ -1,7 +1,7 @@
|
|||
package ch.fritteli.labyrinth.server.handler;
|
||||
package ch.fritteli.maze.server.handler;
|
||||
|
||||
import ch.fritteli.labyrinth.generator.model.Labyrinth;
|
||||
import ch.fritteli.labyrinth.server.OutputType;
|
||||
import ch.fritteli.maze.server.OutputType;
|
||||
import ch.fritteli.maze.generator.model.Maze;
|
||||
import io.undertow.server.HttpServerExchange;
|
||||
import io.undertow.util.Headers;
|
||||
import io.undertow.util.HttpString;
|
||||
|
@ -26,9 +26,9 @@ public class CreateHandler extends AbstractHttpHandler {
|
|||
protected void handle(@NonNull final HttpServerExchange exchange) {
|
||||
final Instant start = Instant.now();
|
||||
log.debug("Handling create request");
|
||||
this.createLabyrinthFromRequestParameters(exchange.getQueryParameters())
|
||||
this.createMazeFromRequestParameters(exchange.getQueryParameters())
|
||||
.onFailure(e -> {
|
||||
log.error("Error creating Labyrinth from request", e);
|
||||
log.error("Error creating maze from request", e);
|
||||
exchange.setStatusCode(StatusCodes.INTERNAL_SERVER_ERROR)
|
||||
.setReasonPhrase(StatusCodes.INTERNAL_SERVER_ERROR_STRING)
|
||||
.getResponseSender()
|
||||
|
@ -36,31 +36,33 @@ public class CreateHandler extends AbstractHttpHandler {
|
|||
})
|
||||
.forEach(tuple -> {
|
||||
final OutputType outputType = tuple._1();
|
||||
final Labyrinth labyrinth = tuple._2();
|
||||
final Maze maze = tuple._2();
|
||||
final byte[] bytes;
|
||||
try {
|
||||
bytes = outputType.render(labyrinth);
|
||||
bytes = outputType.render(maze);
|
||||
} catch (@NonNull final Exception e) {
|
||||
log.error("Error rendering Labyrinth", e);
|
||||
log.error("Error rendering Maze", e);
|
||||
exchange.setStatusCode(StatusCodes.INTERNAL_SERVER_ERROR)
|
||||
.setReasonPhrase(StatusCodes.INTERNAL_SERVER_ERROR_STRING)
|
||||
.getResponseSender()
|
||||
.send("Error creating the Labyrinth. Please contact the administrator. Request id=%s".formatted(MDC.get("correlationId")));
|
||||
.send("Error creating the maze. Please contact the administrator. Request id=%s".formatted(MDC.get("correlationId")));
|
||||
return;
|
||||
}
|
||||
final long durationMillis = start.until(Instant.now(), ChronoUnit.MILLIS);
|
||||
exchange.getResponseHeaders()
|
||||
.put(Headers.CONTENT_TYPE, outputType.getContentType())
|
||||
.put(HttpString.tryFromString("X-Labyrinth-ID"), String.valueOf(labyrinth.getRandomSeed()))
|
||||
.put(HttpString.tryFromString("X-Labyrinth-Width"), String.valueOf(labyrinth.getWidth()))
|
||||
.put(HttpString.tryFromString("X-Labyrinth-Height"), String.valueOf(labyrinth.getHeight()))
|
||||
.put(HttpString.tryFromString("X-Labyrinth-Generation-Duration-millis"), String.valueOf(durationMillis));
|
||||
.put(HttpString.tryFromString("X-Maze-ID"), String.valueOf(maze.getRandomSeed()))
|
||||
.put(HttpString.tryFromString("X-Maze-Width"), String.valueOf(maze.getWidth()))
|
||||
.put(HttpString.tryFromString("X-Maze-Height"), String.valueOf(maze.getHeight()))
|
||||
// TODO read the algorithm from the maze once this is supported.
|
||||
.put(HttpString.tryFromString("X-Maze-Algorithm"), "RandomDepthFirst")
|
||||
.put(HttpString.tryFromString("X-Maze-Generation-Duration-millis"), String.valueOf(durationMillis));
|
||||
if (outputType.isAttachment()) {
|
||||
exchange.getResponseHeaders()
|
||||
.put(Headers.CONTENT_DISPOSITION, "attachment; filename=\"labyrinth-%dx%d-%d.%s\"".formatted(
|
||||
labyrinth.getWidth(),
|
||||
labyrinth.getHeight(),
|
||||
labyrinth.getRandomSeed(),
|
||||
.put(Headers.CONTENT_DISPOSITION, "attachment; filename=\"maze-%dx%d-%d.%s\"".formatted(
|
||||
maze.getWidth(),
|
||||
maze.getHeight(),
|
||||
maze.getRandomSeed(),
|
||||
outputType.getFileExtension()
|
||||
));
|
||||
}
|
||||
|
@ -70,7 +72,7 @@ public class CreateHandler extends AbstractHttpHandler {
|
|||
}
|
||||
|
||||
@NonNull
|
||||
private Try<Tuple2<OutputType, Labyrinth>> createLabyrinthFromRequestParameters(final Map<String, Deque<String>> queryParameters) {
|
||||
return new ParametersToLabyrinthExtractor(queryParameters).createLabyrinth();
|
||||
private Try<Tuple2<OutputType, Maze>> createMazeFromRequestParameters(final Map<String, Deque<String>> queryParameters) {
|
||||
return new ParametersToMazeExtractor(queryParameters).createMaze();
|
||||
}
|
||||
}
|
|
@ -1,28 +1,29 @@
|
|||
package ch.fritteli.labyrinth.server.handler;
|
||||
package ch.fritteli.maze.server.handler;
|
||||
|
||||
import ch.fritteli.labyrinth.generator.Generator;
|
||||
import ch.fritteli.labyrinth.generator.model.Labyrinth;
|
||||
import ch.fritteli.labyrinth.generator.model.Position;
|
||||
import ch.fritteli.labyrinth.server.OutputType;
|
||||
import ch.fritteli.maze.server.OutputType;
|
||||
import ch.fritteli.maze.generator.algorithm.RandomDepthFirst;
|
||||
import ch.fritteli.maze.generator.model.Maze;
|
||||
import ch.fritteli.maze.generator.model.Position;
|
||||
import io.vavr.Tuple;
|
||||
import io.vavr.Tuple2;
|
||||
import io.vavr.collection.Stream;
|
||||
import io.vavr.control.Option;
|
||||
import io.vavr.control.Try;
|
||||
import java.util.Deque;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import lombok.NonNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import java.util.Deque;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
class ParametersToLabyrinthExtractor {
|
||||
class ParametersToMazeExtractor {
|
||||
|
||||
@NonNull
|
||||
private final Map<String, Deque<String>> queryParameters;
|
||||
|
||||
@NonNull
|
||||
Try<Tuple2<OutputType, Labyrinth>> createLabyrinth() {
|
||||
Try<Tuple2<OutputType, Maze>> createMaze() {
|
||||
final Option<OutputType> output = getParameterValue(RequestParameter.OUTPUT);
|
||||
final Option<Integer> width = getParameterValue(RequestParameter.WIDTH);
|
||||
final Option<Integer> height = getParameterValue(RequestParameter.HEIGHT);
|
||||
|
@ -50,14 +51,14 @@ class ParametersToLabyrinthExtractor {
|
|||
}
|
||||
|
||||
return Try.of(() -> {
|
||||
final Labyrinth labyrinth;
|
||||
final Maze maze;
|
||||
if (start.isDefined() && end.isDefined()) {
|
||||
labyrinth = new Labyrinth(width.get(), height.get(), id.getOrElse(() -> new Random().nextLong()), start.get(), end.get());
|
||||
maze = new Maze(width.get(), height.get(), id.getOrElse(() -> new Random().nextLong()), start.get(), end.get());
|
||||
} else {
|
||||
labyrinth = new Labyrinth(width.get(), height.get(), id.getOrElse(() -> new Random().nextLong()));
|
||||
maze = new Maze(width.get(), height.get(), id.getOrElse(() -> new Random().nextLong()));
|
||||
}
|
||||
new Generator(labyrinth).run();
|
||||
return Tuple.of(output.get(), labyrinth);
|
||||
new RandomDepthFirst(maze).run();
|
||||
return Tuple.of(output.get(), maze);
|
||||
});
|
||||
}
|
||||
|
|
@ -1,16 +1,17 @@
|
|||
package ch.fritteli.labyrinth.server.handler;
|
||||
package ch.fritteli.maze.server.handler;
|
||||
|
||||
import ch.fritteli.labyrinth.generator.model.Labyrinth;
|
||||
import ch.fritteli.labyrinth.generator.serialization.v1.SerializerDeserializerV1;
|
||||
import ch.fritteli.labyrinth.server.OutputType;
|
||||
import ch.fritteli.maze.server.OutputType;
|
||||
import ch.fritteli.maze.generator.model.Maze;
|
||||
import ch.fritteli.maze.generator.serialization.v1.SerializerDeserializerV1;
|
||||
import io.undertow.server.HttpServerExchange;
|
||||
import io.undertow.util.HeaderValues;
|
||||
import io.undertow.util.Headers;
|
||||
import io.undertow.util.StatusCodes;
|
||||
import java.nio.ByteBuffer;
|
||||
import lombok.NonNull;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
@Slf4j
|
||||
public class RenderV1Handler extends AbstractHttpHandler {
|
||||
|
||||
|
@ -28,13 +29,13 @@ public class RenderV1Handler extends AbstractHttpHandler {
|
|||
final OutputType output = this.getOutputType(httpServerExchange);
|
||||
final byte[] render;
|
||||
try {
|
||||
final Labyrinth labyrinth = SerializerDeserializerV1.deserialize(bytes);
|
||||
render = output.render(labyrinth);
|
||||
final Maze maze = SerializerDeserializerV1.deserialize(bytes);
|
||||
render = output.render(maze);
|
||||
} catch (final Exception e) {
|
||||
log.error("Error rendering binary labyrinth data", e);
|
||||
log.error("Error rendering binary maze data", e);
|
||||
httpServerExchange.setStatusCode(StatusCodes.INTERNAL_SERVER_ERROR)
|
||||
.getResponseSender()
|
||||
.send("Error rendering labyrinth: %s".formatted(e.getMessage()));
|
||||
.send("Error rendering maze: %s".formatted(e.getMessage()));
|
||||
return;
|
||||
}
|
||||
httpServerExchange
|
|
@ -1,16 +1,17 @@
|
|||
package ch.fritteli.labyrinth.server.handler;
|
||||
package ch.fritteli.maze.server.handler;
|
||||
|
||||
import ch.fritteli.labyrinth.generator.model.Labyrinth;
|
||||
import ch.fritteli.labyrinth.generator.serialization.v2.SerializerDeserializerV2;
|
||||
import ch.fritteli.labyrinth.server.OutputType;
|
||||
import ch.fritteli.maze.server.OutputType;
|
||||
import ch.fritteli.maze.generator.model.Maze;
|
||||
import ch.fritteli.maze.generator.serialization.v2.SerializerDeserializerV2;
|
||||
import io.undertow.server.HttpServerExchange;
|
||||
import io.undertow.util.HeaderValues;
|
||||
import io.undertow.util.Headers;
|
||||
import io.undertow.util.StatusCodes;
|
||||
import java.nio.ByteBuffer;
|
||||
import lombok.NonNull;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
@Slf4j
|
||||
public class RenderV2Handler extends AbstractHttpHandler {
|
||||
|
||||
|
@ -28,13 +29,13 @@ public class RenderV2Handler extends AbstractHttpHandler {
|
|||
final OutputType output = this.getOutputType(httpServerExchange);
|
||||
final byte[] render;
|
||||
try {
|
||||
final Labyrinth labyrinth = SerializerDeserializerV2.deserialize(bytes);
|
||||
render = output.render(labyrinth);
|
||||
final Maze maze = SerializerDeserializerV2.deserialize(bytes);
|
||||
render = output.render(maze);
|
||||
} catch (final Exception e) {
|
||||
log.error("Error rendering binary labyrinth data", e);
|
||||
log.error("Error rendering binary maze data", e);
|
||||
httpServerExchange.setStatusCode(StatusCodes.INTERNAL_SERVER_ERROR)
|
||||
.getResponseSender()
|
||||
.send("Error rendering labyrinth: %s".formatted(e.getMessage()));
|
||||
.send("Error rendering maze: %s".formatted(e.getMessage()));
|
||||
return;
|
||||
}
|
||||
httpServerExchange
|
|
@ -1,20 +1,21 @@
|
|||
package ch.fritteli.labyrinth.server.handler;
|
||||
package ch.fritteli.maze.server.handler;
|
||||
|
||||
import ch.fritteli.labyrinth.generator.model.Position;
|
||||
import ch.fritteli.labyrinth.server.OutputType;
|
||||
import ch.fritteli.maze.server.OutputType;
|
||||
import ch.fritteli.maze.generator.model.Position;
|
||||
import io.vavr.Tuple2;
|
||||
import io.vavr.collection.HashMap;
|
||||
import io.vavr.collection.HashSet;
|
||||
import io.vavr.collection.Set;
|
||||
import io.vavr.control.Option;
|
||||
import io.vavr.control.Try;
|
||||
import java.util.Deque;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
import lombok.Getter;
|
||||
import lombok.NonNull;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.util.Deque;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
|
||||
@Slf4j
|
||||
enum RequestParameter {
|
||||
WIDTH(p -> Try.of(() -> Integer.parseInt(p))
|
|
@ -13,5 +13,5 @@
|
|||
<root level="info">
|
||||
<appender-ref ref="STDOUT"/>
|
||||
</root>
|
||||
<logger name="ch.fritteli.labyrinth.*" level="debug"/>
|
||||
<logger name="ch.fritteli.maze.*" level="debug"/>
|
||||
</configuration>
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package ch.fritteli.labyrinth.server;
|
||||
package ch.fritteli.maze.server;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
Loading…
Reference in a new issue