org.xlightweb.server
Class HttpProtocolAdapter

Package class diagram package HttpProtocolAdapter
java.lang.Object
  extended by org.xlightweb.server.HttpProtocolAdapter
All Implemented Interfaces:
MBeanRegistration, IConnectHandler, IHandler, ILifeCycle

public final class HttpProtocolAdapter
extends Object
implements IConnectHandler, ILifeCycle, MBeanRegistration

The http protocol adapter. The protocol adapter implements the IConnectHandler interface, and "maps" each incoming connection into a HttpServerConnection.

HttpProtcol adapter will be required, if the HttpServer can not be used. See example:

 // establishing a http server based on a mutliplexed tcp connection
 // for multiplexed connections see http://xsocket.sourceforge.net/multiplexed/tutorial/V2/TutorialMultiplexed.htm    
    
 IRequestHandler hdl = new MyRequestHandler();
 IConnectHandler httpAdapter = new HttpProtocolAdapter(hdl);
 
 
 IServer mutliplexedHttpServer = new Server(8080, new MultiplexedProtocolAdapter(httpAdapter)));
 mutliplexedHttpServer.start();
 ...
 


Nested Class Summary
static interface HttpProtocolAdapter.SessionManagerInfoMBean
           
 
Field Summary
 
Fields inherited from interface org.xsocket.connection.IHandler
DEFAULT_EXECUTION_MODE
 
Constructor Summary
HttpProtocolAdapter(IHttpRequestHandler requestHandler)
          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 getImplementationVersion()
          returns the implementation version string
 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 sconds
 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 will be sent
 boolean isUsingCookies()
          returns true, if cookies is used for session state management
 boolean onConnect(INonBlockingConnection connection)
          
 void onDestroy()
          
 void onInit()
          
 void postDeregister()
          
 void postRegister(Boolean registrationDone)
          
 void preDeregister()
          
 ObjectName preRegister(MBeanServer mbeanServer, ObjectName name)
          
 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 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 requesttimeout)
          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 java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HttpProtocolAdapter

public HttpProtocolAdapter(IHttpRequestHandler requestHandler)
constructor

Parameters:
requestHandler - the requestHandler
connectionHandler - the connectionHandler or null
requestTimeoutHandler - the request timeout handler or null
Method Detail

getRequestHandler

public IHttpRequestHandler getRequestHandler()
returns the request handler

Returns:
the request handler

setSessionManager

public void setSessionManager(ISessionManager sessionManager)
sets the session manager

Parameters:
sessionManager - the session manager

setUsingCookies

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

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

isUsingCookies

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

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

getSessionManager

public ISessionManager getSessionManager()
returns the session manager

Returns:
the session manager

setRequestBodyDefaultEncoding

public 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

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

Returns:
the defaultEncoding

preRegister

public ObjectName preRegister(MBeanServer mbeanServer,
                              ObjectName name)
                       throws Exception

Specified by:
preRegister in interface MBeanRegistration
Throws:
Exception

postRegister

public void postRegister(Boolean registrationDone)

Specified by:
postRegister in interface MBeanRegistration

preDeregister

public void preDeregister()
                   throws Exception

Specified by:
preDeregister in interface MBeanRegistration
Throws:
Exception

postDeregister

public void postDeregister()

Specified by:
postDeregister in interface MBeanRegistration

setRequestTimeoutMillis

public void setRequestTimeoutMillis(long requesttimeout)
sets the message receive timeout

Parameters:
requesttimeout - the message receive timeout

setAutoCompressThresholdBytes

public void setAutoCompressThresholdBytes(int autocompressThresholdBytes)
sets the autocompress threshold of responses

Parameters:
autocompressThresholdBytes - the autocompress threshold

getAutoCompressThresholdBytes

public int getAutoCompressThresholdBytes()
gets the autocompress threshold of responses

Returns:
the autocompress threshold

setAutoUncompress

public 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

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

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

getRequestTimeoutMillis

public long getRequestTimeoutMillis()
gets the message receive timeout

Returns:
the message receive timeout

setBodyDataReceiveTimeoutMillis

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

Parameters:
bodyDataReceiveTimeoutSec - the timeout

getBodyDataReceiveTimeoutMillis

public long getBodyDataReceiveTimeoutMillis()
get the body data receive timeout

Returns:
the timeout

setCloseOnSendingError

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

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

isCloseOnSendingError

public boolean isCloseOnSendingError()
returns if the server-side connection will closed, if an error message will be sent

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

setMaxTransactions

public 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

public 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

setSessionMaxInactiveIntervalSec

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

Parameters:
sessionMaxInactiveIntervalSec - the session max inactive interval in seconds

getSessionMaxInactiveIntervalSec

public int getSessionMaxInactiveIntervalSec()
gets the session max inactive interval in sconds

Returns:
the session max inactive interval in sconds

addConnectionHandler

public void addConnectionHandler(IHttpConnectionHandler connectionHandler)
adds a connection handler

Parameters:
connectionHandler - the connection handler to add

getImplementationVersion

public String getImplementationVersion()
returns the implementation version string

Returns:
the implementation version string

onInit

public void onInit()

Specified by:
onInit in interface ILifeCycle

onDestroy

public void onDestroy()
               throws IOException

Specified by:
onDestroy in interface ILifeCycle
Throws:
IOException

onConnect

public boolean onConnect(INonBlockingConnection connection)
                  throws IOException

Specified by:
onConnect in interface IConnectHandler
Throws:
IOException