cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r408059 - in /cocoon/trunk/core: cocoon-bootstrap/src/main/java/org/apache/cocoon/classloader/ cocoon-bootstrap/src/main/java/org/apache/cocoon/components/classloader/ cocoon-bootstrap/src/main/java/org/apache/cocoon/servlet/ cocoon-bootstr...
Date Sat, 20 May 2006 18:09:19 GMT
Author: cziegeler
Date: Sat May 20 11:09:18 2006
New Revision: 408059

URL: http://svn.apache.org/viewvc?rev=408059&view=rev
Log:
Refactoring and add ParanoidFilter implementation

Added:
    cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/classloader/
      - copied from r408039, cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/components/classloader/
    cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/classloader/AbstractClassLoaderFactory.java
      - copied, changed from r408052, cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/components/classloader/AbstractClassLoaderFactory.java
    cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/classloader/ClassLoaderConfiguration.java
      - copied, changed from r408052, cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/components/classloader/ClassLoaderConfiguration.java
    cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/classloader/ClassLoaderFactory.java
      - copied, changed from r408052, cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/components/classloader/ClassLoaderFactory.java
    cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/classloader/DefaultClassLoader.java
      - copied, changed from r408052, cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/components/classloader/DefaultClassLoader.java
    cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/classloader/DefaultClassLoaderFactory.java
      - copied, changed from r408052, cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/components/classloader/DefaultClassLoaderFactory.java
    cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/classloader/ReloadingClassLoader.java
      - copied, changed from r408052, cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/components/classloader/ReloadingClassLoader.java
    cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/classloader/ReloadingClassLoaderFactory.java
      - copied, changed from r408052, cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/components/classloader/ReloadingClassLoaderFactory.java
    cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/servlet/BootstrapClassLoaderManager.java
  (with props)
    cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/servlet/ParanoidServlet.java
      - copied, changed from r407842, cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/servlet/ParanoidCocoonServlet.java
    cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/servlet/ParanoidServletFilter.java
  (with props)
Removed:
    cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/classloader/ClassLoaderUtils.java
    cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/components/classloader/
    cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/servlet/BootstrapServlet.java
    cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/servlet/ParanoidClassLoader.java
    cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/servlet/ParanoidCocoonServlet.java
Modified:
    cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/util/ClassUtils.java
    cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/BeanFactoryFactoryImpl.java
    cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/util/ClassLoaderUtils.java

Copied: cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/classloader/AbstractClassLoaderFactory.java
(from r408052, cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/components/classloader/AbstractClassLoaderFactory.java)
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/classloader/AbstractClassLoaderFactory.java?p2=cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/classloader/AbstractClassLoaderFactory.java&p1=cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/components/classloader/AbstractClassLoaderFactory.java&r1=408052&r2=408059&rev=408059&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/components/classloader/AbstractClassLoaderFactory.java
(original)
+++ cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/classloader/AbstractClassLoaderFactory.java
Sat May 20 11:09:18 2006
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.cocoon.components.classloader;
+package org.apache.cocoon.classloader;
 
 import java.io.File;
 import java.io.FilenameFilter;

Copied: cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/classloader/ClassLoaderConfiguration.java
(from r408052, cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/components/classloader/ClassLoaderConfiguration.java)
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/classloader/ClassLoaderConfiguration.java?p2=cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/classloader/ClassLoaderConfiguration.java&p1=cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/components/classloader/ClassLoaderConfiguration.java&r1=408052&r2=408059&rev=408059&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/components/classloader/ClassLoaderConfiguration.java
(original)
+++ cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/classloader/ClassLoaderConfiguration.java
Sat May 20 11:09:18 2006
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.cocoon.components.classloader;
+package org.apache.cocoon.classloader;
 
 import java.util.ArrayList;
 import java.util.List;

Copied: cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/classloader/ClassLoaderFactory.java
(from r408052, cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/components/classloader/ClassLoaderFactory.java)
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/classloader/ClassLoaderFactory.java?p2=cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/classloader/ClassLoaderFactory.java&p1=cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/components/classloader/ClassLoaderFactory.java&r1=408052&r2=408059&rev=408059&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/components/classloader/ClassLoaderFactory.java
(original)
+++ cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/classloader/ClassLoaderFactory.java
Sat May 20 11:09:18 2006
@@ -3,18 +3,18 @@
  * 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.cocoon.components.classloader;
+package org.apache.cocoon.classloader;
 
 import javax.servlet.ServletContext;
 

