org.xlightweb.server
Interface IHttpServer

Package class diagram package IHttpServer
All Superinterfaces:
Closeable, IServer, Runnable
All Known Implementing Classes:
HttpServer

public interface IHttpServer
extends IServer

A HttpServer definition. 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 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
 
Method Summary
 int getAutoCompressThresholdBytes()
          gets the autocompress threshold of responses
 long getBodyDataReceiveTimeoutMillis()
          get the body data receive timeout
 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 timeoutMillis)
          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 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
 

Method Detail

getRequestHandler

IHttpRequestHandler getRequestHandler()
returns the request handler

Returns:
the request handler

setAutoUncompress

void setAutoUncompress(boolean isAutoUncompress)
set if the request will be uncompressed (if compressed)

Parameters:
isAutoUncompress - true, if the request will be uncompressed (if compressed)

isAutoUncompress

boolean isAutoUncompress()
return true, if the request will be uncompressed (if compressed)

Returns:
true, if the request will be uncompressed (if compressed)

setCloseOnSendingError

void setCloseOnSendingError(boolean isCloseOnSendingError)
set is if the server-side connection will closed, if an error message (4xx or 5xx) is sent

Parameters:
isCloseOnSendingError - if the connection will closed, if an error message is sent

isCloseOnSendingError

boolean isCloseOnSendingError()
returns if the server-side connection will closed, if an error message (4xx or 5xx) will be sent

Returns:
true, if the connection will closed by sending an error message

setUsingCookies

void setUsingCookies(boolean useCookies)
sets if cookies is used for session state management

Parameters:
useCookies - true, if cookies isused for session state management

isUsingCookies

boolean isUsingCookies()
returns true, if cookies is used for session state management

Returns:
true, if cookies is used for session state management

setAutoCompressThresholdBytes

void setAutoCompressThresholdBytes(int autocompressThresholdBytes)
sets the autocompress threshold of responses. Setting the threshold to Integer.MAX_VALUE deactivates autocompressing

Parameters:
autocompressThresholdBytes - the autocompress threshold

getAutoCompressThresholdBytes

int getAutoCompressThresholdBytes()
gets the autocompress threshold of responses

Returns:
the autocompress threshold

setBodyDataReceiveTimeoutMillis

void setBodyDataReceiveTimeoutMillis(long bodyDataReceiveTimeoutMillis)
set the body data receive timeout

Parameters:
bodyDataReceiveTimeoutSec - the timeout

getBodyDataReceiveTimeoutMillis

long getBodyDataReceiveTimeoutMillis()
get the body data receive timeout

Returns:
the timeout

setSessionMaxInactiveIntervalSec

void setSessionMaxInactiveIntervalSec(int sessionMaxInactiveIntervalSec)
sets the session max inactive interval in seconds

Parameters:
sessionMaxInactiveIntervalSec - the session max inactive interval in seconds

getSessionMaxInactiveIntervalSec

int getSessionMaxInactiveIntervalSec()
gets the session max inactive interval in seconds

Returns:
the session max inactive interval in seconds

setMaxTransactions

void setMaxTransactions(int maxTransactions)
set the max transactions per connection. Setting this filed causes that a keep-alive response header will be added

Parameters:
maxTransactions - the max transactions

getMaxTransactions

int getMaxTransactions()
get the max transactions per connection. Setting this filed causes that a keep-alive response header will be added

Returns:
the max transactions

setRequestBodyDefaultEncoding

void setRequestBodyDefaultEncoding(String defaultEncoding)
set the request body default encoding. According to RFC 2616 the initial value is ISO-8859-1

Parameters:
encoding - the defaultEncoding

getRequestBodyDefaultEncoding

String getRequestBodyDefaultEncoding()
get the request body default encoding. According to RFC 2616 the initial value is ISO-8859-1

Returns:
the defaultEncoding

setSessionManager

void setSessionManager(ISessionManager sessionManager)
sets the session manager

Parameters:
sessionManager - the session manager

getSessionManager

ISessionManager getSessionManager()
returns the session manager

Returns:
the session manager

getRequestTimeoutMillis

long getRequestTimeoutMillis()
gets the message receive timeout

Returns:
the message receive timeout

setRequestTimeoutMillis

void setRequestTimeoutMillis(long timeoutMillis)
sets the message receive timeout

Parameters:
timeoutMillis - the message receive timeout