Femto Web Server V1.4-F

dfischer.femtowebserver.httpd
Interface HttpdConnectionAdapterInterface

All Known Implementing Classes:
HttpdSocketConnectionAdapter

public interface HttpdConnectionAdapterInterface

Connection Adapters - network protocol listeners - are used to wire the Femto Web Server to a specific network protocol.

As result of this concept, the further processing of HTTP requests and response is network protocol independent. For example: listening for new HTTPS/SSL client connection instead of listening for a normal TCP/IP connection.

By following this concept consequently it has the impact, that in example the method HttpRequest.getRemoteAddress() returns a String instead of a java.net.InetAddress. So if you will find inside this Java Doc Pages an allude of the TCP/IP protocol please consider, that this is in fact only the most common case - but that theoretically any other network protocol could be used.

If a own connection adapter should be used it must be configured by calling the method Httpd.setConnectionAdapterClass(java.lang.String) before the Httpd tread starts with run().

If no special connection adapter has been configured, the Femto Web Server uses as default the already implemented connection adapter HttpdSocketConnectionAdapter.


The following program fragment illustrates how the Femto Web Server main thread Httpd deals with connection adapters:

 // init adapter
 ((HttpdConnectionAdapterInterface) connectionAdapterObject).init(httpdProperties);
 
 // server up and ready
 Stdout.log("# ... femto web server ready."); 
 
 while (!shutdown)
 {
     try
     {
         // wait for new client
         HttpdConnection connection = ((HttpdConnectionAdapterInterface) connectionAdapterObject).getNextConnection(httpdProperties);
 
 
         // process http request and response
         ...
         ...
 
     }
     catch (java.io.InterruptedIOException iex)
     {
         // normal: so timeout expired - no action
     }
     catch (IOException ie)
     {
         Stdout.log("# *** warning: unable process client, connection aborted ***");
         Stdout.log("# ", ie);
     }
 }
 
 Stdout.log("# femto web server shutdown ...");
 try { ((HttpdConnectionAdapterInterface) connectionAdapterObject).shutdown(httpdProperties); } catch (Exception e) {}

 

See Also:
Httpd.setConnectionAdapterClass(java.lang.String), HttpdConnection, HttpdSocketConnectionAdapter

Method Summary
 HttpdConnection getNextConnection(HttpdProperties httpdProperties)
          Listens for a new client connection and blocks until a new client connection is made.
 void init(HttpdProperties httpdProperties)
          Initializes the connection adapter.
 void shutdown(HttpdProperties httpdProperties)
          Closes the connection adapter.
 

Method Detail

init

public void init(HttpdProperties httpdProperties)
          throws java.lang.Exception
Initializes the connection adapter. Called by the Femto Web Server main thread Httpd only once when it is started.
Parameters:
httpdProperties - read/only access to the Femto Web Server configuration

getNextConnection

public HttpdConnection getNextConnection(HttpdProperties httpdProperties)
                                  throws java.lang.Exception
Listens for a new client connection and blocks until a new client connection is made.
The Femto Web Server calls this method as often as it's possible in an endless loop.
As result a network protocol independent HttpdConnection is given back to the Femto Web Server which is used to process the HTTP request.

From time to time (1..60 seconds) it would be fine that a java.io.InterruptedIOException is thrown by this method.
Optionally throwing the InterruptedIOException will not abort the Httpd main thread, but enables the Femto Web Sever to do a graceful shutdown if Httpd.shutdown() is called.

Parameters:
httpdProperties - read/only access to the Femto Web Server configuration
Returns:
the new client connection (network protocol independment).
See Also:
HttpdConnection, Httpd.shutdown(), Httpd.setConnectionAdapterClass(java.lang.String)

shutdown

public void shutdown(HttpdProperties httpdProperties)
              throws java.lang.Exception
Closes the connection adapter. Called from the Femto Web Server main thread only once when Httpd.shutdown() was called.
Parameters:
httpdProperties - read/only access to the Femto Web Server configuration
See Also:
Httpd.shutdown()

Femto Web Server V1.4-F

Copyright 2002, 2003, 2006 by Ingenieurbüro David Fischer GmbH, Switzerland. All rights reserved.