Copied: cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/classloader/DefaultClassLoader.java
(from r408052, cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/components/classloader/DefaultClassLoader.java)
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/classloader/DefaultClassLoader.java?p2=cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/classloader/DefaultClassLoader.java&p1=cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/components/classloader/DefaultClassLoader.java&r1=408052&r2=408059&rev=408059&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/components/classloader/DefaultClassLoader.java
(original)
+++ cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/classloader/DefaultClassLoader.java
Sat May 20 11:09:18 2006
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.cocoon.components.classloader;
+package org.apache.cocoon.classloader;
 
 import java.io.File;
 import java.io.IOException;

Copied: cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/classloader/DefaultClassLoaderFactory.java
(from r408052, cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/components/classloader/DefaultClassLoaderFactory.java)
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/classloader/DefaultClassLoaderFactory.java?p2=cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/classloader/DefaultClassLoaderFactory.java&p1=cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/components/classloader/DefaultClassLoaderFactory.java&r1=408052&r2=408059&rev=408059&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/components/classloader/DefaultClassLoaderFactory.java
(original)
+++ cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/classloader/DefaultClassLoaderFactory.java
Sat May 20 11:09:18 2006
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.cocoon.components.classloader;
+package org.apache.cocoon.classloader;
 
 import java.net.URL;
 import java.util.List;

Copied: cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/classloader/ReloadingClassLoader.java
(from r408052, cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/components/classloader/ReloadingClassLoader.java)
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/classloader/ReloadingClassLoader.java?p2=cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/classloader/ReloadingClassLoader.java&p1=cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/components/classloader/ReloadingClassLoader.java&r1=408052&r2=408059&rev=408059&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/components/classloader/ReloadingClassLoader.java
(original)
+++ cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/classloader/ReloadingClassLoader.java
Sat May 20 11:09:18 2006
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.cocoon.components.classloader;
+package org.apache.cocoon.classloader;
 
 import java.net.URL;
 import java.net.URLStreamHandlerFactory;

Copied: cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/classloader/ReloadingClassLoaderFactory.java
(from r408052, cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/components/classloader/ReloadingClassLoaderFactory.java)
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/classloader/ReloadingClassLoaderFactory.java?p2=cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/classloader/ReloadingClassLoaderFactory.java&p1=cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/components/classloader/ReloadingClassLoaderFactory.java&r1=408052&r2=408059&rev=408059&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/components/classloader/ReloadingClassLoaderFactory.java
(original)
+++ cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/classloader/ReloadingClassLoaderFactory.java
Sat May 20 11:09:18 2006
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.cocoon.components.classloader;
+package org.apache.cocoon.classloader;
 
 import java.net.URL;
 import java.util.List;

