link
Avalon
Avalon Planet
Home PlanetProductsCentral
HTTP Facility
Overview

The HTTP Facility provides an embedded web server, where components that implements the HttpRequestHandler interface can be mapped into the URL space of the server. Components are regular in all ways except that they implement the HttpRequestHandler interface. The service() method will be called when a request corresponds to the component's mapping into the URL space.

The main reason for this facility is to preserve the IoC and SoC aspects of Avalon, even in a HTTP server environment, since the Servlet API mixes the concerns in unwanted ways. Developers using Avalon are very productive using the Avalon Life Cycle contracts, and Merlin features. The power of Jetty and its embeddability creates a remarkable synergy between Merlin and Jetty.

Declaration

First of all you need to declare the HTTP Facility, and that is done by a simple component declaration in a suitable container;

  <component name="http-server" 
             class="org.apache.avalon.http.impl.DefaultServer"/>
  
  <component name="model-listener" 
             class="org.apache.avalon.http.impl.DefaultModelListener"/>

You may of course either use configurations together with the declaration, or in separate profile files (recommended).

Configuration

I think the easiest way is to show a full-fledged example, instead of the formal description. The configuration below is for the http-server component, not the model-listener

<configuration>
  
  <listeners>
    <listener type="socket">  <!-- Create a standard http socket listener -->
      <port>80</port>  <!-- Default: 8080 -->
      <hostname>myserver.mycompany.com</hostname> <!-- Default: all hosts -->
      <timeout>120000</timeout> <!-- Default: 60000 ms -->
    </listener>
  
    <listener type="jsse">  <!-- Create a SSL socket listener -->
      <port>443</port>  <!-- Default: 8443  -->
      <hostname>myserver.mycompany.com</hostname> <!-- Default: all hosts -->
      <timeout>120000</timeout> <!-- Default: 60000 ms -->
    </listener>
  
    <listener type="ajp">  <!-- Create a listener to a Apache Web Server -->
      <port>3232</port>  <!-- Default: 2345  -->
      <hostname>myserver.mycompany.com</hostname> <!-- Default: all hosts -->
      <timeout>120000</timeout> <!-- Default: 60000 ms -->
    </listener>
  
  </listeners>
  
  <mappings>
  
    <mapping>
      <url>/shopcart<url>
      <component>/http/handlers/ShoppingCartImpl</component>
    </mapping>
    
    <mapping>
      <url>/query<url>
      <component>/http/handlers/SearchEngineImpl</component>
    </mapping>
    
    <!-- Map the root to the Welcome Page implementation component -->
    <mapping>
      <url>/<url>
      <component>/http/handlers/WelcomePageImpl</component>
    </mapping>
    
  </mappings>
</configuration>

And there may be any number of listeners and mappings. Please note that compared to the Servlet API, the initialization values are not tied to the facility but to the component, in standard Avalon ways. It also means that the component can be used both as a normal component and a request handler.