svn commit: rev 23519 - in avalon/trunk/planet/facilities/http: impl/src/etc impl/src/main/org/apache/avalon/http/impl spi/src/main/org/apache/avalon/http

[email protected]
Newsgroups gmane.comp.jakarta.avalon.cvs
Message-ID <[email protected]>
Author: niclas
Date: Sun Jul 25 12:15:50 2004
New Revision: 23519

Modified:
   avalon/trunk/planet/facilities/http/impl/src/etc/default-server.xml
   avalon/trunk/planet/facilities/http/impl/src/main/org/apache/avalon/http/impl/HttpContextImpl.java
   avalon/trunk/planet/facilities/http/impl/src/main/org/apache/avalon/http/impl/HttpServerImpl.java
   avalon/trunk/planet/facilities/http/impl/src/main/org/apache/avalon/http/impl/ModelHandler.java
   avalon/trunk/planet/facilities/http/impl/src/main/org/apache/avalon/http/impl/NcsaRequestLog.java
   avalon/trunk/planet/facilities/http/impl/src/main/org/apache/avalon/http/impl/SocketListenerComponent.java
   avalon/trunk/planet/facilities/http/spi/src/main/org/apache/avalon/http/HttpContextService.java
Log:
More work towards the Http Facility goal. Server is now up and running but doesn't supply anything.

Modified: avalon/trunk/planet/facilities/http/impl/src/etc/default-server.xml
==============================================================================
--- avalon/trunk/planet/facilities/http/impl/src/etc/default-server.xml	(original)
+++ avalon/trunk/planet/facilities/http/impl/src/etc/default-server.xml	Sun Jul 25 12:15:50 2004
@@ -15,25 +15,36 @@
       <artifact>jar:avalon/framework/avalon-framework-legacy#SNAPSHOT</artifact>
       <artifact>jar:avalon/logkit/avalon-logkit#2.0.0</artifact>
       <artifact>jar:avalon/http/avalon-http-impl#SNAPSHOT</artifact>
+      <artifact>jar:commons-logging/commons-logging#SNAPSHOT</artifact>
     </classpath>
   </classloader>
 
   <component name="socketlistener" class="org.apache.avalon.http.impl.SocketListenerComponent">
     <parameters>
       <parameter name="port" value="8088"/>
+      <parameter name="hostname" value="0.0.0.0"/>
     </parameters>
   </component>
     
   <component name="server" class="org.apache.avalon.http.impl.HttpServerImpl" />
   
-  <component name="context" class="org.apache.avalon.http.impl.HttpContextImpl" />
+  <component name="context" class="org.apache.avalon.http.impl.HttpContextImpl" >
+    <configuration>
+      <context-path>/niclas/testing</context-path>
+    </configuration>
+  </component>
+  
   <component name="model-handler" class="org.apache.avalon.http.impl.ModelHandler" >
     <configuration>
-      <url-path>/test</url-path>
-      <component>test</component>
+      <index>5</index>
     </configuration>
   </component>
-  <component name="request-log" class="org.apache.avalon.http.impl.NcsaRequestLog" />
+  
+  <component name="request-log" class="org.apache.avalon.http.impl.NcsaRequestLog" >
+    <parameters>
+      <parameter name="filename" value="request.log" />
+    </parameters>
+  </component>
   
 <!--    
   <container name="model-context" >

Modified: avalon/trunk/planet/facilities/http/impl/src/main/org/apache/avalon/http/impl/HttpContextImpl.java
==============================================================================
--- avalon/trunk/planet/facilities/http/impl/src/main/org/apache/avalon/http/impl/HttpContextImpl.java	(original)
+++ avalon/trunk/planet/facilities/http/impl/src/main/org/apache/avalon/http/impl/HttpContextImpl.java	Sun Jul 25 12:15:50 2004
@@ -53,6 +53,7 @@
 /** Wrapper for the Jetty HttpContext.
  *
  * @avalon.component name="http-context" lifestyle="singleton"
+ * @avalon.service type="org.apache.avalon.http.HttpContextService"
  */
 public class HttpContextImpl
     implements LogEnabled, Contextualizable, Serviceable, Startable, 
@@ -68,6 +69,11 @@
         m_HttpContext = new HttpContext();
     }
     
