org.apache.excalibur.instrument.manager.http.server
Class HTTPServer

java.lang.Object
  extended by org.apache.avalon.framework.logger.AbstractLogEnabled
      extended by org.apache.excalibur.instrument.AbstractLogEnabledInstrumentable
          extended by org.apache.excalibur.instrument.manager.http.server.AbstractLogEnabledInstrumentableStartable
              extended by org.apache.excalibur.instrument.manager.http.server.AbstractSocketServer
                  extended by org.apache.excalibur.instrument.manager.http.server.HTTPServer
All Implemented Interfaces:
java.lang.Runnable, org.apache.avalon.framework.activity.Startable, org.apache.avalon.framework.logger.LogEnabled, org.apache.excalibur.instrument.Instrumentable

public class HTTPServer
extends AbstractSocketServer

Since:
4.1
Version:
CVS $Revision: 1.6 $ $Date: 2004/03/10 13:59:34 $
Author:
Avalon Development Team

Field Summary
private  java.lang.String m_accessLogFile
          Access log file name.
private  java.io.File m_currentLogFile
          The currently open log file.
private  java.io.PrintWriter m_currentLogWriter
          The currently open log PrintWriter.
private  java.text.SimpleDateFormat m_dayFormat
          DateFormat used when generating log file names.
private  HTTPURLHandler[] m_handlerArray
          Optimized array of the handler list that lets us avoid synchronization
private  java.util.List m_handlers
          List of registered HTTPURLHandlers.
private  org.apache.excalibur.instrument.CounterInstrument m_instrumentRequestBytes
          Number of request bytes received from the client.
private  org.apache.excalibur.instrument.CounterInstrument m_instrumentRequests
          Number of requests.
private  org.apache.excalibur.instrument.CounterInstrument m_instrumentResponseBytes
          Number of response bytes sent to the client.
private  java.text.SimpleDateFormat m_logTimeFormat
          DateFormat used when generating log entries.
 
Fields inherited from interface org.apache.excalibur.instrument.Instrumentable
EMPTY_INSTRUMENT_ARRAY, EMPTY_INSTRUMENTABLE_ARRAY
 
Constructor Summary
HTTPServer(int port, java.net.InetAddress bindAddress)
          Creates a new HTTPServer.
 
Method Summary
private  void decodeParameter(java.util.Map params, java.lang.String pair, java.lang.String encoding)
           
private  void decodeQuery(java.util.Map params, java.lang.String query, java.lang.String encoding)
           
private  HTTPURLHandler[] getHandlers()
           
private  boolean handleRequest(java.io.InputStream is, java.io.OutputStream os, java.lang.String ip)
           
protected  void handleSocket(java.net.Socket socket)
          Handle a newly connected socket.
private  void logAccessEvent(java.lang.String ip, java.lang.String method, java.lang.String url, int errorCode, int contentLength, java.lang.String referrer, java.lang.String userAgent)
           
 void registerHandler(HTTPURLHandler handler)
          Registers a new HTTP URL Handler with the server.
 void setAccessLogFile(java.lang.String accessLogFile)
          Access log file name.
 void setParameter(java.util.Map params, java.lang.String param, java.lang.String value)
           
 void stop()
          Stops the server.
 
Methods inherited from class org.apache.excalibur.instrument.manager.http.server.AbstractSocketServer
getSoTimeout, runner, start, stopRunner
 
Methods inherited from class org.apache.excalibur.instrument.manager.http.server.AbstractLogEnabledInstrumentableStartable
isStopping, run
 
Methods inherited from class org.apache.excalibur.instrument.AbstractLogEnabledInstrumentable
addChildInstrumentable, addInstrument, getChildInstrumentables, getInstrumentableName, getInstruments, setInstrumentableName
 
Methods inherited from class org.apache.avalon.framework.logger.AbstractLogEnabled
enableLogging, getLogger, setupLogger, setupLogger, setupLogger
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_handlers

private java.util.List m_handlers
List of registered HTTPURLHandlers.


m_handlerArray

private HTTPURLHandler[] m_handlerArray
Optimized array of the handler list that lets us avoid synchronization


m_accessLogFile

private java.lang.String m_accessLogFile
Access log file name. Null if not configured.


m_currentLogFile

private java.io.File m_currentLogFile
The currently open log file. May be null.


m_currentLogWriter

private java.io.PrintWriter m_currentLogWriter
The currently open log PrintWriter.


m_dayFormat

private java.text.SimpleDateFormat m_dayFormat
DateFormat used when generating log file names. Only use when synchronized.


m_logTimeFormat

private java.text.SimpleDateFormat m_logTimeFormat
DateFormat used when generating log entries. Only use when synchronized. The US Locale is set because other locales do not correctly show the month.


m_instrumentRequests

private org.apache.excalibur.instrument.CounterInstrument m_instrumentRequests
Number of requests.


m_instrumentResponseBytes

private org.apache.excalibur.instrument.CounterInstrument m_instrumentResponseBytes
Number of response bytes sent to the client. Includes all bytes, not only the content.


m_instrumentRequestBytes

private org.apache.excalibur.instrument.CounterInstrument m_instrumentRequestBytes
Number of request bytes received from the client.

Constructor Detail

HTTPServer

public HTTPServer(int port,
                  java.net.InetAddress bindAddress)
Creates a new HTTPServer.

Parameters:
port - The port on which the server will listen.
bindAddress - The address on which the server will listen for connections.
Method Detail

stop

public void stop()
          throws java.lang.Exception
Stops the server.

Specified by:
stop in interface org.apache.avalon.framework.activity.Startable
Overrides:
stop in class AbstractLogEnabledInstrumentableStartable
Throws:
java.lang.Exception - If there are any problems stopping the component.

handleSocket

protected void handleSocket(java.net.Socket socket)
Handle a newly connected socket. The implementation need not worry about closing the socket.

Specified by:
handleSocket in class AbstractSocketServer
Parameters:
socket - Newly connected Socket to be handled.

setAccessLogFile

public void setAccessLogFile(java.lang.String accessLogFile)
Access log file name. Null if not configured. If the log file name contains the string "yyyy_mm_dd" then that token will be replaced with the current day and the file will be rolled each day at midnight.

Parameters:
accessLogFile - Name of the log file or null if disabled.

registerHandler

public void registerHandler(HTTPURLHandler handler)
Registers a new HTTP URL Handler with the server.

Parameters:
handler - The handler to register.

logAccessEvent

private void logAccessEvent(java.lang.String ip,
                            java.lang.String method,
                            java.lang.String url,
                            int errorCode,
                            int contentLength,
                            java.lang.String referrer,
                            java.lang.String userAgent)

handleRequest

private boolean handleRequest(java.io.InputStream is,
                              java.io.OutputStream os,
                              java.lang.String ip)
                       throws java.io.IOException
Throws:
java.io.IOException

setParameter

public void setParameter(java.util.Map params,
                         java.lang.String param,
                         java.lang.String value)

decodeParameter

private void decodeParameter(java.util.Map params,
                             java.lang.String pair,
                             java.lang.String encoding)

decodeQuery

private void decodeQuery(java.util.Map params,
                         java.lang.String query,
                         java.lang.String encoding)

getHandlers

private HTTPURLHandler[] getHandlers()