avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nic...@apache.org
Subject svn commit: rev 30712 - in avalon/trunk/planet/facilities/http: impl/src/etc impl/src/main/org/apache/avalon/http/impl spi/src/main/org/apache/avalon/http
Date Mon, 26 Jul 2004 11:31:06 GMT
Author: niclas
Date: Mon Jul 26 04:31:06 2004
New Revision: 30712

Added:
   avalon/trunk/planet/facilities/http/impl/src/main/org/apache/avalon/http/impl/SystemMimeTypes.java
  (contents, props changed)
   avalon/trunk/planet/facilities/http/spi/src/main/org/apache/avalon/http/MimeTypes.java
  (contents, props changed)
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/NcsaRequestLog.java
   avalon/trunk/planet/facilities/http/impl/src/main/org/apache/avalon/http/impl/ResourceHandler.java
Log:
Static content is finally served.

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	Mon Jul 26 04:31:06
2004
@@ -28,11 +28,15 @@
     
   <component name="server" class="org.apache.avalon.http.impl.HttpServerImpl" />
   
+  <component name="mimetypes" class="org.apache.avalon.http.impl.SystemMimeTypes" />
+  
   <component name="context" class="org.apache.avalon.http.impl.HttpContextImpl" >
     <configuration>
       <context-path>/niclas/testing</context-path>
     </configuration>
   </component>
+  
+  
 <!--  
   <component name="security-handler" class="org.apache.avalon.http.impl.SecurityHandler"
>
     <parameters>

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
Mon Jul 26 04:31:06 2004
@@ -44,6 +44,7 @@
 
 import org.apache.avalon.http.HttpContextService;
 import org.apache.avalon.http.HttpService;
+import org.apache.avalon.http.MimeTypes;
 
 import org.mortbay.http.Authenticator;
 import org.mortbay.http.HttpContext;
@@ -65,8 +66,13 @@
     private Logger      m_Logger;
     private boolean     m_Graceful;
     private File        m_TemporaryDir;
+    private File        m_ResourceBase;
+    private int         m_MaxCacheSize;
+    private int         m_MaxCachedFilesize;
+    
     private ClassLoader m_ClassLoader;
     private RequestLog  m_RequestLog;
+    private MimeTypes   m_MimeTypes;
     
     public HttpContextImpl()
     {
@@ -110,6 +116,8 @@
     /**
      * @avalon.dependency type="org.apache.avalon.http.HttpService"
      *                    key="server"
+     * @avalon.dependency type="org.apache.avalon.http.MimeTypes"
+     *                    key="mimetypes"
      * @avalon.dependency type="org.mortbay.http.Authenticator"
      *                    key="authenticator" optional="true"
      * @avalon.dependency type="org.mortbay.http.UserRealm"
@@ -136,6 +144,8 @@
         } 
         
         m_RequestLog = (RequestLog) man.lookup( "request-log" );
+        
+        m_MimeTypes = (MimeTypes) man.lookup( "mimetypes" );
     }
 
     public void parameterize( Parameters params )
@@ -167,6 +177,13 @@
     
         Configuration welcomeFiles = conf.getChild( "welcome-files" );
         configureWelcomeFiles( welcomeFiles );
+        
+        String resourceBase = conf.getChild( "resource-base").getValue( "." );
+        m_ResourceBase = new File( resourceBase );
+        
+        m_MaxCachedFilesize = conf.getChild( "max-cached-filesize" ).getValueAsInteger( -1
);
+        
+        m_MaxCacheSize = conf.getChild( "max-cache-size" ).getValueAsInteger( -1 );
     }
     
     private void configureAttributes( Configuration conf )
@@ -206,10 +223,17 @@
     }
 
     public void initialize()
+        throws ConfigurationException
     {
         m_HttpContext.setClassLoader( m_ClassLoader );
         m_HttpContext.setTempDirectory( m_TemporaryDir );
         m_HttpContext.setRequestLog( m_RequestLog );
+        m_HttpContext.setResourceBase( m_ResourceBase.getAbsolutePath() );
+        if( m_MaxCacheSize > 0 )
+            m_HttpContext.setMaxCacheSize( m_MaxCacheSize );        
+        if( m_MaxCachedFilesize > 0 )
+            m_HttpContext.setMaxCachedFileSize( m_MaxCachedFilesize );        
+        m_HttpContext.setMimeMap( m_MimeTypes.getExtensionMap() );
     }
         
     public void start()

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
Mon Jul 26 04:31:06 2004
@@ -33,7 +33,7 @@
 /** Wrapper for the Jetty NCSA request logger.
  *
  * @avalon.component name="http-ncsa-log" lifestyle="singleton"
- * @avalon.service type="org.mortbay.http.RequestLog" lifestyle="singleton"
+ * @avalon.service type="org.mortbay.http.RequestLog"
  */
 public class NcsaRequestLog extends NCSARequestLog
     implements RequestLog, Parameterizable, Startable

Modified: avalon/trunk/planet/facilities/http/impl/src/main/org/apache/avalon/http/impl/ResourceHandler.java
==============================================================================
--- avalon/trunk/planet/facilities/http/impl/src/main/org/apache/avalon/http/impl/ResourceHandler.java
(original)
+++ avalon/trunk/planet/facilities/http/impl/src/main/org/apache/avalon/http/impl/ResourceHandler.java
Mon Jul 26 04:31:06 2004
@@ -45,7 +45,7 @@
 
 /**
  * @avalon.component name="http-resource-handler" lifestyle="singleton"
- * @avalon.server    type="org.mortbay.http.HttpHandler"
+ * @avalon.service   type="org.mortbay.http.HttpHandler"
  */
 public class ResourceHandler 
     extends org.mortbay.http.handler.ResourceHandler 
@@ -167,4 +167,4 @@
         super.handleGet( request, response, pathInContext, pathParams, resource );
     }
 