+    public HttpContext getHttpContext()
+    {
+        return m_HttpContext;
+    }
+    
     /**
      * Enable the logging system.
      *
@@ -90,6 +96,7 @@
         throws ContextException
     {
         File tmpDir = (File) ctx.get( "urn:avalon:temp" );
+        tmpDir.mkdirs();
         m_HttpContext.setTempDirectory( tmpDir );
     }
     
@@ -108,20 +115,18 @@
     {
         m_HttpServer = (HttpService) man.lookup( "server" );
         
-        try
+        if( man.hasService( "authenticator" ) )
         {
             Authenticator auth = (Authenticator) man.lookup( "authenticator" );
             m_HttpContext.setAuthenticator( auth );
-        } catch( ServiceException e )
-        {} // ignore, quite ok.
+        }
         
-        try
+        if( man.hasService( "realm" ) )
         {
             UserRealm realm = (UserRealm) man.lookup( "realm" );
             m_HttpContext.setRealm( realm );
             m_HttpContext.setRealmName( realm.getName() ); // Is this necessary?
-        } catch( ServiceException e )
-        {} // ignore, quite ok.
+        } 
         
         RequestLog log = (RequestLog) man.lookup( "request-log" );
         m_HttpContext.setRequestLog( log );
@@ -147,7 +152,7 @@
         configureAttributes( attributes );
         
         Configuration contextPath = conf.getChild( "context-path" );
-        m_HttpContext.setContextPath( contextPath.getValue() );
+        m_HttpContext.setContextPath( contextPath.getValue( "/" ) );
         
         Configuration virtualHosts = conf.getChild( "virtual-hosts" );
         configureVirtualHosts( virtualHosts );
@@ -195,6 +200,8 @@
     public void start()
         throws Exception
     {
+        if( m_Logger.isDebugEnabled() )
+            m_Logger.debug( "Starting context: " + m_HttpContext );
         m_HttpServer.addContext( m_HttpContext );
         m_HttpContext.start();
     }
@@ -202,12 +209,16 @@
     public void stop()
         throws Exception
     {
+        if( m_Logger.isDebugEnabled() )
+            m_Logger.debug( "Stopping context: " + m_HttpContext );
         m_HttpContext.stop( m_Graceful );
         m_HttpServer.removeContext( m_HttpContext );
     }
     
     public void dispose()
     {
+        if( m_Logger.isDebugEnabled() )
+            m_Logger.debug( "Disposing context: " + m_HttpContext );
         m_HttpContext.destroy();
         m_HttpServer = null;
         m_HttpContext = null;
@@ -217,11 +228,15 @@
     
     public void addHandler( HttpHandler handler )
     {
+        if( m_Logger.isDebugEnabled() )
+            m_Logger.debug( "Adding handler: " + handler );
         m_HttpContext.addHandler( handler );
     }
     
     public void removeHandler( HttpHandler handler )
     {
+        if( m_Logger.isDebugEnabled() )
+            m_Logger.debug( "Removing handler: " + handler );
         m_HttpContext.removeHandler( handler );
     }
 }

Modified: avalon/trunk/planet/facilities/http/impl/src/main/org/apache/avalon/http/impl/HttpServerImpl.java
==============================================================================
--- avalon/trunk/planet/facilities/http/impl/src/main/org/apache/avalon/http/impl/HttpServerImpl.java	(original)
+++ avalon/trunk/planet/facilities/http/impl/src/main/org/apache/avalon/http/impl/HttpServerImpl.java	Sun Jul 25 12:15:50 2004
@@ -82,17 +82,23 @@
     public void start()
         throws MultiException
     {
+        if( m_Logger.isDebugEnabled() )
+            m_Logger.debug( "Starting server: " + this );
         super.start();
     }
     
     public void stop()
         throws InterruptedException
     {
+        if( m_Logger.isDebugEnabled() )
+            m_Logger.debug( "Stopping server: " + this );
         super.stop( m_Graceful );
     }
     
     public void dispose()
     {
+        if( m_Logger.isDebugEnabled() )
+            m_Logger.debug( "Disposing server: " + this );
         super.destroy();
     }
 } 

Modified: avalon/trunk/planet/facilities/http/impl/src/main/org/apache/avalon/http/impl/ModelHandler.java
==============================================================================
--- avalon/trunk/planet/facilities/http/impl/src/main/org/apache/avalon/http/impl/ModelHandler.java	(original)
+++ avalon/trunk/planet/facilities/http/impl/src/main/org/apache/avalon/http/impl/ModelHandler.java	Sun Jul 25 12:15:50 2004
@@ -39,13 +39,14 @@
 import org.apache.avalon.framework.service.ServiceManager;
 
 import org.apache.avalon.http.HttpRequestHandler;
+import org.apache.avalon.http.HttpContextService;
 
 import org.mortbay.http.HttpContext;
 import org.mortbay.http.HttpHandler;
 import org.mortbay.http.HttpRequest;
 import org.mortbay.http.HttpResponse;
 
-/** Wrapper for the Jetty HttpContext.
+/** Handler for requests targetted at the composition model.
  *
  * @avalon.component name="http-model-handler" lifestyle="singleton"
  * @avalon.service type="org.mortbay.http.HttpHandler"
@@ -54,11 +55,11 @@
     implements Serviceable, Configurable, Contextualizable, LogEnabled,
                HttpHandler, CompositionListener
 {
-    private Logger           m_Logger;
-    private ContainmentModel m_Model;
-    private HttpContext      m_Context;
-    private String           m_Name;
-    private boolean          m_Started;
+    private Logger              m_Logger;
+    private ContainmentModel    m_Model;
+    private HttpContextService  m_Context;
+    private String              m_Name;
+    private boolean             m_Started;
     
     public ModelHandler()
     {
@@ -101,10 +102,15 @@
         m_Model = (ContainmentModel) ctx.get( "urn:composition:containment.model" );
         m_Name = (String) ctx.get( "urn:avalon:name" );
     }
-   
+
+    /**  
+     * @avalon.dependency type="org.apache.avalon.http.HttpContextService"
+     *                    key="httpcontext" 
+     */
     public void service( ServiceManager man )
         throws ServiceException
     {
+        m_Context = (HttpContextService) man.lookup( "httpcontext" );
     }
     
     public void configure( Configuration conf )
