james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rdon...@apache.org
Subject svn commit: r564484 - /james/jsieve/trunk/src/main/java/org/apache/jsieve/ConfigurationManager.java
Date Fri, 10 Aug 2007 06:27:13 GMT
Author: rdonkin
Date: Thu Aug  9 23:27:12 2007
New Revision: 564484

URL: http://svn.apache.org/viewvc?view=rev&rev=564484
Log:
Support for context classloader. https://issues.apache.org/jira/browse/JSIEVE-5.

Modified:
    james/jsieve/trunk/src/main/java/org/apache/jsieve/ConfigurationManager.java

Modified: james/jsieve/trunk/src/main/java/org/apache/jsieve/ConfigurationManager.java
URL: http://svn.apache.org/viewvc/james/jsieve/trunk/src/main/java/org/apache/jsieve/ConfigurationManager.java?view=diff&rev=564484&r1=564483&r2=564484
==============================================================================
--- james/jsieve/trunk/src/main/java/org/apache/jsieve/ConfigurationManager.java (original)
+++ james/jsieve/trunk/src/main/java/org/apache/jsieve/ConfigurationManager.java Thu Aug 
9 23:27:12 2007
@@ -145,19 +145,39 @@
         return "sieveConfig.xml";
     }
     /**
+     * <p>
      * Method getConfigStream answers an InputStream over the Sieve
      * configuration file. It is located by searching the classpath of the
      * current ClassLoader.
-     * 
+     * </p><p>
+     * The context classloader is searched first. If a suitably named
+     * resource is found then this is returned. Otherwise, the classloader
+     * used to load this class is searched for the resource.
+     * </p>
      * @return InputStream
      * @throws IOException
      */
     static protected InputStream getConfigStream() throws IOException
     {
-        InputStream stream = ConfigurationManager.class.getClassLoader()
-                .getResourceAsStream(getConfigName());
+        InputStream stream = null;
+        final String configName = getConfigName();
+        // Context classloader is usually right in a JEE evironment
+        final ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
+        if (contextClassLoader != null)
+        {
+            stream = contextClassLoader.getResourceAsStream(configName);
+        }
+        
+        // Sometimes context classloader will not be set conventionally
+        // So, try class classloader
         if (null == stream)
-            throw new IOException("Resource \"" + getConfigName()
+        {
+            stream = ConfigurationManager.class.getClassLoader()
+                .getResourceAsStream(configName);
+        }
+
+        if (null == stream)
+            throw new IOException("Resource \"" + configName
                     + "\" not found");
         return stream;
     }



---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Mime
View raw message