BasicHTTPService
, java.lang.AutoCloseable
public class MicroHTTPDService extends java.lang.Object implements BasicHTTPService
BasicHTTPService.BinderHandler, BasicHTTPService.FileUpload, BasicHTTPService.Handler, BasicHTTPService.Request, BasicHTTPService.RequestPreprocessor, BasicHTTPService.Response
Constructor | Description |
---|---|
MicroHTTPDService() |
Modifier and Type | Method | Description |
---|---|---|
void |
close() |
Shutdown the service and free all allocated resources.
|
@Nullable BasicHTTPService.Handler |
on(java.lang.String pathStart,
BasicHTTPService.Handler handler) |
Register request handler which must be called if the
BasicHTTPService.Request.getPath() starts with pathStart. |
@Nullable BasicHTTPService.Handler |
onNotFound(BasicHTTPService.Handler handler) |
Register request handler which must be called if there is no matching
BasicHTTPService.on(String, Handler) requests found. |
void |
start(int port,
int maxResponseThreads) |
Start the service in a separate thread, returns as soon as listening port will be opened.
|
public void start(int port, int maxResponseThreads) throws java.io.IOException
BasicHTTPService
start
in interface BasicHTTPService
port
- is port numbermaxResponseThreads
- is maximum available threadsjava.io.IOException
- if port can't be open for listeningpublic void close() throws java.lang.Exception
BasicHTTPService
close
in interface java.lang.AutoCloseable
close
in interface BasicHTTPService
java.lang.Exception
- for closing exceptionspublic @Nullable BasicHTTPService.Handler on(java.lang.String pathStart, BasicHTTPService.Handler handler)
BasicHTTPService
BasicHTTPService.Request.getPath()
starts with pathStart.on
in interface BasicHTTPService
pathStart
- the beginning of the request's path that should be handled by this handlerhandler
- to handle such requestsnull
if there were no previous handlers bound to this request
path prefix before this handler;
or BasicHTTPService.Handler
which was bound at this prefix before and that was overwritten.public @Nullable BasicHTTPService.Handler onNotFound(BasicHTTPService.Handler handler)
BasicHTTPService
BasicHTTPService.on(String, Handler)
requests found.
By default, if no BasicHTTPService.onNotFound(Handler)
handlers found,
a response with 404 HTTP code and an empty body is returned.
onNotFound
in interface BasicHTTPService
handler
- to handle such requestsnull
if there were no previous handlers bound to this request
path prefix before this handler;
or BasicHTTPService.Handler
which was bound at this prefix before and that was overwritten.