Package org.ka2ddo.yaac.webserver
Class HttpServer
java.lang.Object
org.ka2ddo.yaac.webserver.HttpServer
- All Implemented Interfaces:
Runnable
This class implements a very simple HTTP server. It spawns a HttpConnectionThread instance for each incoming
connection request.
- Author:
- Andrew Pavlin, KA2DDO
- See Also:
-
Constructor Summary
ConstructorDescriptionHttpServer
(int listenPort, int refreshRateInSec) Create a HttpServer instance on the specified listening port. -
Method Summary
Modifier and TypeMethodDescriptionint
Get the port the mini-webserver is currently listening on.Obtain an Iterator across all the GETable pages known to this web server.getPathIterator
(String method) Obtain an Iterator across all the pages known to this web server.int
Get the automatic page refresh rate setting currently sent to browsers.boolean
registerPage
(String method, String path, PathHandler handler) Register a page handler for a particular path within the website.boolean
registerPage
(String path, PathHandler handler) Register a page handler for a particular path within the website, using the "GET" HTTP method.void
run()
Accept incoming HTTP connection requests and spawn a handler thread for each browser connection.void
setListenPort
(int listenPort) Change the port number that the mini-webserver should listen on.void
setRefreshRateInSec
(int refreshRateInSec) Set the automatic page refresh rate setting currently sent to browsers.
-
Constructor Details
-
HttpServer
public HttpServer(int listenPort, int refreshRateInSec) Create a HttpServer instance on the specified listening port.- Parameters:
listenPort
- TCP port number to accept incoming HTTP requests onrefreshRateInSec
- refresh interval in seconds for web pages that do auto-refreshing
-
-
Method Details
-
run
public void run()Accept incoming HTTP connection requests and spawn a handler thread for each browser connection. -
getRefreshRateInSec
public int getRefreshRateInSec()Get the automatic page refresh rate setting currently sent to browsers.- Returns:
- page refresh rate in seconds between refreshes
-
setRefreshRateInSec
Set the automatic page refresh rate setting currently sent to browsers.- Parameters:
refreshRateInSec
- page refresh rate in seconds between refreshes- Throws:
IllegalArgumentException
- if specified refresh rate is shorter than 5 seconds
-
getListenPort
public int getListenPort()Get the port the mini-webserver is currently listening on.- Returns:
- TCP port number for YAAC's internal webserver
-
setListenPort
public void setListenPort(int listenPort) Change the port number that the mini-webserver should listen on. Note this will not take effect until the next time YAAC is started. Changing this port number will shut down the existing listening socket for this HttpServer instance and create a new one on the new port number.- Parameters:
listenPort
- TCP port number for YAAC's internal webserver
-
registerPage
Register a page handler for a particular path within the website, using the "GET" HTTP method.- Parameters:
path
- String of leading part of URL pathhandler
- PathHandler to generate a response page for the path- Returns:
- boolean true if a page is being replaced, false if this is a new page
-
registerPage
Register a page handler for a particular path within the website.- Parameters:
method
- String of HTTP method for accessing this pagepath
- String of leading part of URL pathhandler
- PathHandler to generate a response page for the path- Returns:
- boolean true if a page is being replaced, false if this is a new page
-
getPathIterator
Obtain an Iterator across all the GETable pages known to this web server.- Returns:
- Iterator of Strings
-
getPathIterator
Obtain an Iterator across all the pages known to this web server.- Parameters:
method
- String of HTTP method for accessing these pages- Returns:
- Iterator of Strings
-