|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||

java.lang.Objectorg.xsocket.connection.Server
org.xlightweb.server.HttpServer
public class HttpServer
A HttpServer. The http server accepts incoming connections and forwards the request to
the assigned IHttpRequestHandler. Example:
// defining a request handler
class MyRequestHandler implements IHttpRequestHandler {
public void onRequest(IHttpExchange exchange) throws IOException {
IHttpRequest request = exchange.getRequest();
//...
exchange.send(new HttpResponse(200, "text/plain", "it works"));
}
}
// creates a server
IServer server = new HttpServer(8080, new MyRequestHandler());
// setting some properties
server.setMaxTransactions(400);
server.setRequestTimeoutMillis(5 * 60 * 1000);
//...
// executing the server
server.run(); // (blocks forever)
// or server.start(); (blocks until the server has been started)
//...
| Field Summary |
|---|
| Fields inherited from class org.xsocket.connection.Server |
|---|
MIN_SIZE_WORKER_POOL, SIZE_WORKER_POOL, TASK_QUEUE_SIZE |
| Fields inherited from interface org.xsocket.connection.IServer |
|---|
DEFAULT_CONNECTION_TIMEOUT_SEC, DEFAULT_IDLE_TIMEOUT_SEC, DEFAULT_READ_TRANSFER_PREALLOCATION_MIN_SIZE, DEFAULT_READ_TRANSFER_PREALLOCATION_SIZE, DEFAULT_READ_TRANSFER_USE_DIRECT, SO_RCVBUF, SO_REUSEADDR |
| Constructor Summary | |
|---|---|
HttpServer(IHttpRequestHandler requestHandler)
constructor |
|
HttpServer(IHttpRequestHandler handler,
Map<String,Object> options)
constructor |
|
HttpServer(InetAddress address,
int port,
IHttpRequestHandler handler)
constructor |
|
HttpServer(InetAddress address,
int port,
IHttpRequestHandler handler,
Map<String,Object> options,
SSLContext sslContext,
boolean sslOn)
constructor |
|
HttpServer(InetAddress address,
int port,
IHttpRequestHandler handler,
SSLContext sslContext,
boolean sslOn)
constructor |
|
HttpServer(int port,
IHttpRequestHandler handler)
constructor |
|
HttpServer(int port,
IHttpRequestHandler handler,
int minPoolsize,
int maxPoolsize)
constructor |
|
HttpServer(int port,
IHttpRequestHandler handler,
Map<String,Object> options)
constructor |
|
HttpServer(int port,
IHttpRequestHandler handler,
Map<String,Object> options,
SSLContext sslContext,
boolean sslOn)
constructor |
|
HttpServer(int port,
IHttpRequestHandler handler,
SSLContext sslContext,
boolean sslOn)
constructor |
|
HttpServer(int port,
IHttpRequestHandler handler,
SSLContext sslContext,
boolean sslOn,
int minPoolsize,
int maxPoolsize)
constructor |
|
HttpServer(String host,
int port,
IHttpRequestHandler handler)
constructor |
|
HttpServer(String host,
int port,
IHttpRequestHandler handler,
Map<String,Object> options)
constructor |
|
HttpServer(String hostname,
int port,
IHttpRequestHandler handler,
Map<String,Object> options,
SSLContext sslContext,
boolean sslOn)
constructor |
|
HttpServer(String hostname,
int port,
IHttpRequestHandler handler,
SSLContext sslContext,
boolean sslOn)
constructor |
|
| Method Summary | |
|---|---|
void |
addConnectionHandler(IHttpConnectionHandler connectionHandler)
adds a connection handler |
int |
getAutoCompressThresholdBytes()
gets the autocompress threshold of responses |
long |
getBodyDataReceiveTimeoutMillis()
get the body data receive timeout |
String |
getImplementationDate()
returns the implementation date |
String |
getImplementationVersion()
returns the implementation version |
int |
getMaxTransactions()
get the max transactions per connection. |
String |
getRequestBodyDefaultEncoding()
get the request body default encoding. |
IHttpRequestHandler |
getRequestHandler()
returns the request handler |
long |
getRequestTimeoutMillis()
gets the message receive timeout |
ISessionManager |
getSessionManager()
returns the session manager |
int |
getSessionMaxInactiveIntervalSec()
gets the session max inactive interval in seconds |
boolean |
isAutoUncompress()
return true, if the request will be uncompressed (if compressed) |
boolean |
isCloseOnSendingError()
returns if the server-side connection will closed, if an error message (4xx or 5xx) will be sent |
boolean |
isUsingCookies()
returns true, if cookies is used for session state management |
protected void |
onPreRejectConnection(NonBlockingConnection connection)
|
void |
setAutoCompressThresholdBytes(int autocompressThresholdBytes)
sets the autocompress threshold of responses. |
void |
setAutoUncompress(boolean isAutoUncompress)
set if the request will be uncompressed (if compressed) |
void |
setBodyDataReceiveTimeoutMillis(long bodyDataReceiveTimeoutMillis)
set the body data receive timeout |
void |
setCloseOnSendingError(boolean isCloseOnSendingError)
set is if the server-side connection will closed, if an error message (4xx or 5xx) is sent |
void |
setMaxTransactions(int maxTransactions)
set the max transactions per connection. |
void |
setRequestBodyDefaultEncoding(String defaultEncoding)
set the request body default encoding. |
void |
setRequestTimeoutMillis(long receivetimeout)
sets the message receive timeout |
void |
setSessionManager(ISessionManager sessionManager)
sets the session manager |
void |
setSessionMaxInactiveIntervalSec(int sessionMaxInactiveIntervalSec)
sets the session max inactive interval in seconds |
void |
setUsingCookies(boolean useCookies)
sets if cookies is used for session state management |
| Methods inherited from class org.xsocket.connection.Server |
|---|
addListener, close, getAutoflush, getConnectionTimeoutMillis, getFlushmode, getHandler, getIdleTimeoutMillis, getLocalAddress, getLocalPort, getOpenConnections, getOption, getOptions, getServerName, getStartUpLogMessage, getWorkerpool, isOpen, onClosed, removeListener, run, setAutoflush, setConnectionTimeoutMillis, setFlushmode, setHandler, setIdleTimeoutMillis, setMaxConcurrentConnections, setMaxReadBufferThreshold, setServerName, setStartUpLogMessage, setWorkerpool, setWriteTransferRate, start, toString |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface org.xsocket.connection.IServer |
|---|
addListener, getAutoflush, getConnectionTimeoutMillis, getFlushmode, getHandler, getIdleTimeoutMillis, getLocalAddress, getLocalPort, getOption, getOptions, getStartUpLogMessage, getWorkerpool, isOpen, removeListener, setAutoflush, setConnectionTimeoutMillis, setFlushmode, setIdleTimeoutMillis, setStartUpLogMessage, setWorkerpool, setWriteTransferRate, start |
| Methods inherited from interface java.lang.Runnable |
|---|
run |
| Methods inherited from interface java.io.Closeable |
|---|
close |
| Constructor Detail |
|---|
public HttpServer(IHttpRequestHandler requestHandler)
throws UnknownHostException,
IOException
requestHandler - the requestHandler
IOException - If some other I/O error occurs
UnknownHostException - if the local host cannot determined
public HttpServer(IHttpRequestHandler handler,
Map<String,Object> options)
throws UnknownHostException,
IOException
handler - the handler to useoptions - the socket options
IOException - If some other I/O error occurs
UnknownHostException - if the local host cannot determined
public HttpServer(int port,
IHttpRequestHandler handler)
throws UnknownHostException,
IOException
port - the local porthandler - the handler to use
UnknownHostException - if the local host cannot determined
IOException - If some other I/O error occurs
public HttpServer(int port,
IHttpRequestHandler handler,
int minPoolsize,
int maxPoolsize)
throws UnknownHostException,
IOException
port - the local porthandler - the handler to useminPoolsize - the min workerpool sizemaxPoolsize - the max workerpool size
UnknownHostException - if the local host cannot determined
IOException - If some other I/O error occurs
public HttpServer(int port,
IHttpRequestHandler handler,
Map<String,Object> options)
throws UnknownHostException,
IOException
port - the local porthandler - the handler to useoptions - the acceptor socket options
UnknownHostException - if the local host cannot determined
IOException - If some other I/O error occurs
public HttpServer(InetAddress address,
int port,
IHttpRequestHandler handler)
throws UnknownHostException,
IOException
address - the local addressport - the local porthandler - the handler to use
UnknownHostException - if the local host cannot determined
IOException - If some other I/O error occurs
public HttpServer(String host,
int port,
IHttpRequestHandler handler)
throws UnknownHostException,
IOException
host - the local hodt nameport - the local porthandler - the handler to use
UnknownHostException - if the local host cannot determined
IOException - If some other I/O error occurs
public HttpServer(String host,
int port,
IHttpRequestHandler handler,
Map<String,Object> options)
throws UnknownHostException,
IOException
host - the local hostport - the local porthandler - the handler to useoptions - the socket options
UnknownHostException - if the local host cannot determined
IOException - If some other I/O error occurs
public HttpServer(int port,
IHttpRequestHandler handler,
SSLContext sslContext,
boolean sslOn)
throws UnknownHostException,
IOException
port - local porthandler - the handler to usesslOn - true, is SSL should be activatedsslContext - the ssl context to use
UnknownHostException - if the local host cannot determined
IOException - If some other I/O error occurs
public HttpServer(int port,
IHttpRequestHandler handler,
SSLContext sslContext,
boolean sslOn,
int minPoolsize,
int maxPoolsize)
throws UnknownHostException,
IOException
port - local porthandler - the handler to usesslOn - true, is SSL should be activatedsslContext - the ssl context to useminPoolsize - the min workerpool sizemaxPoolsize - the max workerpool size
UnknownHostException - if the local host cannot determined
IOException - If some other I/O error occurs
public HttpServer(int port,
IHttpRequestHandler handler,
Map<String,Object> options,
SSLContext sslContext,
boolean sslOn)
throws UnknownHostException,
IOException
port - local portoptions - the acceptor socket optionshandler - the handler to usesslOn - true, is SSL should be activatedsslContext - the ssl context to use
UnknownHostException - if the local host cannot determined
IOException - If some other I/O error occurs
public HttpServer(String hostname,
int port,
IHttpRequestHandler handler,
SSLContext sslContext,
boolean sslOn)
throws UnknownHostException,
IOException
hostname - local hostnameport - local porthandler - the handler to usesslOn - true, is SSL should be activatedsslContext - the ssl context to use
UnknownHostException - if the local host cannot determined
IOException - If some other I/O error occurs
public HttpServer(String hostname,
int port,
IHttpRequestHandler handler,
Map<String,Object> options,
SSLContext sslContext,
boolean sslOn)
throws UnknownHostException,
IOException
hostname - local hostnameport - local portoptions - the acceptor socket optionshandler - the handler to usesslOn - true, is SSL should be activatedsslContext - the ssl context to use
UnknownHostException - if the local host cannot determined
IOException - If some other I/O error occurs
public HttpServer(InetAddress address,
int port,
IHttpRequestHandler handler,
SSLContext sslContext,
boolean sslOn)
throws UnknownHostException,
IOException
address - local addressport - local porthandler - the request handlersslOn - true, is SSL should be activatedsslContext - the ssl context to use
UnknownHostException - if the local host cannot determined
IOException - If some other I/O error occurs
public HttpServer(InetAddress address,
int port,
IHttpRequestHandler handler,
Map<String,Object> options,
SSLContext sslContext,
boolean sslOn)
throws UnknownHostException,
IOException
address - local addressport - local portoptions - the socket optionshandler - the request handlersslOn - true, is SSL should be activatedsslContext - the ssl context to use
UnknownHostException - if the local host cannot determined
IOException - If some other I/O error occurs| Method Detail |
|---|
public void addConnectionHandler(IHttpConnectionHandler connectionHandler)
connectionHandler - the connection handler to add
protected final void onPreRejectConnection(NonBlockingConnection connection)
throws IOException
onPreRejectConnection in class ServerIOExceptionpublic String getImplementationVersion()
getImplementationVersion in class Serverpublic String getImplementationDate()
getImplementationDate in class Serverpublic IHttpRequestHandler getRequestHandler()
getRequestHandler in interface IHttpServerpublic void setRequestTimeoutMillis(long receivetimeout)
setRequestTimeoutMillis in interface IHttpServerreceivetimeout - the message receive timeoutpublic void setAutoCompressThresholdBytes(int autocompressThresholdBytes)
setAutoCompressThresholdBytes in interface IHttpServerautocompressThresholdBytes - the autocompress thresholdpublic int getAutoCompressThresholdBytes()
getAutoCompressThresholdBytes in interface IHttpServerpublic void setAutoUncompress(boolean isAutoUncompress)
setAutoUncompress in interface IHttpServerisAutoUncompress - true, if the request will be uncompressed (if compressed)public final boolean isAutoUncompress()
isAutoUncompress in interface IHttpServerpublic long getRequestTimeoutMillis()
getRequestTimeoutMillis in interface IHttpServerpublic final void setBodyDataReceiveTimeoutMillis(long bodyDataReceiveTimeoutMillis)
setBodyDataReceiveTimeoutMillis in interface IHttpServerpublic long getBodyDataReceiveTimeoutMillis()
getBodyDataReceiveTimeoutMillis in interface IHttpServerpublic void setSessionMaxInactiveIntervalSec(int sessionMaxInactiveIntervalSec)
setSessionMaxInactiveIntervalSec in interface IHttpServersessionMaxInactiveIntervalSec - the session max inactive interval in secondspublic int getSessionMaxInactiveIntervalSec()
getSessionMaxInactiveIntervalSec in interface IHttpServerpublic void setCloseOnSendingError(boolean isCloseOnSendingError)
setCloseOnSendingError in interface IHttpServerisCloseOnSendingError - if the connection will closed, if an error message is sentpublic boolean isCloseOnSendingError()
isCloseOnSendingError in interface IHttpServerpublic void setRequestBodyDefaultEncoding(String defaultEncoding)
setRequestBodyDefaultEncoding in interface IHttpServerpublic String getRequestBodyDefaultEncoding()
getRequestBodyDefaultEncoding in interface IHttpServerpublic void setMaxTransactions(int maxTransactions)
setMaxTransactions in interface IHttpServermaxTransactions - the max transactionspublic int getMaxTransactions()
getMaxTransactions in interface IHttpServerpublic void setSessionManager(ISessionManager sessionManager)
setSessionManager in interface IHttpServersessionManager - the session managerpublic ISessionManager getSessionManager()
getSessionManager in interface IHttpServerpublic void setUsingCookies(boolean useCookies)
setUsingCookies in interface IHttpServeruseCookies - true, if cookies isused for session state managementpublic boolean isUsingCookies()
isUsingCookies in interface IHttpServer
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||