@@ -116,7 +122,7 @@
    
     public HttpContext getHttpContext()
     {
-        return m_Context;
+        return m_Context.getHttpContext();
     }
     
     public String getName()
@@ -132,7 +138,7 @@
 
     public void initialize( HttpContext context )
     {
-        m_Context = context;
+        m_Logger.warn( "unhandled:  initialize( " + context + " );" );
     }
 
     /* Jetty LifeCycle interface */
@@ -144,11 +150,13 @@
     
     public void start()
     {
+        m_Context.addHandler( this );
         m_Started = true;
     }
     
     public void stop()
     {
+        m_Context.removeHandler( this );
         m_Started = false;
     }
    

Modified: avalon/trunk/planet/facilities/http/impl/src/main/org/apache/avalon/http/impl/NcsaRequestLog.java
==============================================================================
--- avalon/trunk/planet/facilities/http/impl/src/main/org/apache/avalon/http/impl/NcsaRequestLog.java	(original)
+++ avalon/trunk/planet/facilities/http/impl/src/main/org/apache/avalon/http/impl/NcsaRequestLog.java	Sun Jul 25 12:15:50 2004
@@ -69,7 +69,7 @@
             setLogDateFormat( dateformat );
     
         String ignorepaths = params.getParameter( "ignore-paths", null );
-        if( filename != null )
+        if( ignorepaths != null )
         {
             String[] paths = tokenize( ignorepaths );
             setIgnorePaths( paths );

Modified: avalon/trunk/planet/facilities/http/impl/src/main/org/apache/avalon/http/impl/SocketListenerComponent.java
==============================================================================
--- avalon/trunk/planet/facilities/http/impl/src/main/org/apache/avalon/http/impl/SocketListenerComponent.java	(original)
+++ avalon/trunk/planet/facilities/http/impl/src/main/org/apache/avalon/http/impl/SocketListenerComponent.java	Sun Jul 25 12:15:50 2004
@@ -97,6 +97,19 @@
         if( integralScheme != null )
             m_SocketListener.setIntegralScheme( integralScheme );
     
+        String host = params.getParameter( "hostname", null );
+        try
+        {
+            if( host != null )
+                m_SocketListener.setHost( host );
+        } catch( java.net.UnknownHostException e )
+        {
+            throw new ParameterException( "Unknown hostname: " + host );
+        }
+        
+        int port = params.getParameterAsInteger( "port", 8080 );
+        m_SocketListener.setPort( port );
+        
         int lowResMs = params.getParameterAsInteger( "low-resource-persist-ms", -1 );
         if( lowResMs > 0 )
             m_SocketListener.setLowResourcePersistTimeMs( lowResMs );
@@ -120,6 +133,8 @@
     public void start()
         throws Exception
     {
+        if( m_Logger.isDebugEnabled() )
+            m_Logger.debug( "Starting socket: " + m_SocketListener );
         m_HttpServer.addListener( m_SocketListener );
         m_SocketListener.start();
     }
@@ -127,6 +142,8 @@
     public void stop()
         throws Exception
     {
+        if( m_Logger.isDebugEnabled() )
+            m_Logger.debug( "Stopping socket: " + m_SocketListener );
         m_SocketListener.stop();
         m_HttpServer.removeListener( m_SocketListener );
     }

Modified: avalon/trunk/planet/facilities/http/spi/src/main/org/apache/avalon/http/HttpContextService.java
==============================================================================
--- avalon/trunk/planet/facilities/http/spi/src/main/org/apache/avalon/http/HttpContextService.java	(original)
+++ avalon/trunk/planet/facilities/http/spi/src/main/org/apache/avalon/http/HttpContextService.java	Sun Jul 25 12:15:50 2004
@@ -16,7 +16,8 @@
  */
 
 package org.apache.avalon.http;
- 
+
+import org.mortbay.http.HttpContext;
 import org.mortbay.http.HttpHandler;
 
 /**
@@ -29,4 +30,5 @@
     
     void removeHandler( HttpHandler handler );
     
+    HttpContext getHttpContext();
 }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.