Class BeetRootWebServer
java.lang.Object
org.nanohttpd.protocols.http.NanoHTTPD
ch.autumo.beetroot.server.HTTPServer
ch.autumo.beetroot.BeetRootWebServer
- All Implemented Interfaces:
BeetRootService
The beetRoot Web Server and Template Engine.
-
Nested Class Summary
Nested classes/interfaces inherited from class HTTPServer
HTTPServer.BaseRoutePrioritizer, HTTPServer.DefaultHandler, HTTPServer.DefaultRoutePrioritizer, HTTPServer.DefaultStreamHandler, HTTPServer.Error404UriHandler, HTTPServer.GeneralHandler, HTTPServer.IndexHandler, HTTPServer.InsertionOrderRoutePrioritizer, HTTPServer.IRoutePrioritizer, HTTPServer.NotImplementedHandler, HTTPServer.ProvidedPriorityRoutePrioritizer, HTTPServer.StaticPageHandler, HTTPServer.UriResource, HTTPServer.UriResponder, HTTPServer.UriRouterModifier and TypeClassDescriptionstatic classBase implementation of a route prioritizer that owns the route mappings.static classGeneral nanolet to inherit from if you provide text or html data, only fixed size responses will be generated.static classOrders routes by the priority assigned when they were added.static classGeneral nanolet to inherit from if you provide stream data, only chucked responses will be generated.static classHandling error 404 - unrecognized urlsstatic classGeneral nanolet to print debug info's as a html page.static classHandling indexstatic classKeeps routes in the order in which they were added.static interfaceHolds the registered routes and defines their processing order.static classFallback handler for routes that are registered without an implementation.static classUses the priority that was passed toaddRouteunchanged.static classServes static files from a directory that is passed as init parameter.static classA single route: URI pattern, handler class, priority and init parameters.static interfaceResponder for a routed URI.static classResolves a request URI to a registered route and processes the request with that route's handler.Nested 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.LoggerLogger for this class.static final StringVirtual relative path for temporary stored files to server (e.g.Fields inherited from class HTTPServer
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) Creates the JSON response for a client answer.static org.nanohttpd.protocols.http.response.ResponseserverResponse(BeetRootHTTPSession session, Class<?> handlerClass, Object... initParameter) Creates the response by instantiating and calling the given handler.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 HTTPServer
addRoute, normalizeUri, removeRoute, setNotFoundHandler, setNotImplementedHandler, setRoutePrioritizerModifier and TypeMethodDescriptionvoidAdds a route with the default priority100.static StringnormalizeUri(String value) Removes a leading and a trailing slash from the given URI.voidremoveRoute(String url) Removes the route with the given URI pattern.<T extends HTTPServer.UriResponder>
voidsetNotFoundHandler(Class<T> handler) Sets the handler for URIs that match no route.<T extends HTTPServer.UriResponder>
voidsetNotImplementedHandler(Class<T> handler) Sets the handler for routes without an implementation.voidsetRoutePrioritizer(HTTPServer.IRoutePrioritizer routePrioritizer) Replaces the route prioritizer.Methods 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 LOGLogger for this class. -
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
-
BeetRootWebServer
-
BeetRootWebServer
-
-
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 classHTTPServer- 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) Creates the JSON response for a client answer.- Parameters:
session- the HTTP sessionanswer- the client answer- Returns:
- the response
-
serverResponse
public static org.nanohttpd.protocols.http.response.Response serverResponse(BeetRootHTTPSession session, Class<?> handlerClass, Object... initParameter) Creates the response by instantiating and calling the given handler.- Parameters:
session- the HTTP sessionhandlerClass- the handler classinitParameter- the handler constructor parameters- Returns:
- the response
-
getHandlerClass
-
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 callHTTPServer.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 classHTTPServer
-