-}
\ No newline at end of file
+}

Added: avalon/trunk/planet/facilities/http/impl/src/main/org/apache/avalon/http/impl/SystemMimeTypes.java
==============================================================================
--- (empty file)
+++ avalon/trunk/planet/facilities/http/impl/src/main/org/apache/avalon/http/impl/SystemMimeTypes.java
Mon Jul 26 04:31:06 2004
@@ -0,0 +1,123 @@
+/* 
+ * Copyright 2004 Apache Software Foundation
+ * Licensed  under the  Apache License,  Version 2.0  (the "License");
+ * you may not use  this file  except in  compliance with the License.
+ * You may obtain a copy of the License at 
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed  under the  License is distributed on an "AS IS" BASIS,
+ * WITHOUT  WARRANTIES OR CONDITIONS  OF ANY KIND, either  express  or
+ * implied.
+ * 
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.avalon.http.impl;
+
+import java.io.BufferedReader;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStreamReader;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.StringTokenizer;
+
+import org.apache.avalon.framework.activity.Initializable;
+
+import org.apache.avalon.framework.parameters.ParameterException;
+import org.apache.avalon.framework.parameters.Parameterizable;
+import org.apache.avalon.framework.parameters.Parameters;
+
+import org.apache.avalon.http.MimeTypes;
+
+/**
+ * @avalon.component name="mimetypes" lifestyle="singleton"
+ * @avalon.service  type="org.apache.avalon.http.MimeTypes"
+ */
+public class SystemMimeTypes
+    implements Parameterizable, Initializable, MimeTypes
+{
+    private String m_Filename;
+    private HashMap m_MimeTypeToExtMap;
+    private HashMap m_ExtToMimeTypeMap;
+    
+    public SystemMimeTypes()
+    {
+    }
+    
+    public void parameterize( Parameters params )
+        throws ParameterException
+    {
+        m_Filename = params.getParameter( "filename", "/etc/mime.types" );
+    }
+    
+    public void initialize()
+        throws Exception
+    {
+        m_MimeTypeToExtMap = new HashMap();
+        m_ExtToMimeTypeMap = new HashMap();
+        
+        FileInputStream fis = null;
+        InputStreamReader isr = null;
+        BufferedReader in = null;
+        try
+        {
+            fis = new FileInputStream( m_Filename );
+            isr = new InputStreamReader( fis );
+            in = new BufferedReader( isr );
+            
+            String line;
+            while( (line = in.readLine() ) != null )
+            {
+                processLine( line );
+            }
+        } finally
+        {
+            if( in != null )
+                in.close();
+            if( isr != null )
+                isr.close();
+            if( fis != null )
+                fis.close();
+        }
+    }
+
+    public Map getExtensionMap()
+    {
+        return m_ExtToMimeTypeMap;
+    }
+    
+    public String getMimeType( String extension )
+    {
+        return (String) m_ExtToMimeTypeMap.get( extension );
+    }
+    
+    public String[] getExtensions( String mimetype )
+    {
+        return (String[]) m_MimeTypeToExtMap.get( mimetype );
+    }
+    
+    private void processLine( String line )
+    {
+        if( "".equals( line ) )
+            return;
+
+        StringTokenizer st = new StringTokenizer( line, " ", false );
+        String mimetype = st.nextToken();
+        ArrayList exts = new ArrayList();        
+        while( st.hasMoreTokens() )
+        {
+            String extension = st.nextToken();
+            exts.add( extension );
+            m_ExtToMimeTypeMap.put( extension, mimetype );
+        }
+        String[] extensions = new String[ exts.size() ];
+        exts.toArray( extensions );
+        m_MimeTypeToExtMap.put( mimetype, exts );
+    }
+} 

Added: avalon/trunk/planet/facilities/http/spi/src/main/org/apache/avalon/http/MimeTypes.java
==============================================================================
--- (empty file)
+++ avalon/trunk/planet/facilities/http/spi/src/main/org/apache/avalon/http/MimeTypes.java
Mon Jul 26 04:31:06 2004
@@ -0,0 +1,32 @@
+/* 
+ * Copyright 2004 Apache Software Foundation
+ * Licensed  under the  Apache License,  Version 2.0  (the "License");
+ * you may not use  this file  except in  compliance with the License.
+ * You may obtain a copy of the License at 
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed  under the  License is distributed on an "AS IS" BASIS,
+ * WITHOUT  WARRANTIES OR CONDITIONS  OF ANY KIND, either  express  or
+ * implied.
+ * 
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.avalon.http;
+ 
+import java.util.Map;
+
+
+public interface MimeTypes
+{
+
+    Map getExtensionMap();
+    
+    String getMimeType( String extension );
+    
+    String[] getExtensions( String mimetype );
+    
+}
\ No newline at end of file

---------------------------------------------------------------------
To unsubscribe, e-mail: cvs-unsubscribe@avalon.apache.org
For additional commands, e-mail: cvs-help@avalon.apache.org


Mime
View raw message