## org.apache.felix.httplite.server
Class Server

    java.lang.Object
      org.apache.felix.httplite.server.Server

    public class Server

extends java.lang.Object

This class implements a simple multi-threaded web server. It only supports GET/HEAD requests. The web server has various configurable properties that can be passed into the constructor; see the constructor for more information about configuration properties.

Field Summary
`static int` `ACTIVE_STATE` Server is active (running)
`static java.lang.String` `CONFIG_PROPERTY_CONNECTION_REQUESTLIMIT_PROP` Connection request limit property
`static java.lang.String` `CONFIG_PROPERTY_CONNECTION_TIMEOUT_PROP` Connection timeout property
`static java.lang.String` `CONFIG_PROPERTY_HTTP_DEBUG` Flag to enable debugging for this service implementation.
`static java.lang.String` `CONFIG_PROPERTY_HTTP_ENABLE` Flag to enable the use of HTTP.
`static java.lang.String` `CONFIG_PROPERTY_HTTP_PORT` The port used for servlets and resources available via HTTP.
`static java.lang.String` `CONFIG_PROPERTY_HTTPS_ENABLE` Flag to enable the user of HTTPS.
`static java.lang.String` `CONFIG_PROPERTY_THREADPOOL_LIMIT_PROP` Thread pool limit property
`static java.lang.String` `CONFIG_PROPERTY_THREADPOOL_TIMEOUT_PROP` Thread pool timeout property
`static int` `INACTIVE_STATE` Server is inactive (off).
`static int` `STOPPING_STATE` Server is shutting down.

Constructor Summary
`Server(java.util.Map configMap, Logger logger)` Construct a web server with the specified configuration.

Method Summary
`static int` `getConfiguredPort(java.util.Map configMap)` Get the port the HTTP server listens on based on configuration map or default value.
`java.lang.String` `getHostname()` Returns the hostname associated with the web server.
`int` `getPort()` Returns the port associated with the web server.
`int` `getState()` This method returns the current state of the web server, which is one of the following values: `HttpServer.INACTIVE_STATE` - the web server is currently not active.
`void` `setStopping()` Sets the stopping flag to true, meaning that further socket exceptions will not be logged as errors.
`void` `start(ServiceRegistrationResolver resolver)` This method starts the web server if it is not already active.
`void` `stop()` This method stops the web server if it is currently active.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### CONFIG_PROPERTY_CONNECTION_TIMEOUT_PROP

    public static final java.lang.String CONFIG_PROPERTY_CONNECTION_TIMEOUT_PROP

  Connection timeout property

  See Also:
    Constant Field Values

### CONFIG_PROPERTY_CONNECTION_REQUESTLIMIT_PROP

    public static final java.lang.String CONFIG_PROPERTY_CONNECTION_REQUESTLIMIT_PROP

  Connection request limit property

  See Also:
    Constant Field Values

### CONFIG_PROPERTY_THREADPOOL_TIMEOUT_PROP

    public static final java.lang.String CONFIG_PROPERTY_THREADPOOL_TIMEOUT_PROP

  Thread pool timeout property

  See Also:
    Constant Field Values

### CONFIG_PROPERTY_THREADPOOL_LIMIT_PROP

    public static final java.lang.String CONFIG_PROPERTY_THREADPOOL_LIMIT_PROP

  Thread pool limit property

  See Also:
    Constant Field Values

### CONFIG_PROPERTY_HTTP_DEBUG

    public static final java.lang.String CONFIG_PROPERTY_HTTP_DEBUG

  Flag to enable debugging for this service implementation. The default is false.

  See Also:
    Constant Field Values

### CONFIG_PROPERTY_HTTPS_ENABLE

    public static final java.lang.String CONFIG_PROPERTY_HTTPS_ENABLE

  Flag to enable the user of HTTPS. The default is false.

  See Also:
    Constant Field Values

