Package ch.autumo.beetroot
Class BeetRootWebServer
java.lang.Object
org.nanohttpd.protocols.http.NanoHTTPD
org.nanohttpd.router.RouterNanoHTTPD
ch.autumo.beetroot.BeetRootWebServer
- All Implemented Interfaces:
BeetRootService
The beetRoot Web Server and Template Engine.
-
Nested Class Summary
Nested classes/interfaces inherited from class org.nanohttpd.router.RouterNanoHTTPD
RouterNanoHTTPD.BaseRoutePrioritizer, RouterNanoHTTPD.DefaultHandler, RouterNanoHTTPD.DefaultRoutePrioritizer, RouterNanoHTTPD.DefaultStreamHandler, RouterNanoHTTPD.Error404UriHandler, RouterNanoHTTPD.GeneralHandler, RouterNanoHTTPD.IndexHandler, RouterNanoHTTPD.InsertionOrderRoutePrioritizer, RouterNanoHTTPD.IRoutePrioritizer, RouterNanoHTTPD.NotImplementedHandler, RouterNanoHTTPD.ProvidedPriorityRoutePrioritizer, RouterNanoHTTPD.StaticPageHandler, RouterNanoHTTPD.UriResource, RouterNanoHTTPD.UriResponder, RouterNanoHTTPD.UriRouterNested classes/interfaces inherited from class org.nanohttpd.protocols.http.NanoHTTPD
org.nanohttpd.protocols.http.NanoHTTPD.ResponseException -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final org.slf4j.Loggerstatic final StringVirtual relative path for temporary stored files to server (e.g. generated images such as the 2FA QR code.Fields inherited from class org.nanohttpd.router.RouterNanoHTTPD
routerFields inherited from class org.nanohttpd.protocols.http.NanoHTTPD
asyncRunner, CONTENT_DISPOSITION_ATTRIBUTE_PATTERN, CONTENT_DISPOSITION_ATTRIBUTE_REGEX, CONTENT_DISPOSITION_PATTERN, CONTENT_DISPOSITION_REGEX, CONTENT_TYPE_PATTERN, CONTENT_TYPE_REGEX, hostname, interceptors, MIME_HTML, MIME_PLAINTEXT, MIME_TYPES, myPort, SOCKET_READ_TIMEOUT -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal voidAdd mappings respectively set web routes.voidNew public method to add routes with priority.protected org.nanohttpd.protocols.http.ClientHandlercreateClientHandler(Socket finalAccept, InputStream inputStream) voiddestroy()Cleanup method.org.nanohttpd.protocols.http.threading.IAsyncRunnerGet async runner.Class<?>Get default handler class.Get default handler entity.final Class<?>getHandlerClass(String handlerName) Get a handler class by handler name.org.nanohttpd.protocols.http.tempfiles.ITempFileManagerGet a new temporary file manager.org.nanohttpd.protocols.http.response.Responseserve(BeetRootHTTPSession session, jakarta.servlet.http.HttpServletRequest request) Main serve method for the beetroot-engine in a servlet contextorg.nanohttpd.protocols.http.response.Responseserve(org.nanohttpd.protocols.http.IHTTPSession session) Main serve method for the beetRoot-engine.org.nanohttpd.protocols.http.response.ResponseserveAtLast(BeetRootHTTPSession session) Last call before the routed website is served.static org.nanohttpd.protocols.http.response.ResponseserverCommandResponse(BeetRootHTTPSession session, ClientAnswer answer) static org.nanohttpd.protocols.http.response.ResponseserverResponse(BeetRootHTTPSession session, Class<?> handlerClass, Object... initParameter) voidsetBaseServer(BaseServer baseServer) Set base server.voidstart()Start the server.voidstart(boolean daemon) Start the server.voidstart(int timeout) Starts the server (in setDaemon(true) mode).voidstart(int timeout, boolean daemon) Start the server.voidstop()Stop the server.Methods inherited from class org.nanohttpd.router.RouterNanoHTTPD
addRoute, normalizeUri, removeRoute, setNotFoundHandler, setNotImplementedHandler, setRoutePrioritizerMethods inherited from class org.nanohttpd.protocols.http.NanoHTTPD
addHTTPInterceptor, closeAllConnections, createServerRunnable, decodeParameters, decodeParameters, decodePercent, getHostname, getListeningPort, getMimeTypeForFile, getMyServerSocket, getServerSocketFactory, getTempFileManagerFactory, handle, isAlive, makeSecure, makeSSLSocketFactory, makeSSLSocketFactory, makeSSLSocketFactory, mimeTypes, safeClose, setAsyncRunner, setHTTPHandler, setServerSocketFactory, setTempFileManagerFactory, wasStarted
-
Field Details
-
LOG
protected static final org.slf4j.Logger LOG -
VIRTUAL_TMP_PATH
Virtual relative path for temporary stored files to server (e.g. generated images such as the 2FA QR code.- See Also:
-
-
Constructor Details
-
Method Details
-
createClientHandler
protected org.nanohttpd.protocols.http.ClientHandler createClientHandler(Socket finalAccept, InputStream inputStream) - Overrides:
createClientHandlerin classorg.nanohttpd.protocols.http.NanoHTTPD
-
getAsyncRunner
public org.nanohttpd.protocols.http.threading.IAsyncRunner getAsyncRunner()Get async runner.- Returns:
- async runner
-
setBaseServer
Set base server.- Parameters:
baseServer- base server
-
start
Start the server.- Overrides:
startin classorg.nanohttpd.protocols.http.NanoHTTPD- Throws:
IOException
-
start
Starts the server (in setDaemon(true) mode).- Overrides:
startin classorg.nanohttpd.protocols.http.NanoHTTPD- Throws:
IOException
-
start
Start the server.- Parameters:
daemon- start the web server as a daemon thread?- Throws:
IOException- IO exception
-
start
Start the server.- Overrides:
startin classorg.nanohttpd.protocols.http.NanoHTTPD- Parameters:
timeout- timeout to use for socket connections.daemon- start the thread daemon or not.- Throws:
IOException- if the socket is in use.
-
stop
public void stop()Stop the server.- Overrides:
stopin classorg.nanohttpd.protocols.http.NanoHTTPD
-
serve
public org.nanohttpd.protocols.http.response.Response serve(org.nanohttpd.protocols.http.IHTTPSession session) Main serve method for the beetRoot-engine.- Overrides:
servein classRouterNanoHTTPD- Parameters:
session- nano session.- Returns:
- response response
-
newTempFileManager
public org.nanohttpd.protocols.http.tempfiles.ITempFileManager newTempFileManager()Description copied from interface:BeetRootServiceGet a new temporary file manager.- Specified by:
newTempFileManagerin interfaceBeetRootService- Returns:
- new temporary file manager
-
destroy
public void destroy()Description copied from interface:BeetRootServiceCleanup method. Close what needs to be closed and free resources.- Specified by:
destroyin interfaceBeetRootService
-
serve
public org.nanohttpd.protocols.http.response.Response serve(BeetRootHTTPSession session, jakarta.servlet.http.HttpServletRequest request) Main serve method for the beetroot-engine in a servlet context- Parameters:
session- session.request- servlet request- Returns:
- response response
-
serverCommandResponse
public static org.nanohttpd.protocols.http.response.Response serverCommandResponse(BeetRootHTTPSession session, ClientAnswer answer) -
serverResponse
public static org.nanohttpd.protocols.http.response.Response serverResponse(BeetRootHTTPSession session, Class<?> handlerClass, Object... initParameter) -
getHandlerClass
Get a handler class by handler name.- Parameters:
handlerName- handler name- Returns:
- handler class or null if not found
-
getDefaultHandlerClass
Get default handler class. Overwrite for customization.- Returns:
- default handler class
-
getDefaultHandlerEntity
Get default handler entity. Overwrite for customization.- Returns:
- default handler entity
-
serveAtLast
Last call before the routed website is served. At this point, templates have been parsed and compiled. Overwrite this method, if you still need to do something. In any case and at the end, it must callRouterNanoHTTPD.serve(IHTTPSession)- Parameters:
session- HTTP sessiom- Returns:
- response
-
addRoute
New public method to add routes with priority. Beetroot has an own generic router where priorities are pre-defined.- Parameters:
url- urlpriority- priorityhandler- handlerinitParameter- init parameter for handler
-
addMappings
public final void addMappings()Add mappings respectively set web routes.- Overrides:
addMappingsin classRouterNanoHTTPD
-