public class HttpServer extends Object
| Constructor and Description |
|---|
HttpServer(HttpServerRequestHandler requestHandler,
InetAddress inetAddress,
int port)
Creating an instance of HttpServer listening to one ports (this does not actually start the server - call start()
for that).
|
HttpServer(HttpServerRequestHandler requestHandler,
InetAddress inetAddress,
int port,
int sslPort,
KeyStore keyStore,
String certificatePassword)
Creating an instance of HttpServer listening to two ports (this does not actually start the server - call start()
for that).
|
HttpServer(HttpServerRequestHandler requestHandler,
InetAddress inetAddress,
int port,
int sslPort,
KeyStore keyStore,
String certificatePassword,
TrustManager clientAuthTrustManager)
Creating an instance of HttpServer listening to two ports (this does not actually start the server - call start()
for that).
|
HttpServer(HttpServerRequestHandler requestHandler,
InetAddress inetAddress,
int port,
int sslPort,
String keyStorePath,
String keyStorePassword,
String certificatePassword)
Creating an instance of HttpServer listening to two ports (this does not actually start the server - call start()
for that).
|
HttpServer(HttpServerRequestHandler requestHandler,
InetAddress inetAddress,
int port,
int sslPort,
String keyStorePath,
String keyStorePassword,
String certificatePassword,
TrustManager clientAuthTrustManager)
Creating an instance of HttpServer listening to two ports (this does not actually start the server - call start()
for that).
|
HttpServer(HttpServerRequestHandler requestHandler,
int port)
Creating an instance of HttpServer listening to one ports (this does not actually start the server - call start()
for that).
|
HttpServer(HttpServerRequestHandler requestHandler,
int port,
int sslPort,
KeyStore keyStore,
String certificatePassword)
Creating an instance of HttpServer listening to two ports (this does not actually start the server - call start()
for that).
|
HttpServer(HttpServerRequestHandler requestHandler,
int port,
int sslPort,
KeyStore keyStore,
String certificatePassword,
TrustManager clientAuthTrustManager)
Creating an instance of HttpServer listening to two ports (this does not actually start the server - call start()
for that).
|
HttpServer(HttpServerRequestHandler requestHandler,
int port,
int sslPort,
String keyStorePath,
String keyStorePassword,
String certificatePassword)
Creating an instance of HttpServer listening to two ports (this does not actually start the server - call start()
for that).
|
HttpServer(HttpServerRequestHandler requestHandler,
int port,
int sslPort,
String keyStorePath,
String keyStorePassword,
String certificatePassword,
TrustManager clientAuthTrustManager)
Creating an instance of HttpServer listening to two ports (this does not actually start the server - call start()
for that).
|
| Modifier and Type | Method and Description |
|---|---|
void |
addHostSpecificKeystore(String serverName,
KeyStore keyStore,
String certificatePassword)
Add additional keyStore with keys for a specific host name Choice will be made based on SNI, if nothing matches,
the default specified in the constructor will be used
|
void |
addHostSpecificKeystore(String serverName,
String keyStorePath,
String keyStorePassword,
String certificatePassword)
Add additional keyStore with keys for a specific host name Choice will be made based on SNI, if nothing matches,
the default specified in the constructor will be used
|
void |
closeAllConnection()
Closes all connections immediately without waiting for the processing to finish The server will continue to
accept new connections
|
int |
getConnectionNo() |
long |
getConnectionsCreated() |
protected HttpServerRequestHandler |
getRequestHandler() |
boolean |
isRunning() |
boolean |
isStopped() |
void |
setCipherSuites(String... enabledCipherSuites) |
void |
setNeedClientAuthentication(boolean needClientAuthentication)
This requests a client to provide authentication certificate (TLS only)
|
void |
setOnConnectHandler(HttpServerOnConnectProcess onConnectHandler)
Sets a handler that will be called immediately after the connection to the server is made, in case of TLS
connection, also after the handshake took place
|
void |
setOnRequestHeadersHandler(HttpServerOnRequestHeadersProcess onRequestHeadersHandler)
Sets a handler that will be called immediately after the request headers are read but before reading the request
body (if any)
|
void |
setTcpNoDelay(boolean tcpNoDelay)
Switch TCP_NODELAY
When it is TCP_NODELAY is on, Nagle's algorithm is switched off
This will affect new connections only
|
void |
setThrottlingDelay(int throttlingDelayMils)
If set to a value of more then zero, this introduces a delay between every 100 bytes read from input stream.
|
void |
setTimeoutMils(int timeoutMils)
Set timeout on client connection.
|
void |
setTlsProtocol(TlsVersion... enabledTlsProtocols) |
void |
shouldFailWhenNoSni(boolean shouldFail) |
void |
shouldWarnWhenSniNotMatching(boolean warnWhenSniNotMatching) |
void |
start()
Starts the server.
|
void |
start(int attempts,
int timeoutMillis)
Starts the server making several attempts.
|
void |
start(int attempts,
int timeoutMillis,
int backlog)
Starts the server making several attempts.
|
void |
stop()
Stops the server.
|
void |
stopNow()
Stops the server.
|
void |
useJdkDefaultCipherSuites() |
void |
useJdkDefaultTlsProtocols() |
public HttpServer(HttpServerRequestHandler requestHandler, int port)
requestHandler - - an implementation of HttpServerRequestHandler that will processes all requestsport - - port for HTTP requestspublic HttpServer(HttpServerRequestHandler requestHandler, InetAddress inetAddress, int port)
requestHandler - - an implementation of HttpServerRequestHandler that will processes all requestsinetAddress - - an IP address to which the server is bound. You can use this constructor if you wish to limit your
server to a particular local interface, if it is null, then we binding on 0.0.0.0port - - port for HTTP requestspublic HttpServer(HttpServerRequestHandler requestHandler, int port, int sslPort, String keyStorePath, String keyStorePassword, String certificatePassword)
requestHandler - - an implementation of HttpServerRequestHandler that will processes all requestsport - - port for HTTP requestssslPort - - port for HTTPS requests (on connection to this port the server will expect the client to start SSL
handshake)keyStorePath - - path to Java keystore file (JKS file)keyStorePassword - - password for Java keystore filecertificatePassword - - password for certificates in Java keystorepublic HttpServer(HttpServerRequestHandler requestHandler, int port, int sslPort, String keyStorePath, String keyStorePassword, String certificatePassword, TrustManager clientAuthTrustManager)
requestHandler - - an implementation of HttpServerRequestHandler that will processes all requestsport - - port for HTTP requestssslPort - - port for HTTPS requests (on connection to this port the server will expect the client to start SSL
handshake)keyStorePath - - path to Java keystore file (JKS file)keyStorePassword - - password for Java keystore filecertificatePassword - - password for certificates in Java keystoreclientAuthTrustManager - - trust manager for client authentication (when requested)public HttpServer(HttpServerRequestHandler requestHandler, int port, int sslPort, KeyStore keyStore, String certificatePassword, TrustManager clientAuthTrustManager)
requestHandler - - an implementation of HttpServerRequestHandler that will processes all requestsport - - port for HTTP requestssslPort - - port for HTTPS requests (on connection to this port the server will expect the client to start SSL
handshake)keyStore - - Java keystorecertificatePassword - - password for certificates in Java keystorepublic HttpServer(HttpServerRequestHandler requestHandler, int port, int sslPort, KeyStore keyStore, String certificatePassword)
requestHandler - - an implementation of HttpServerRequestHandler that will processes all requestsport - - port for HTTP requestssslPort - - port for HTTPS requests (on connection to this port the server will expect the client to start SSL
handshake)keyStore - - Java keystorecertificatePassword - - password for certificates in Java keystorepublic HttpServer(HttpServerRequestHandler requestHandler, InetAddress inetAddress, int port, int sslPort, String keyStorePath, String keyStorePassword, String certificatePassword)
requestHandler - - an implementation of HttpServerRequestHandler that will processes all requestsinetAddress - - an IP address to which the server is bound. You can use this constructor if you wish to limit your
server to a particular local interface, if it is null, then we binding on 0.0.0.0port - - port for HTTP requestssslPort - - port for HTTPS requests (on connection to this port the server will expect the client to start SSL
handshake)keyStorePath - - path to Java keystore file (JKS file)keyStorePassword - - password for Java keystore filecertificatePassword - - password for certificates in Java keystorepublic HttpServer(HttpServerRequestHandler requestHandler, InetAddress inetAddress, int port, int sslPort, KeyStore keyStore, String certificatePassword)
requestHandler - - an implementation of HttpServerRequestHandler that will processes all requestsinetAddress - - an IP address to which the server is bound. You can use this constructor if you wish to limit your
server to a particular local interface, if it is null, then we binding on 0.0.0.0port - - port for HTTP requestssslPort - - port for HTTPS requests (on connection to this port the server will expect the client to start SSL
handshake)keyStore - - Java keystorecertificatePassword - - password for certificates in Java keystorepublic HttpServer(HttpServerRequestHandler requestHandler, InetAddress inetAddress, int port, int sslPort, String keyStorePath, String keyStorePassword, String certificatePassword, TrustManager clientAuthTrustManager)
requestHandler - - an implementation of HttpServerRequestHandler that will processes all requestsinetAddress - - an IP address to which the server is bound. You can use this constructor if you wish to limit your
server to a particular local interface, if it is null, then we binding on 0.0.0.0port - - port for HTTP requestssslPort - - port for HTTPS requests (on connection to this port the server will expect the client to start SSL
handshake)keyStorePath - - path to Java keystore file (JKS file)keyStorePassword - - password for Java keystore filecertificatePassword - - password for certificates in Java keystoreclientAuthTrustManager - - trust manager for client authentication (when requested)public HttpServer(HttpServerRequestHandler requestHandler, InetAddress inetAddress, int port, int sslPort, KeyStore keyStore, String certificatePassword, TrustManager clientAuthTrustManager)
requestHandler - - an implementation of HttpServerRequestHandler that will processes all requestsinetAddress - - an IP address to which the server is bound. You can use this constructor if you wish to limit your
server to a particular local interface, if it is null, then we binding on 0.0.0.0port - - port for HTTP requestssslPort - - port for HTTPS requests (on connection to this port the server will expect the client to start SSL
handshake)keyStore - - Java keystorecertificatePassword - - password for certificates in Java keystoreclientAuthTrustManager - - trust manager for client authentication (when requested)public void start()
throws IOException
IOException - - often indicate that we can't bind to a port (e.g. because it is used by a different application or
we don't have authority to find to it).public void start(int attempts,
int timeoutMillis)
throws IOException
attempts - - number of attemptstimeoutMillis - - pause between two attempts in millisecondsIOException - - often indicate that we can't bind to a port (e.g. because it is used by a different application or
we don't have authority to find to it).public void start(int attempts,
int timeoutMillis,
int backlog)
throws IOException
attempts - - number of attemptstimeoutMillis - - pause between two attempts in millisecondsbacklog - - requested maximum length of the queue of incoming connectionsIOException - - often indicate that we can't bind to a port (e.g. because it is used by a different application or
we don't have authority to find to it).public void stop()
public void stopNow()
public int getConnectionNo()
public long getConnectionsCreated()
public boolean isRunning()
public boolean isStopped()
public void setTlsProtocol(TlsVersion... enabledTlsProtocols)
enabledTlsProtocols - - list of allowed TLS protocolspublic void useJdkDefaultTlsProtocols()
public void setCipherSuites(String... enabledCipherSuites)
enabledCipherSuites - - list of allowed Cipher Suitespublic void useJdkDefaultCipherSuites()
public void setNeedClientAuthentication(boolean needClientAuthentication)
needClientAuthentication - - true if authentication required, false if notpublic void addHostSpecificKeystore(String serverName, String keyStorePath, String keyStorePassword, String certificatePassword)
serverName - - server name received in SNI during TLS handshakekeyStorePath - - path to Java keystore file (JKS file)keyStorePassword - - password for Java keystore filecertificatePassword - - password for certificates in Java keystorepublic void addHostSpecificKeystore(String serverName, KeyStore keyStore, String certificatePassword)
serverName - - server name received in SNI during TLS handshakekeyStore - - Java keystorecertificatePassword - - password for certificates in Java keystorepublic void closeAllConnection()
public void shouldFailWhenNoSni(boolean shouldFail)
shouldFail - - when set to TRUE, server will fail handshake if ClientHello does not include Server Name Indication
extension.public void shouldWarnWhenSniNotMatching(boolean warnWhenSniNotMatching)
warnWhenSniNotMatching - - when set to TRUE, server will send unrecognized_name alert if ClientHello includes Server Name
Indication extension, but it does not match any host-specific keystores.public void setTimeoutMils(int timeoutMils)
timeoutMils - - timeout in millisecondspublic void setThrottlingDelay(int throttlingDelayMils)
throttlingDelayMils - - delay in milliseconds, when zero - no delay.public void setTcpNoDelay(boolean tcpNoDelay)
tcpNoDelay - - when true then Nagle's algorithm is off (default)public void setOnRequestHeadersHandler(HttpServerOnRequestHeadersProcess onRequestHeadersHandler)
onRequestHeadersHandler - - the handler, if null (default) - no processing will take placepublic void setOnConnectHandler(HttpServerOnConnectProcess onConnectHandler)
onConnectHandler - - the handler, if null (default) - no processing will take placeprotected HttpServerRequestHandler getRequestHandler()
Copyright © 2019. All rights reserved.