Added: cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/servlet/BootstrapClassLoaderManager.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/servlet/BootstrapClassLoaderManager.java?rev=408059&view=auto
==============================================================================
--- cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/servlet/BootstrapClassLoaderManager.java
(added)
+++ cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/servlet/BootstrapClassLoaderManager.java
Sat May 20 11:09:18 2006
@@ -0,0 +1,141 @@
+/* 
+ * Copyright 2006 The 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.cocoon.servlet;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.LineNumberReader;
+import java.lang.reflect.InvocationTargetException;
+
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+
+import org.apache.cocoon.classloader.ClassLoaderConfiguration;
+import org.apache.cocoon.classloader.ClassLoaderFactory;
+import org.apache.cocoon.classloader.DefaultClassLoaderFactory;
+
+/**
+ * This class creates a singleton instance of the bootstrap class loader used
+ * by Cocoon.
+ *
+ * @version $Id$
+ * @since 2.2
+ */
+public class BootstrapClassLoaderManager {
+
+    protected static ClassLoader bootstrapClassLoader;
+
+    protected static final String CONTEXT_PREFIX = "context:";
+
+    protected static final String FILE_PREFIX = "file:";
+
+    public static synchronized ClassLoader getClassLoader(ServletContext servletContext)
+    throws ServletException {
+        if ( bootstrapClassLoader == null ) {
+            // Create configuration
+            ClassLoaderConfiguration config = new ClassLoaderConfiguration();
+
+            config.addClassDirectory("WEB-INF/classes");
+            config.addLibDirectory("WEB-INF/lib");
+            final String externalClasspath = servletContext.getInitParameter("bootstrap-classpath-file");
+            if ( externalClasspath != null ) {
+                getClassPath(externalClasspath, servletContext, config);
+            }
+
+            final String classLoaderFactoryName = servletContext.getInitParameter("bootstrap-classloader-factory");
+            if (classLoaderFactoryName != null) {
+                servletContext.log("Using classloader factory " + classLoaderFactoryName);
+            }
+            bootstrapClassLoader = createClassLoader(classLoaderFactoryName, servletContext,
config);
+        }
+        return bootstrapClassLoader;
+    }
+
+    protected static void getClassPath(final String                   externalClasspath,

+                                       final ServletContext           servletContext,
+                                       final ClassLoaderConfiguration config)
+    throws ServletException {
+        servletContext.log("Adding classpath from " + externalClasspath);
+
+        InputStream is = servletContext.getResourceAsStream(externalClasspath);
+        if ( is == null ) {
+            throw new ServletException("Classpath file " + externalClasspath + " can't be
found.");
+        }
+
+        try {
+            LineNumberReader lineReader = new LineNumberReader(new InputStreamReader(is));
+
+            String line;
+            do {
+                line = lineReader.readLine();
+                if (line != null) {
+                    if (line.startsWith("class-dir:")) {
+                        line = line.substring("class-dir:".length()).trim();
+                        if (line.startsWith(CONTEXT_PREFIX)) {
+                            line = line.substring(CONTEXT_PREFIX.length());
+                        }
+                        config.addClassDirectory(line);
+                    } else if (line.startsWith("lib-dir:")) {
+                        line = line.substring("lib-dir:".length()).trim();
+                        if (line.startsWith(CONTEXT_PREFIX)) {
+                            line = line.substring(CONTEXT_PREFIX.length());
+                        }
+                        config.addLibDirectory(line);
+                    } else if (line.startsWith("#")) {
+                        // skip it (consider it as comment)
+                    } else {
+                        // ignore it
+                    }
+                }
+            } while (line != null);
+            lineReader.close();
+        } catch (IOException io) {
+            throw new ServletException(io);
+        }
+    }
+
+    protected static ClassLoader createClassLoader(String                   factoryClassName,
+                                                   ServletContext           servletContext,
+                                                   ClassLoaderConfiguration config)
+    throws ServletException {
+        if ( factoryClassName == null ) {
+            factoryClassName = DefaultClassLoaderFactory.class.getName();
+        }
+        try {
+            final Class classLoaderFactoryClass = Class.forName(factoryClassName);
+            ClassLoaderFactory factory = (ClassLoaderFactory)classLoaderFactoryClass.newInstance();
+            return factory.createClassLoader(config.getClass().getClassLoader(), config,
servletContext, "/");
+        } catch (InstantiationException e) {
+            throw new ServletException("", e);
+        } catch (IllegalAccessException e) {
+            throw new ServletException("", e);
+        } catch (ClassNotFoundException e) {
+            throw new ServletException("", e);
+        } catch (SecurityException e) {
+            throw new ServletException("", e);
+        } catch (NoSuchMethodException e) {
+            throw new ServletException("", e);
+        } catch (IllegalArgumentException e) {
+            throw new ServletException("", e);
+        } catch (InvocationTargetException e) {
+            throw new ServletException("", e);
+        } catch (Exception e) {
+            throw new ServletException("", e);
+        }
+    }
+}

Propchange: cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/servlet/BootstrapClassLoaderManager.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/servlet/BootstrapClassLoaderManager.java
------------------------------------------------------------------------------
    svn:keywords = Id

Copied: cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/servlet/ParanoidServlet.java
(from r407842, cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/servlet/ParanoidCocoonServlet.java)
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/servlet/ParanoidServlet.java?p2=cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/servlet/ParanoidServlet.java&p1=cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/servlet/ParanoidCocoonServlet.java&r1=407842&r2=408059&rev=408059&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/servlet/ParanoidCocoonServlet.java
(original)
+++ cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/servlet/ParanoidServlet.java
Sat May 20 11:09:18 2006
@@ -1,12 +1,12 @@
 /*
- * Copyright 1999-2004 The Apache Software Foundation.
+ * Copyright 1999-2006 The 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.
@@ -15,17 +15,7 @@
  */
 package org.apache.cocoon.servlet;
 
-import java.io.File;
-import java.io.FileReader;
-import java.io.FilenameFilter;
 import java.io.IOException;
-import java.io.LineNumberReader;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.InvocationTargetException;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.List;
 
 import javax.servlet.Servlet;
 import javax.servlet.ServletConfig;
@@ -59,17 +49,13 @@
  *
  * @version $Id$
  */
-public class ParanoidCocoonServlet extends HttpServlet {
+public class ParanoidServlet extends HttpServlet {
 
     /**
      * The name of the actual servlet class.
      */
     public static final String DEFAULT_SERVLET_CLASS = "org.apache.cocoon.servlet.CocoonServlet";
 
-    protected static final String CONTEXT_PREFIX = "context:";
-
-    protected static final String FILE_PREFIX = "file:";
-
     protected Servlet servlet;
 
     protected ClassLoader classloader;
@@ -79,28 +65,14 @@
      */
     public void init(ServletConfig config) throws ServletException {
         super.init(config);
-        // Create the classloader in which we will load the servlet
-        // this can either be specified by an external file configured
-        // as a parameter in web.xml or (the default) all jars and
-        // classes from WEB-INF/lib and WEB-INF/classes are used.
-        final String externalClasspath = config.getInitParameter("paranoid-classpath");
-        final URL[] classPath = (externalClasspath == null)
-            ? getClassPath(getContextDir())
-            : getClassPath(externalClasspath, getContextDir());
-
-            
-        final String classLoaderName = config.getInitParameter("classloader-class");
-        if (classLoaderName != null) {
-            log("Using classloader " + classLoaderName);
-        }
-        this.classloader = createClassLoader(classLoaderName, getContextDir(), classPath);
+        // Get the classloader
+        this.classloader = BootstrapClassLoaderManager.getClassLoader(config.getServletContext());
 
         String servletName = config.getInitParameter("servlet-class");
         if (servletName == null) {
             servletName = DEFAULT_SERVLET_CLASS;
         }
         log("Loading servlet class " + servletName);
-
         
         // Create the servlet
         try {
@@ -120,7 +92,7 @@
             Thread.currentThread().setContextClassLoader(this.classloader);
 
             // Inlitialize the actual servlet
-            this.initServlet();
+            this.servlet.init(this.getServletConfig());
         } finally {
             Thread.currentThread().setContextClassLoader(old);
         }
@@ -128,164 +100,6 @@
     }
 
     /**
-     * Initialize the wrapped servlet. Subclasses (see {@link BootstrapServlet}
-     * change the <code>ServletConfig</code> given to the servlet.
-     * 
-     * @throws ServletException
-     */
-    protected void initServlet() throws ServletException {
-        this.servlet.init(this.getServletConfig());
-    }
-
-    /**
-     * Get the web application context directory.
-     * 
-     * @return the context dir
-     * @throws ServletException
-     */
-    protected File getContextDir() throws ServletException {
-        String result = getServletContext().getRealPath("/");
-        if (result == null) {
-            throw new ServletException(this.getClass().getName() + " cannot run in an undeployed
WAR file");
-        }
-        return new File(result);
-    }
-
-    protected URL[] getClassPath(final File contextDir) throws ServletException {
-        List urlList = new ArrayList();
-
-        try {
-            File classDir = new File(contextDir + "/WEB-INF/classes");
-            if (classDir.exists()) {
-                if (!classDir.isDirectory()) {
-                    throw new ServletException(classDir + " exists but is not a directory");
-                }
-
-                URL classURL = classDir.toURL();
-                log("Adding class directory " + classURL);
-                urlList.add(classURL);
-
-            }
-
-            // List all .jar and .zip
-            File libDir = new File(contextDir + "/WEB-INF/lib");
-            File[] libraries = libDir.listFiles(new JarFileFilter());
-
-            for (int i = 0; i < libraries.length; i++) {
-                URL lib = libraries[i].toURL();
-                log("Adding class library " + lib);
-                urlList.add(lib);
-            }
-        } catch (MalformedURLException mue) {
-            throw new ServletException(mue);
-        }
-
-        URL[] urls = (URL[]) urlList.toArray(new URL[urlList.size()]);
-
-        return urls;
-    }
-
-    protected URL[] getClassPath(final String externalClasspath, final File contextDir) throws
ServletException {
-        final List urlList = new ArrayList();
-
-        File file = new File(externalClasspath);
-        if (!file.isAbsolute()) {
-            file = new File(contextDir, externalClasspath);
-        }
-
-        log("Adding classpath from " + file);
-        try {
-            FileReader fileReader = new FileReader(file);
-            LineNumberReader lineReader = new LineNumberReader(fileReader);
-
-            String line;
-            do {
-                line = lineReader.readLine();
-                if (line != null) {
-                    if (line.startsWith("class-dir:")) {
-                        line = line.substring("class-dir:".length()).trim();
-                        if (line.startsWith(CONTEXT_PREFIX)) {
-                            line = contextDir + line.substring(CONTEXT_PREFIX.length());
-                        }
-                        URL url = new File(line).toURL();
-                        log("Adding class directory " + url);
-                        urlList.add(url);
-
-                    } else if (line.startsWith("lib-dir:")) {
-                        line = line.substring("lib-dir:".length()).trim();
-                        if (line.startsWith(CONTEXT_PREFIX)) {
-                            line = contextDir + line.substring(CONTEXT_PREFIX.length());
-                        }
-                        File dir = new File(line);
-                        File[] libraries = dir.listFiles(new JarFileFilter());
-                        log("Adding " + libraries.length + " libraries from " + dir.toURL());
-                        for (int i = 0; i < libraries.length; i++) {
-                            URL url = libraries[i].toURL();
-                            urlList.add(url);
-                        }
-                    } else if (line.startsWith("#")) {
-                        // skip it (consider it as comment)
-                    } else {
-                        // Consider it as a URL
-                        final URL lib;
-                        if (line.startsWith(CONTEXT_PREFIX)) {
-                            line = FILE_PREFIX + "/" + contextDir + line.substring(CONTEXT_PREFIX.length()).trim();
-                        }
-                        if (line.indexOf(':') == -1) {
-                            File entry = new File(line);
-                            lib = entry.toURL();
-                        } else {
-                            lib = new URL(line);
-                        }
-                        log("Adding class URL " + lib);
-                        urlList.add(lib);
-                    }
-                }
-            } while (line != null);
-            lineReader.close();
-        } catch (IOException io) {
-            throw new ServletException(io);
-        }
-        URL[] urls = (URL[]) urlList.toArray(new URL[urlList.size()]);
-
-        return urls;
-    }
-
-    protected ClassLoader createClassLoader(final String className,
-                                            final File contextDir,
-                                            final URL[] classPath)
-    throws ServletException {
-        if (className != null && !className.equals(ParanoidClassLoader.class.getName()))
{
-            try {
-                final Class classLoaderClass = Class.forName(className);
-                final Class[] parameterClasses = new Class[] { ClassLoader.class, File.class
};
-                final Constructor constructor = classLoaderClass.getConstructor(parameterClasses);
-                // REVISIT: make the path configurable
-                final Object[] parameters = new Object[] { this.getClass().getClassLoader(),
-                        new File(contextDir, "WEB-INF/compile") };
-                final ClassLoader classloader = (ClassLoader) constructor.newInstance(parameters);
-                return classloader;
-            } catch (InstantiationException e) {
-                throw new ServletException("", e);
-            } catch (IllegalAccessException e) {
-                throw new ServletException("", e);
-            } catch (ClassNotFoundException e) {
-                throw new ServletException("", e);
-            } catch (SecurityException e) {
-                throw new ServletException("", e);
-            } catch (NoSuchMethodException e) {
-                throw new ServletException("", e);
-            } catch (IllegalArgumentException e) {
-                throw new ServletException("", e);
-            } catch (InvocationTargetException e) {
-                throw new ServletException("", e);
-            }
-        } else {
-            return new ParanoidClassLoader(classPath, this.getClass().getClassLoader());
-        }
-    }
-
-    /**
      * Service the request by delegating the call to the real servlet
      */
     public void service(ServletRequest request, ServletResponse response) throws ServletException,
IOException {
@@ -312,11 +126,5 @@
             }
         }
         super.destroy();
-    }
-
-    private class JarFileFilter implements FilenameFilter {
-        public boolean accept(File dir, String name) {
-            return name.endsWith(".zip") || name.endsWith(".jar");
-        }
     }
 }

Added: cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/servlet/ParanoidServletFilter.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/servlet/ParanoidServletFilter.java?rev=408059&view=auto
==============================================================================
--- cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/servlet/ParanoidServletFilter.java
(added)
+++ cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/servlet/ParanoidServletFilter.java
Sat May 20 11:09:18 2006
@@ -0,0 +1,100 @@
+/*
+ * Copyright 2006 The 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.cocoon.servlet;
+
+import java.io.IOException;
+
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+
+/**
+ * @version $Id$
+ */
+public class ParanoidServletFilter implements Filter {
+
+    protected Filter filter;
+
+    protected ClassLoader classloader;
+
+    /**
+     * @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse,
javax.servlet.FilterChain)
+     */
+    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
+    throws IOException, ServletException {
+        if ( this.filter != null ) {
+            final ClassLoader old = Thread.currentThread().getContextClassLoader();
+            try {
+                Thread.currentThread().setContextClassLoader(this.classloader);
+
+                this.filter.doFilter(request, response, chain);
+            } finally {
+                Thread.currentThread().setContextClassLoader(old);
+            }            
+        }
+    }
+
+    /**
+     * @see javax.servlet.Filter#init(javax.servlet.FilterConfig)
+     */
+    public void init(FilterConfig config) throws ServletException {
+        // Get the classloader
+        this.classloader = BootstrapClassLoaderManager.getClassLoader(config.getServletContext());
+
+        String filterName = config.getInitParameter("filter-class");
+        if (filterName == null) {
+            throw new ServletException("Filter-class parameter is missing.");
+        }
+        
+        // Create the filter
+        try {
+
+            Class filterClass = this.classloader.loadClass(filterName);
+            this.filter = (Filter) filterClass.newInstance();
+
+        } catch (Exception e) {
+            throw new ServletException("Cannot load filter " + filterName, e);
+        }
+
+        final ClassLoader old = Thread.currentThread().getContextClassLoader();
+        try {
+            Thread.currentThread().setContextClassLoader(this.classloader);
+
+            // Inlitialize the actual filter
+            this.filter.init(config);
+        } finally {
+            Thread.currentThread().setContextClassLoader(old);
+        }
+    }
+
+    /**
+     * @see javax.servlet.Filter#destroy()
+     */
+    public void destroy() {
+        if (this.filter != null) {
+            final ClassLoader old = Thread.currentThread().getContextClassLoader();
+            try {
+                Thread.currentThread().setContextClassLoader(this.classloader);
+                this.filter.destroy();
+            } finally {
+                Thread.currentThread().setContextClassLoader(old);
+            }
+        }
+    }
+}
\ No newline at end of file

Propchange: cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/servlet/ParanoidServletFilter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/servlet/ParanoidServletFilter.java
------------------------------------------------------------------------------
    svn:keywords = Id

Modified: cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/util/ClassUtils.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/util/ClassUtils.java?rev=408059&r1=408058&r2=408059&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/util/ClassUtils.java
(original)
+++ cocoon/trunk/core/cocoon-bootstrap/src/main/java/org/apache/cocoon/util/ClassUtils.java
Sat May 20 11:09:18 2006
@@ -1,12 +1,12 @@
 /*
  * Copyright 1999-2004 The 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.
@@ -73,5 +73,4 @@
     public static ClassLoader getClassLoader() {
         return Thread.currentThread().getContextClassLoader();
     }
-
 }

Modified: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/BeanFactoryFactoryImpl.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/BeanFactoryFactoryImpl.java?rev=408059&r1=408058&r2=408059&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/BeanFactoryFactoryImpl.java
(original)
+++ cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/BeanFactoryFactoryImpl.java
Sat May 20 11:09:18 2006
@@ -19,9 +19,9 @@
 import org.apache.avalon.framework.context.Context;
 import org.apache.avalon.framework.logger.Logger;
 import org.apache.cocoon.ProcessingUtil;
+import org.apache.cocoon.classloader.ClassLoaderConfiguration;
+import org.apache.cocoon.classloader.ClassLoaderFactory;
 import org.apache.cocoon.components.ContextHelper;
-import org.apache.cocoon.components.classloader.ClassLoaderConfiguration;
-import org.apache.cocoon.components.classloader.ClassLoaderFactory;
 import org.apache.cocoon.core.Settings;
 import org.apache.cocoon.core.container.util.ClassLoaderUtils;
 import org.apache.cocoon.environment.Request;

Modified: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/util/ClassLoaderUtils.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/util/ClassLoaderUtils.java?rev=408059&r1=408058&r2=408059&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/util/ClassLoaderUtils.java
(original)
+++ cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/util/ClassLoaderUtils.java
Sat May 20 11:09:18 2006
@@ -18,7 +18,7 @@
 
 import org.apache.avalon.framework.configuration.Configuration;
 import org.apache.avalon.framework.configuration.ConfigurationException;
-import org.apache.cocoon.components.classloader.ClassLoaderConfiguration;
+import org.apache.cocoon.classloader.ClassLoaderConfiguration;
 
 /**
  * Utility class for converting Avalon based Configuration into a {@link ClassLoaderConfiguration}.



Mime
View raw message