From ab0da5e43dbf3c4f041ba67960095ddf7074ebec Mon Sep 17 00:00:00 2001 From: mathias Date: Sat, 2 Oct 2021 17:32:24 +0200 Subject: [PATCH] Integrated the NotFoundHandler into the SimpleAutoResponder --- .../autoresponder/SimpleAutoResponder.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/main/java/de/gnmyt/autoresponder/SimpleAutoResponder.java b/src/main/java/de/gnmyt/autoresponder/SimpleAutoResponder.java index b3c94e8..1b98756 100644 --- a/src/main/java/de/gnmyt/autoresponder/SimpleAutoResponder.java +++ b/src/main/java/de/gnmyt/autoresponder/SimpleAutoResponder.java @@ -7,6 +7,8 @@ import de.gnmyt.autoresponder.authentication.ResponderAuthentication; import de.gnmyt.autoresponder.event.api.EventManager; import de.gnmyt.autoresponder.event.api.Listener; import de.gnmyt.autoresponder.exceptions.ResponderException; +import de.gnmyt.autoresponder.handler.NotFoundHandler; +import de.gnmyt.autoresponder.handler.SendNothingHandler; import de.gnmyt.autoresponder.http.contexts.ResponderContext; import java.io.IOException; @@ -19,6 +21,8 @@ public class SimpleAutoResponder { private HttpServer httpServer; private AuthenticationDetails authenticationDetails; + private NotFoundHandler notFoundHandler = new SendNothingHandler(); + private int port = 8025; /** @@ -73,6 +77,17 @@ public class SimpleAutoResponder { return this; } + /** + * Sets the custom "not found handler". It executes whenever a message could not be found / answered + * + * @param notFoundHandler The new "not found handler" + * @return the current {@link SimpleAutoResponder} instance + */ + public SimpleAutoResponder useNotFoundHandler(NotFoundHandler notFoundHandler) { + this.notFoundHandler = notFoundHandler; + return this; + } + /** * Gets the port of the webserver * @@ -101,4 +116,13 @@ public class SimpleAutoResponder { public EventManager getEventManager() { return eventManager; } + + /** + * Gets the handler which executes whenever the message could not be found + * + * @return the not found handler + */ + public NotFoundHandler getNotFoundHandler() { + return notFoundHandler; + } }