public class HTTPServer
extends java.lang.Object
Features + limitations:
Define a RequestHandler
to expose the different services of your application.
Example:
// get a new server which uses a ResourceRequestHandler HTTPServer server = new HTTPServer(serverSocket, 10, 1); // start the server server.start();
To parse the request and write the response, a buffer size of 2048 by default is used. To change this value, set the property "hoka.buffer.size".
RequestHandlerComposite
,
ResourceRequestHandler
Constructor and Description |
---|
HTTPServer(int port,
int maxSimultaneousConnection,
int jobCount)
|
HTTPServer(int port,
int maxSimultaneousConnection,
int jobCount,
RequestHandler requestHandler)
|
HTTPServer(int port,
int maxSimultaneousConnection,
int jobCount,
RequestHandler requestHandler,
javax.net.ServerSocketFactory serverSocketFactory)
|
HTTPServer(int port,
int maxSimultaneousConnection,
int jobCount,
RequestHandler requestHandler,
javax.net.ServerSocketFactory serverSocketFactory,
int keepAliveDuration)
|
HTTPServer(TCPServer tcpServer,
int jobCount,
RequestHandler requestHandler)
Constructs a HTTP server that manage jobs to handle the connections from
tcpServer with
requestHandler . |
HTTPServer(TCPServer tcpServer,
int jobCount,
RequestHandler requestHandler,
HTTPEncodingRegistry encodingRegistry)
Constructs a HTTP server that manage jobs to handle the connections from
tcpServer with
requestHandler . |
Modifier and Type | Method and Description |
---|---|
boolean |
getSendStackTraceOnException()
Returns whether or not the server sends the stack trace of thrown exceptions.
|
void |
sendStackTraceOnException(boolean sendStackTraceOnException)
Sets whether or not the server must send the stack trace of thrown exceptions.
|
void |
start()
Start the
HTTPServer (in a dedicated thread): start listening for connections and start jobs to process
opened connections. |
void |
stop()
Stops the
HTTPServer . |
public HTTPServer(int port, int maxSimultaneousConnection, int jobCount)
TCPServer
and the HTTP server that manage jobs to handle the connections from
the TCPServer
.
Requests are handled by a ResourceRequestHandler
targeting the /hoka/
resource folder.
port
- the port to use.maxSimultaneousConnection
- the maximum number of simultaneously opened connections.jobCount
- the number of jobs to run.public HTTPServer(int port, int maxSimultaneousConnection, int jobCount, RequestHandler requestHandler)
TCPServer
and the HTTP server that manage jobs to handle the connections from
the TCPServer
with requestHandler
.port
- the port to use.maxSimultaneousConnection
- the maximum number of simultaneously opened connections.jobCount
- the number of jobs to run.requestHandler
- the application request handler.public HTTPServer(int port, int maxSimultaneousConnection, int jobCount, RequestHandler requestHandler, javax.net.ServerSocketFactory serverSocketFactory)
TCPServer
and the HTTP server that manage jobs to handle the connections from
the TCPServer
with requestHandler
.port
- the port to use.maxSimultaneousConnection
- the maximum number of simultaneously opened connections.jobCount
- the number of jobs to run.requestHandler
- the application request handler.serverSocketFactory
- the ServerSocketFactory
.public HTTPServer(int port, int maxSimultaneousConnection, int jobCount, RequestHandler requestHandler, javax.net.ServerSocketFactory serverSocketFactory, int keepAliveDuration)
TCPServer
and the HTTP server that manage jobs to handle the connections from
the TCPServer
with requestHandler
.port
- the port to use.maxSimultaneousConnection
- the maximum number of simultaneously opened connections.jobCount
- the number of jobs to run.requestHandler
- the application request handler.serverSocketFactory
- the ServerSocketFactory
.keepAliveDuration
- the timeout duration for idling persistent connections.public HTTPServer(TCPServer tcpServer, int jobCount, RequestHandler requestHandler)
tcpServer
with
requestHandler
.tcpServer
- the underlying TCP server that stores upcoming connections.jobCount
- the number of jobs to run.requestHandler
- the application request handler.public HTTPServer(TCPServer tcpServer, int jobCount, RequestHandler requestHandler, HTTPEncodingRegistry encodingRegistry)
tcpServer
with
requestHandler
.tcpServer
- the underlying TCP server that stores upcoming connections.jobCount
- the number of jobs to run.requestHandler
- the application request handler.encodingRegistry
- the registry of available encoding handlers.public void start() throws java.io.IOException
HTTPServer
(in a dedicated thread): start listening for connections and start jobs to process
opened connections.
Multiple start is not allowed.
java.io.IOException
- if an error occurs during the creation of the socket.public void stop()
HTTPServer
. Stops listening for connections. This method blocks until all session jobs are
stopped.public boolean getSendStackTraceOnException()
Returns false by default.
true
if the server sends the stack trace of thrown exceptions, false
otherwise.sendStackTraceOnException(boolean)
public void sendStackTraceOnException(boolean sendStackTraceOnException)
sendStackTraceOnException
- true
if the server must send the stack trace of thrown exceptions, false
otherwise.