feature/rename-to-maze #8

Merged
manuel merged 2 commits from feature/rename-to-maze into master 2023-05-16 03:14:37 +02:00
18 changed files with 129 additions and 129 deletions
Showing only changes of commit ca8f2bfec7 - Show all commits

View file

@ -26,6 +26,8 @@ steps:
environment: environment:
REPO_TOKEN: REPO_TOKEN:
from_secret: repo-token from_secret: repo-token
REPO_TOKEN_OSSRH:
from_secret: repo-token-ossrh
commands: commands:
- mvn -s maven-settings.xml deploy -DskipTests=true - mvn -s maven-settings.xml deploy -DskipTests=true
when: when:
@ -41,7 +43,7 @@ steps:
username: manuel username: manuel
password: password:
from_secret: docker-token from_secret: docker-token
repo: gittr.ch/java/labyrinth repo: gittr.ch/java/a-maze-r
tags: tags:
- latest - latest
dockerfile: docker/Dockerfile dockerfile: docker/Dockerfile
@ -59,7 +61,7 @@ steps:
username: manuel username: manuel
password: password:
from_secret: docker-token from_secret: docker-token
repo: gittr.ch/java/labyrinth repo: gittr.ch/java/a-maze-r
tags: tags:
- latest - latest
- ${DRONE_TAG} - ${DRONE_TAG}

View file

@ -1,2 +1 @@
# labyrinth-server # maze-server

View file