### CONFIG_PROPERTY_HTTP_ENABLE

    public static final java.lang.String CONFIG_PROPERTY_HTTP_ENABLE

  Flag to enable the use of HTTP. The default is true.

  See Also:
    Constant Field Values

### CONFIG_PROPERTY_HTTP_PORT

    public static final java.lang.String CONFIG_PROPERTY_HTTP_PORT

  The port used for servlets and resources available via HTTP. The default is 8080. A negative port number has the same effect as setting org.apache.felix.http.enable to false.

  See Also:
    Constant Field Values

### INACTIVE_STATE

    public static final int INACTIVE_STATE

  Server is inactive (off).

  See Also:
    Constant Field Values

### ACTIVE_STATE

    public static final int ACTIVE_STATE

  Server is active (running)

  See Also:
    Constant Field Values

### STOPPING_STATE

    public static final int STOPPING_STATE

  Server is shutting down.

  See Also:
    Constant Field Values

Constructor Detail

### Server

    public Server(java.util.Map configMap,
                  Logger logger)

  Construct a web server with the specified configuration. The configuration map may contain the following properties:
  - `org.osgi.service.http.port` - the port on which it listens for connections; the default is 8080.
  - `org.apache.felix.http.threadpool.limit` - the maximum number of threads in the thread pool; the default value is 10.
  - `org.apache.felix.http.threadpool.timeout` - the inactivity timeout for threads in the thread pool after which time the threads will terminate; the default value is 60000 milliseconds.
  - `.org.apache.felix.http.connection.requestlimit` - the maximum number of requests that will be accepted over a persistent connection before closing the connection; the default value is 50.
  - `org.apache.felix.http.connection.timeout` - the inactivity timeout for persistent connections after which the connection is closed; the default value is 10000 milliseconds.
  The configuration properties cannot be changed after construction. The web server is not active until it is started.

  Parameters:
    `configMap` - The map of configuration properties; can be `null`.
    `logger` -

Method Detail

### getConfiguredPort

    public static int getConfiguredPort(java.util.Map configMap)

  Get the port the HTTP server listens on based on configuration map or default value.

  Parameters:
    `configMap` -
  Returns:
    port number that server listens on.

### getState

    public int getState()

  This method returns the current state of the web server, which is one of the following values:
  - `HttpServer.INACTIVE_STATE` - the web server is currently not active.
  - `HttpServer.ACTIVE_STATE` - the web server is active and serving files.
  - `HttpServer.STOPPING_STATE` - the web server is in the process of shutting down.

  Returns:
    The current state of the web server.

### getHostname

    public java.lang.String getHostname()

  Returns the hostname associated with the web server.

  Returns:
    The hostname associated with the web server.

### getPort

    public int getPort()

  Returns the port associated with the web server.

  Returns:
    The port associated with the web server.

### start

    public void start(ServiceRegistrationResolver resolver)
               throws java.io.IOException

  This method starts the web server if it is not already active.

  Parameters:
    `resolver` - Resolver is able to get Servlet or Resource based on request URI.
  Throws:
    `java.io.IOException` - If there are any networking issues.
    `java.lang.IllegalStateException` - If the server is in the `HttpServer.STOPPING_STATE` state.

### stop

    public void stop()
              throws java.lang.InterruptedException

  This method stops the web server if it is currently active. This method will block the calling thread until the web server is completely stopped. This can potentially take a long time, since it allows all existing connections to be processed before shutting down. Subsequent calls to this method will also block the caller. If a blocked thread is interrupted, the method will release the blocked thread by throwing an interrupted exception. In such a case, the web server will still continue its shutdown process.

  Throws:
    `java.lang.InterruptedException` - If the calling thread is interrupted.

### setStopping

    public void setStopping()

  Sets the stopping flag to true, meaning that further socket exceptions will not be logged as errors.

Copyright © 2006-2012 The Apache Software Foundation. All Rights Reserved.