|
|||||||||
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 ipAddress,
int port,
IHttpRequestHandler handler)
constructor |
|
HttpServer(String ipAddress,
int port,
IHttpRequestHandler handler,
Map<String,Object> options)
constructor |
|
HttpServer(String ipAddress,
int port,
IHttpRequestHandler handler,
Map<String,Object> options,
SSLContext sslContext,
boolean sslOn)
constructor |
|
HttpServer(String ipAddress,
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 |
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 determinedpublic 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 determinedpublic 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 occurspublic 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 occurspublic 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 occurspublic 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 occurspublic HttpServer(String ipAddress, int port, IHttpRequestHandler handler) throws UnknownHostException, IOException
ipAddress
- the local ip addressport
- the local porthandler
- the handler to use
UnknownHostException
- if the local host cannot determined
IOException
- If some other I/O error occurspublic HttpServer(String ipAddress, int port, IHttpRequestHandler handler, Map<String,Object> options) throws UnknownHostException, IOException
ipAddress
- the local ip addressport
- the local porthandler
- the handler to useoptions
- the socket options
UnknownHostException
- if the local host cannot determined
IOException
- If some other I/O error occurspublic 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 occurspublic 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 occurspublic 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 occurspublic HttpServer(String ipAddress, int port, IHttpRequestHandler handler, SSLContext sslContext, boolean sslOn) throws UnknownHostException, IOException
ipAddress
- local ip addressport
- 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 occurspublic HttpServer(String ipAddress, int port, IHttpRequestHandler handler, Map<String,Object> options, SSLContext sslContext, boolean sslOn) throws UnknownHostException, IOException
ipAddress
- local ip addressport
- 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 occurspublic 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 occurspublic 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 occursMethod Detail |
---|
public void addConnectionHandler(IHttpConnectionHandler connectionHandler)
connectionHandler
- the connection handler to addpublic String getImplementationVersion()
getImplementationVersion
in class Server
public String getImplementationDate()
getImplementationDate
in class Server
public IHttpRequestHandler getRequestHandler()
getRequestHandler
in interface IHttpServer
public void setRequestTimeoutMillis(long receivetimeout)
setRequestTimeoutMillis
in interface IHttpServer
receivetimeout
- the message receive timeoutpublic void setAutoCompressThresholdBytes(int autocompressThresholdBytes)
setAutoCompressThresholdBytes
in interface IHttpServer
autocompressThresholdBytes
- the autocompress thresholdpublic int getAutoCompressThresholdBytes()
getAutoCompressThresholdBytes
in interface IHttpServer
public void setAutoUncompress(boolean isAutoUncompress)
setAutoUncompress
in interface IHttpServer
isAutoUncompress
- true, if the request will be uncompressed (if compressed)public final boolean isAutoUncompress()
isAutoUncompress
in interface IHttpServer
public long getRequestTimeoutMillis()
getRequestTimeoutMillis
in interface IHttpServer
public final void setBodyDataReceiveTimeoutMillis(long bodyDataReceiveTimeoutMillis)
setBodyDataReceiveTimeoutMillis
in interface IHttpServer
public long getBodyDataReceiveTimeoutMillis()
getBodyDataReceiveTimeoutMillis
in interface IHttpServer
public void setSessionMaxInactiveIntervalSec(int sessionMaxInactiveIntervalSec)
setSessionMaxInactiveIntervalSec
in interface IHttpServer
sessionMaxInactiveIntervalSec
- the session max inactive interval in secondspublic int getSessionMaxInactiveIntervalSec()
getSessionMaxInactiveIntervalSec
in interface IHttpServer
public void setCloseOnSendingError(boolean isCloseOnSendingError)
setCloseOnSendingError
in interface IHttpServer
isCloseOnSendingError
- if the connection will closed, if an error message is sentpublic boolean isCloseOnSendingError()
isCloseOnSendingError
in interface IHttpServer
public void setRequestBodyDefaultEncoding(String defaultEncoding)
setRequestBodyDefaultEncoding
in interface IHttpServer
public String getRequestBodyDefaultEncoding()
getRequestBodyDefaultEncoding
in interface IHttpServer
public void setMaxTransactions(int maxTransactions)
setMaxTransactions
in interface IHttpServer
maxTransactions
- the max transactionspublic int getMaxTransactions()
getMaxTransactions
in interface IHttpServer
public void setSessionManager(ISessionManager sessionManager)
setSessionManager
in interface IHttpServer
sessionManager
- the session managerpublic ISessionManager getSessionManager()
getSessionManager
in interface IHttpServer
public void setUsingCookies(boolean useCookies)
setUsingCookies
in interface IHttpServer
useCookies
- 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 |