@ -1,7 +1,7 @@
FROM openjdk:17-slim FROM openjdk:17-slim
COPY target/labyrinth-server-*.jar /app/ COPY target/maze-server-*.jar /app/
RUN rm /app/*-sources.jar RUN rm /app/*-sources.jar
RUN mv /app/*.jar /app/app.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

View file

@ -8,5 +8,10 @@
<username>ci</username> <username>ci</username>
<password>${env.REPO_TOKEN}</password> <password>${env.REPO_TOKEN}</password>
</server> </server>
<server>
<id>ossrh</id>
<username>fritteli</username>
<password>${env.REPO_TOKEN_OSSRH}</password>
</server>
</servers> </servers>
</settings> </settings>

40
pom.xml
View file

@ -5,26 +5,18 @@
<parent> <parent>
<groupId>ch.fritteli</groupId> <groupId>ch.fritteli</groupId>
<artifactId>fritteli-build-parent</artifactId> <artifactId>fritteli-build-parent</artifactId>
<version>2.0.4</version> <version>5.0.0</version>
</parent> </parent>
<groupId>ch.fritteli.labyrinth</groupId> <groupId>ch.fritteli.a-maze-r</groupId>
<artifactId>labyrinth-server</artifactId> <artifactId>maze-server</artifactId>
<version>0.0.7-SNAPSHOT</version> <version>0.0.7-SNAPSHOT</version>
<description>The Labyrinth server, offering a REST endpoint to access the Labyrinth Generator.</description> <description>The A-Maze-R server, offering a REST endpoint to access the Maze Generator.</description>
<url>https://manuel.friedli.info/labyrinth.html</url> <url>https://manuel.friedli.info/maze.html</url>
<properties> <properties>
<java.source.version>17</java.source.version> <maze-generator.version>0.1.0</maze-generator.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> <undertow.version>2.3.5.Final</undertow.version>
<vavr.version>0.10.4</vavr.version>
</properties> </properties>
<developers> <developers>
@ -45,9 +37,9 @@
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>ch.fritteli.labyrinth</groupId> <groupId>ch.fritteli.a-maze-r</groupId>
<artifactId>labyrinth-generator</artifactId> <artifactId>maze-generator</artifactId>
<version>${labyrinth-generator.version}</version> <version>${maze-generator.version}</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>io.vavr</groupId> <groupId>io.vavr</groupId>
@ -64,12 +56,10 @@
<dependency> <dependency>
<groupId>org.slf4j</groupId> <groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId> <artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>ch.qos.logback</groupId> <groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId> <artifactId>logback-classic</artifactId>
<version>${logback.version}</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>io.undertow</groupId> <groupId>io.undertow</groupId>
@ -87,16 +77,15 @@
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId> <artifactId>maven-shade-plugin</artifactId>
<version>3.4.1</version>
<configuration> <configuration>
<transformers> <transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>ch.fritteli.labyrinth.server.Main</mainClass> <mainClass>ch.fritteli.maze.server.Main</mainClass>
</transformer> </transformer>
</transformers> </transformers>
<filters> <filters>
<filter> <filter>
<artifact>ch.fritteli.labyrinth:labyrinth-generator</artifact> <artifact>ch.fritteli.a-maze-r:maze-generator</artifact>
<excludes> <excludes>
<exclude>logback.xml</exclude> <exclude>logback.xml</exclude>
</excludes> </excludes>
@ -128,14 +117,13 @@
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId> <artifactId>maven-site-plugin</artifactId>
<version>4.0.0-M6</version>
</plugin> </plugin>
</plugins> </plugins>
</build> </build>
<scm> <scm>
<connection>scm:git:https://gittr.ch/java/labyrinth-server.git</connection> <connection>scm:git:https://gittr.ch/java/maze-server.git</connection>
<developerConnection>scm:git:ssh://git@gittr.ch/java/labyrinth-server.git</developerConnection> <developerConnection>scm:git:ssh://git@gittr.ch/java/maze-server.git</developerConnection>
<url>https://gittr.ch/java/labyrinth-server</url> <url>https://gittr.ch/java/maze-server</url>
<tag>HEAD</tag> <tag>HEAD</tag>
</scm> </scm>
<distributionManagement> <distributionManagement>

View file

@ -1,4 +1,4 @@
package ch.fritteli.labyrinth.server; package ch.fritteli.maze.server;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;

View file

@ -1,4 +1,4 @@
package ch.fritteli.labyrinth.server; package ch.fritteli.maze.server;
import lombok.experimental.UtilityClass; import lombok.experimental.UtilityClass;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@ -8,7 +8,7 @@ import lombok.extern.slf4j.Slf4j;
public class Main { public class Main {
public static void main(String[] args) { public static void main(String[] args) {
LabyrinthServer.createAndStartServer() MazeServer.createAndStartServer()
.onFailure(e -> log.error("Failed to create server. Stopping.", e)); .onFailure(e -> log.error("Failed to create server. Stopping.", e));
} }
} }

View file

@ -1,8 +1,8 @@
package ch.fritteli.labyrinth.server; package ch.fritteli.maze.server;
import ch.fritteli.labyrinth.server.handler.CreateHandler; import ch.fritteli.maze.server.handler.CreateHandler;
import ch.fritteli.labyrinth.server.handler.RenderV1Handler; import ch.fritteli.maze.server.handler.RenderV1Handler;
import ch.fritteli.labyrinth.server.handler.RenderV2Handler; import ch.fritteli.maze.server.handler.RenderV2Handler;
import io.undertow.Undertow; import io.undertow.Undertow;
import io.undertow.server.RoutingHandler; import io.undertow.server.RoutingHandler;
import io.vavr.control.Try; import io.vavr.control.Try;
@ -11,12 +11,12 @@ import lombok.NonNull;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@Slf4j @Slf4j
public class LabyrinthServer { public class MazeServer {
@NonNull @NonNull
private final Undertow undertow; private final Undertow undertow;
private LabyrinthServer(@NonNull final ServerConfig config) { private MazeServer(@NonNull final ServerConfig config) {
final String hostAddress = config.getAddress().getHostAddress(); final String hostAddress = config.getAddress().getHostAddress();
final int port = config.getPort(); final int port = config.getPort();
log.info("Starting Server at http://{}:{}/", hostAddress, port); log.info("Starting Server at http://{}:{}/", hostAddress, port);
@ -32,15 +32,15 @@ public class LabyrinthServer {
} }
@NonNull @NonNull
public static Try<LabyrinthServer> createAndStartServer() { public static Try<MazeServer> createAndStartServer() {
return Try.of(ServerConfig::init) return Try.of(ServerConfig::init)
.flatMapTry(LabyrinthServer::createAndStartServer); .flatMapTry(MazeServer::createAndStartServer);
} }
@NonNull @NonNull
public static Try<LabyrinthServer> createAndStartServer(@NonNull final ServerConfig config) { public static Try<MazeServer> createAndStartServer(@NonNull final ServerConfig config) {
return Try.of(() -> new LabyrinthServer(config)) return Try.of(() -> new MazeServer(config))
.peek(LabyrinthServer::start); .peek(MazeServer::start);
} }
private void start() { private void start() {

View file

@ -1,12 +1,12 @@
package ch.fritteli.labyrinth.server; package ch.fritteli.maze.server;
import ch.fritteli.labyrinth.generator.model.Labyrinth; import ch.fritteli.maze.generator.renderer.html.HTMLRenderer;
import ch.fritteli.labyrinth.generator.renderer.html.HTMLRenderer; import ch.fritteli.maze.generator.renderer.json.JsonRenderer;
import ch.fritteli.labyrinth.generator.renderer.json.JsonRenderer; import ch.fritteli.maze.generator.renderer.pdf.PDFRenderer;
import ch.fritteli.labyrinth.generator.renderer.pdf.PDFRenderer; import ch.fritteli.maze.generator.renderer.text.TextRenderer;
import ch.fritteli.labyrinth.generator.renderer.text.TextRenderer; import ch.fritteli.maze.generator.serialization.v1.SerializerDeserializerV1;
import ch.fritteli.labyrinth.generator.serialization.v1.SerializerDeserializerV1; import ch.fritteli.maze.generator.serialization.v2.SerializerDeserializerV2;
import ch.fritteli.labyrinth.generator.serialization.v2.SerializerDeserializerV2; import ch.fritteli.maze.generator.model.Maze;
import io.vavr.collection.List; import io.vavr.collection.List;
import io.vavr.collection.Stream; import io.vavr.collection.Stream;
import io.vavr.control.Option; import io.vavr.control.Option;
@ -20,37 +20,37 @@ import java.util.function.Function;
public enum OutputType { public enum OutputType {
TEXT_PLAIN("text/plain; charset=UTF-8", TEXT_PLAIN("text/plain; charset=UTF-8",
"txt", "txt",
labyrinth -> TextRenderer.newInstance().render(labyrinth).getBytes(StandardCharsets.UTF_8), maze -> TextRenderer.newInstance().render(maze).getBytes(StandardCharsets.UTF_8),
false, false,
"t", "t",
"text"), "text"),
HTML("text/html", HTML("text/html",
"html", "html",
labyrinth -> HTMLRenderer.newInstance().render(labyrinth).getBytes(StandardCharsets.UTF_8), maze -> HTMLRenderer.newInstance().render(maze).getBytes(StandardCharsets.UTF_8),
false, false,
"h", "h",
"html"), "html"),
JSON("application/json", JSON("application/json",
"json", "json",
labyrinth -> JsonRenderer.newInstance().render(labyrinth).getBytes(StandardCharsets.UTF_8), maze -> JsonRenderer.newInstance().render(maze).getBytes(StandardCharsets.UTF_8),
false, false,
"j", "j",
"json"), "json"),
JSONFILE("application/json", JSONFILE("application/json",
"json", "json",
labyrinth -> JsonRenderer.newInstance().render(labyrinth).getBytes(StandardCharsets.UTF_8), maze -> JsonRenderer.newInstance().render(maze).getBytes(StandardCharsets.UTF_8),
true, true,
"s", "s",
"jsonfile"), "jsonfile"),
PDF("application/pdf", PDF("application/pdf",
"pdf", "pdf",
labyrinth -> PDFRenderer.newInstance().render(labyrinth).toByteArray(), maze -> PDFRenderer.newInstance().render(maze).toByteArray(),
false, false,
"p", "p",
"pdf"), "pdf"),
PDFFILE("application/pdf", PDFFILE("application/pdf",
"pdf", "pdf",
labyrinth -> PDFRenderer.newInstance().render(labyrinth).toByteArray(), maze -> PDFRenderer.newInstance().render(maze).toByteArray(),
true, true,
"f", "f",
"pdffile"), "pdffile"),
@ -61,7 +61,7 @@ public enum OutputType {
"b", "b",
"binary"), "binary"),
BINARY_V2("application/octet-stream", BINARY_V2("application/octet-stream",
"lab2", "maze",
SerializerDeserializerV2::serialize, SerializerDeserializerV2::serialize,
true, true,
"v", "v",
@ -73,7 +73,7 @@ public enum OutputType {
@NonNull @NonNull
private final String fileExtension; private final String fileExtension;
@NonNull @NonNull
private final Function<Labyrinth, byte[]> render; private final Function<Maze, byte[]> render;
@Getter @Getter
private final boolean attachment; private final boolean attachment;
@Getter @Getter
@ -82,7 +82,7 @@ public enum OutputType {
OutputType(@NonNull final String contentType, OutputType(@NonNull final String contentType,
@NonNull final String fileExtension, @NonNull final String fileExtension,
@NonNull final Function<Labyrinth, byte[]> render, @NonNull final Function<Maze, byte[]> render,
final boolean attachment, final boolean attachment,
@NonNull final String... names) { @NonNull final String... names) {
this.contentType = contentType; this.contentType = contentType;
@ -108,7 +108,7 @@ public enum OutputType {
} }
@NonNull @NonNull
public byte[] render(@NonNull final Labyrinth labyrinth) { public byte[] render(@NonNull final Maze maze) {
return this.render.apply(labyrinth); return this.render.apply(maze);
} }
} }

View file

@ -1,4 +1,4 @@
package ch.fritteli.labyrinth.server; package ch.fritteli.maze.server;
import io.vavr.control.Try; import io.vavr.control.Try;
import lombok.AccessLevel; import lombok.AccessLevel;
@ -14,8 +14,8 @@ import java.net.InetAddress;
@Slf4j @Slf4j
@Value @Value
public class ServerConfig { public class ServerConfig {
public static final String SYSPROP_HOST = "fritteli.labyrinth.server.host"; public static final String SYSPROP_HOST = "fritteli.maze.server.host";
public static final String SYSPROP_PORT = "fritteli.labyrinth.server.port"; public static final String SYSPROP_PORT = "fritteli.maze.server.port";
@NonNull @NonNull
InetAddress address; InetAddress address;

View file

@ -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.HttpHandler;
import io.undertow.server.HttpServerExchange; import io.undertow.server.HttpServerExchange;

View file

@ -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.maze.server.OutputType;
import ch.fritteli.labyrinth.server.OutputType; import ch.fritteli.maze.generator.model.Maze;
import io.undertow.server.HttpServerExchange; import io.undertow.server.HttpServerExchange;
import io.undertow.util.Headers; import io.undertow.util.Headers;
import io.undertow.util.HttpString; import io.undertow.util.HttpString;
@ -26,9 +26,9 @@ public class CreateHandler extends AbstractHttpHandler {
protected void handle(@NonNull final HttpServerExchange exchange) { protected void handle(@NonNull final HttpServerExchange exchange) {
final Instant start = Instant.now(); final Instant start = Instant.now();
log.debug("Handling create request"); log.debug("Handling create request");
this.createLabyrinthFromRequestParameters(exchange.getQueryParameters()) this.createMazeFromRequestParameters(exchange.getQueryParameters())
.onFailure(e -> { .onFailure(e -> {
log.error("Error creating Labyrinth from request", e); log.error("Error creating maze from request", e);
exchange.setStatusCode(StatusCodes.INTERNAL_SERVER_ERROR) exchange.setStatusCode(StatusCodes.INTERNAL_SERVER_ERROR)
.setReasonPhrase(StatusCodes.INTERNAL_SERVER_ERROR_STRING) .setReasonPhrase(StatusCodes.INTERNAL_SERVER_ERROR_STRING)
.getResponseSender() .getResponseSender()
@ -36,31 +36,33 @@ public class CreateHandler extends AbstractHttpHandler {
}) })
.forEach(tuple -> { .forEach(tuple -> {
final OutputType outputType = tuple._1(); final OutputType outputType = tuple._1();
final Labyrinth labyrinth = tuple._2(); final Maze maze = tuple._2();
final byte[] bytes; final byte[] bytes;
try { try {
bytes = outputType.render(labyrinth); bytes = outputType.render(maze);
} catch (@NonNull final Exception e) { } catch (@NonNull final Exception e) {
log.error("Error rendering Labyrinth", e); log.error("Error rendering Maze", e);
exchange.setStatusCode(StatusCodes.INTERNAL_SERVER_ERROR) exchange.setStatusCode(StatusCodes.INTERNAL_SERVER_ERROR)
.setReasonPhrase(StatusCodes.INTERNAL_SERVER_ERROR_STRING) .setReasonPhrase(StatusCodes.INTERNAL_SERVER_ERROR_STRING)
.getResponseSender() .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; return;
} }
final long durationMillis = start.until(Instant.now(), ChronoUnit.MILLIS); final long durationMillis = start.until(Instant.now(), ChronoUnit.MILLIS);
exchange.getResponseHeaders() exchange.getResponseHeaders()
.put(Headers.CONTENT_TYPE, outputType.getContentType()) .put(Headers.CONTENT_TYPE, outputType.getContentType())
.put(HttpString.tryFromString("X-Labyrinth-ID"), String.valueOf(labyrinth.getRandomSeed())) .put(HttpString.tryFromString("X-Maze-ID"), String.valueOf(maze.getRandomSeed()))
.put(HttpString.tryFromString("X-Labyrinth-Width"), String.valueOf(labyrinth.getWidth())) .put(HttpString.tryFromString("X-Maze-Width"), String.valueOf(maze.getWidth()))
.put(HttpString.tryFromString("X-Labyrinth-Height"), String.valueOf(labyrinth.getHeight())) .put(HttpString.tryFromString("X-Maze-Height"), String.valueOf(maze.getHeight()))
.put(HttpString.tryFromString("X-Labyrinth-Generation-Duration-millis"), String.valueOf(durationMillis)); // 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()) { if (outputType.isAttachment()) {
exchange.getResponseHeaders() exchange.getResponseHeaders()
.put(Headers.CONTENT_DISPOSITION, "attachment; filename=\"labyrinth-%dx%d-%d.%s\"".formatted( .put(Headers.CONTENT_DISPOSITION, "attachment; filename=\"maze-%dx%d-%d.%s\"".formatted(
labyrinth.getWidth(), maze.getWidth(),
labyrinth.getHeight(), maze.getHeight(),
labyrinth.getRandomSeed(), maze.getRandomSeed(),
outputType.getFileExtension() outputType.getFileExtension()
)); ));
} }
@ -70,7 +72,7 @@ public class CreateHandler extends AbstractHttpHandler {
} }
@NonNull @NonNull
private Try<Tuple2<OutputType, Labyrinth>> createLabyrinthFromRequestParameters(final Map<String, Deque<String>> queryParameters) { private Try<Tuple2<OutputType, Maze>> createMazeFromRequestParameters(final Map<String, Deque<String>> queryParameters) {
return new ParametersToLabyrinthExtractor(queryParameters).createLabyrinth(); return new ParametersToMazeExtractor(queryParameters).createMaze();
} }
} }

View file

@ -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.maze.server.OutputType;
import ch.fritteli.labyrinth.generator.model.Labyrinth; import ch.fritteli.maze.generator.algorithm.RandomDepthFirst;
import ch.fritteli.labyrinth.generator.model.Position; import ch.fritteli.maze.generator.model.Maze;
import ch.fritteli.labyrinth.server.OutputType; import ch.fritteli.maze.generator.model.Position;
import io.vavr.Tuple; import io.vavr.Tuple;
import io.vavr.Tuple2; import io.vavr.Tuple2;
import io.vavr.collection.Stream; import io.vavr.collection.Stream;
import io.vavr.control.Option; import io.vavr.control.Option;
import io.vavr.control.Try; import io.vavr.control.Try;
import java.util.Deque;
import java.util.Map;
import java.util.Random;
import lombok.NonNull; import lombok.NonNull;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import java.util.Deque;
import java.util.Map;
import java.util.Random;
@RequiredArgsConstructor @RequiredArgsConstructor
class ParametersToLabyrinthExtractor { class ParametersToMazeExtractor {
@NonNull @NonNull
private final Map<String, Deque<String>> queryParameters; private final Map<String, Deque<String>> queryParameters;
@NonNull @NonNull
Try<Tuple2<OutputType, Labyrinth>> createLabyrinth() { Try<Tuple2<OutputType, Maze>> createMaze() {
final Option<OutputType> output = getParameterValue(RequestParameter.OUTPUT); final Option<OutputType> output = getParameterValue(RequestParameter.OUTPUT);
final Option<Integer> width = getParameterValue(RequestParameter.WIDTH); final Option<Integer> width = getParameterValue(RequestParameter.WIDTH);
final Option<Integer> height = getParameterValue(RequestParameter.HEIGHT); final Option<Integer> height = getParameterValue(RequestParameter.HEIGHT);
@ -50,14 +51,14 @@ class ParametersToLabyrinthExtractor {
} }
return Try.of(() -> { return Try.of(() -> {
final Labyrinth labyrinth; final Maze maze;
if (start.isDefined() && end.isDefined()) { 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 { } 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(); new RandomDepthFirst(maze).run();
return Tuple.of(output.get(), labyrinth); return Tuple.of(output.get(), maze);
}); });
} }

View file

@ -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.maze.server.OutputType;
import ch.fritteli.labyrinth.generator.serialization.v1.SerializerDeserializerV1; import ch.fritteli.maze.generator.model.Maze;
import ch.fritteli.labyrinth.server.OutputType; import ch.fritteli.maze.generator.serialization.v1.SerializerDeserializerV1;
import io.undertow.server.HttpServerExchange; import io.undertow.server.HttpServerExchange;
import io.undertow.util.HeaderValues; import io.undertow.util.HeaderValues;
import io.undertow.util.Headers; import io.undertow.util.Headers;
import io.undertow.util.StatusCodes; import io.undertow.util.StatusCodes;
import java.nio.ByteBuffer;
import lombok.NonNull; import lombok.NonNull;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import java.nio.ByteBuffer;
@Slf4j @Slf4j
public class RenderV1Handler extends AbstractHttpHandler { public class RenderV1Handler extends AbstractHttpHandler {
@ -28,13 +29,13 @@ public class RenderV1Handler extends AbstractHttpHandler {
final OutputType output = this.getOutputType(httpServerExchange); final OutputType output = this.getOutputType(httpServerExchange);
final byte[] render; final byte[] render;
try { try {
final Labyrinth labyrinth = SerializerDeserializerV1.deserialize(bytes); final Maze maze = SerializerDeserializerV1.deserialize(bytes);
render = output.render(labyrinth); render = output.render(maze);
} catch (final Exception e) { } 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) httpServerExchange.setStatusCode(StatusCodes.INTERNAL_SERVER_ERROR)
.getResponseSender() .getResponseSender()
.send("Error rendering labyrinth: %s".formatted(e.getMessage())); .send("Error rendering maze: %s".formatted(e.getMessage()));
return; return;
} }
httpServerExchange httpServerExchange

View file

@ -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.maze.server.OutputType;
import ch.fritteli.labyrinth.generator.serialization.v2.SerializerDeserializerV2; import ch.fritteli.maze.generator.model.Maze;
import ch.fritteli.labyrinth.server.OutputType; import ch.fritteli.maze.generator.serialization.v2.SerializerDeserializerV2;
import io.undertow.server.HttpServerExchange; import io.undertow.server.HttpServerExchange;
import io.undertow.util.HeaderValues; import io.undertow.util.HeaderValues;
import io.undertow.util.Headers; import io.undertow.util.Headers;
import io.undertow.util.StatusCodes; import io.undertow.util.StatusCodes;
import java.nio.ByteBuffer;
import lombok.NonNull; import lombok.NonNull;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import java.nio.ByteBuffer;
@Slf4j @Slf4j
public class RenderV2Handler extends AbstractHttpHandler { public class RenderV2Handler extends AbstractHttpHandler {
@ -28,13 +29,13 @@ public class RenderV2Handler extends AbstractHttpHandler {
final OutputType output = this.getOutputType(httpServerExchange); final OutputType output = this.getOutputType(httpServerExchange);
final byte[] render; final byte[] render;
try { try {
final Labyrinth labyrinth = SerializerDeserializerV2.deserialize(bytes); final Maze maze = SerializerDeserializerV2.deserialize(bytes);
render = output.render(labyrinth); render = output.render(maze);
} catch (final Exception e) { } 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) httpServerExchange.setStatusCode(StatusCodes.INTERNAL_SERVER_ERROR)
.getResponseSender() .getResponseSender()
.send("Error rendering labyrinth: %s".formatted(e.getMessage())); .send("Error rendering maze: %s".formatted(e.getMessage()));
return; return;
} }
httpServerExchange httpServerExchange

View file

@ -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.maze.server.OutputType;
import ch.fritteli.labyrinth.server.OutputType; import ch.fritteli.maze.generator.model.Position;
import io.vavr.Tuple2; import io.vavr.Tuple2;
import io.vavr.collection.HashMap; import io.vavr.collection.HashMap;
import io.vavr.collection.HashSet; import io.vavr.collection.HashSet;
import io.vavr.collection.Set; import io.vavr.collection.Set;
import io.vavr.control.Option; import io.vavr.control.Option;
import io.vavr.control.Try; import io.vavr.control.Try;
import java.util.Deque;
import java.util.Map;
import java.util.function.Function;
import lombok.Getter; import lombok.Getter;
import lombok.NonNull; import lombok.NonNull;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import java.util.Deque;
import java.util.Map;
import java.util.function.Function;
@Slf4j @Slf4j
enum RequestParameter { enum RequestParameter {
WIDTH(p -> Try.of(() -> Integer.parseInt(p)) WIDTH(p -> Try.of(() -> Integer.parseInt(p))

View file

@ -13,5 +13,5 @@
<root level="info"> <root level="info">
<appender-ref ref="STDOUT"/> <appender-ref ref="STDOUT"/>
</root> </root>
<logger name="ch.fritteli.labyrinth.*" level="debug"/> <logger name="ch.fritteli.maze.*" level="debug"/>
</configuration> </configuration>

View file

@ -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.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;