Class HTTPServer
java.lang.Object
org.nanohttpd.protocols.http.NanoHTTPD
ch.autumo.beetroot.server.HTTPServer
- Direct Known Subclasses:
BeetRootWebServer
public class HTTPServer
extends org.nanohttpd.protocols.http.NanoHTTPD
Nano HTTP server.
-
Nested Class Summary
Nested ClassesModifier 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.protected HTTPServer.UriRouterFields 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
ConstructorsConstructorDescriptionHTTPServer(int port) Creates the server on the given port.HTTPServer(String hostname, int port) Creates the server on the given host name and port. -
Method Summary
Modifier and TypeMethodDescriptionvoidDefault routings, they are over writable.voidAdds 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.org.nanohttpd.protocols.http.response.Responseserve(org.nanohttpd.protocols.http.IHTTPSession session) <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, createClientHandler, createServerRunnable, decodeParameters, decodeParameters, decodePercent, getHostname, getListeningPort, getMimeTypeForFile, getMyServerSocket, getServerSocketFactory, getTempFileManagerFactory, handle, isAlive, makeSecure, makeSSLSocketFactory, makeSSLSocketFactory, makeSSLSocketFactory, mimeTypes, safeClose, setAsyncRunner, setHTTPHandler, setServerSocketFactory, setTempFileManagerFactory, start, start, start, stop, wasStarted
-
Field Details
-
LOG
protected static final org.slf4j.Logger LOGLogger. -
router
-
-
Constructor Details
-
HTTPServer
public HTTPServer(int port) Creates the server on the given port.- Parameters:
port- the port to listen on
-
HTTPServer
Creates the server on the given host name and port.- Parameters:
hostname- the host name to bind toport- the port to listen on
-
-
Method Details
-
normalizeUri
-
addMappings
public void addMappings()Default routings, they are over writable.router.setNotFoundHandler(GeneralHandler.class);
-
addRoute
-
setNotImplementedHandler
Sets the handler for routes without an implementation.- Type Parameters:
T- the responder type- Parameters:
handler- the handler class
-
setNotFoundHandler
Sets the handler for URIs that match no route.- Type Parameters:
T- the responder type- Parameters:
handler- the handler class
-
removeRoute
Removes the route with the given URI pattern.- Parameters:
url- the URI pattern
-
setRoutePrioritizer
Replaces the route prioritizer.- Parameters:
routePrioritizer- the new prioritizer
-
serve
public org.nanohttpd.protocols.http.response.Response serve(org.nanohttpd.protocols.http.IHTTPSession session) - Overrides:
servein classorg.nanohttpd.protocols.http.NanoHTTPD
-