This is a http server program which can be used with another program that requires a (simple) server implementation.
Feel free to give any feedback.
- To start the server, create an instance of the
HttpServer
orHttpsServer
class and assign it to Server class. - To set the logics for any of the http request methods, call the
setRequestProcessor()
method and pass an instance of theRequestProcessor
class. - Call the
start()
function. - To set the request timeout, call the
setTimeout()
method and pass an instance of Duration class. - For HttpsServer only, the
setKeyStore()
method needs to be called with keyStoreFileName and password.
Note:-
- If no RequestProcessor is set, the server returns the default http response.
- If
setKeyStore()
method is not called then connection to HttpsServer cannot be established.
Extending the RequestPreprocessor class
class TestRequestProcessor extends RequestProcessor
{
// override the required methods
}
Starting the server
TestRequestProcessor testRequestProcessor = new TestRequestProcessor();
Server server = new HttpServer(); // Starts an HTTP Server
Server server = new HttpsServer(); // Starts an HTTPS Server
server.setRequestProcessor(testRequestProcessor);
server.start();