axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject svn commit: r530881 - in /webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2: context/ deployment/ util/
Date Fri, 20 Apr 2007 18:35:00 GMT
Author: dims
Date: Fri Apr 20 11:34:59 2007
New Revision: 530881

URL: http://svn.apache.org/viewvc?view=rev&rev=530881
Log:
Fix for AXIS2-2484 - IllegalArgumentException: Null InputStream is not a valid argument when
loading axis client from URLClassLoader

Modified:
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/context/ConfigurationContextFactory.java
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/FileSystemConfigurator.java
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/URLBasedAxisConfigurator.java
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/WarBasedAxisConfigurator.java
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/Loader.java

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/context/ConfigurationContextFactory.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/context/ConfigurationContextFactory.java?view=diff&rev=530881&r1=530880&r2=530881
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/context/ConfigurationContextFactory.java
(original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/context/ConfigurationContextFactory.java
Fri Apr 20 11:34:59 2007
@@ -31,6 +31,7 @@
 import org.apache.axis2.modules.Module;
 import org.apache.axis2.transport.TransportSender;
 import org.apache.axis2.util.SessionUtils;
+import org.apache.axis2.util.Loader;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
@@ -262,8 +263,7 @@
      * @return Returns ConfigurationContext.
      */
     public static ConfigurationContext createDefaultConfigurationContext() throws Exception
{
-        ClassLoader cl = Thread.currentThread().getContextClassLoader();
-        InputStream in = cl.getResourceAsStream(DeploymentConstants.AXIS2_CONFIGURATION_RESOURCE);
+        InputStream in = Loader.getResourceAsStream(DeploymentConstants.AXIS2_CONFIGURATION_RESOURCE);
 
         AxisConfiguration axisConfig = new AxisConfiguration();
         AxisConfigBuilder builder = new AxisConfigBuilder(in, axisConfig, null);

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/FileSystemConfigurator.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/FileSystemConfigurator.java?view=diff&rev=530881&r1=530880&r2=530881
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/FileSystemConfigurator.java
(original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/FileSystemConfigurator.java
Fri Apr 20 11:34:59 2007
@@ -2,6 +2,7 @@
 
 import org.apache.axis2.AxisFault;
 import org.apache.axis2.Constants;
+import org.apache.axis2.util.Loader;
 import org.apache.axis2.description.Parameter;
 import org.apache.axis2.engine.AxisConfiguration;
 import org.apache.axis2.engine.AxisConfigurator;
@@ -103,9 +104,8 @@
             if (axis2xml != null && !"".equals(axis2xml)) {
                 axis2xmlSream = new FileInputStream(axis2xml);
             } else {
-                ClassLoader cl = Thread.currentThread().getContextClassLoader();
                 axis2xmlSream =
-                        cl.getResourceAsStream(DeploymentConstants.AXIS2_CONFIGURATION_RESOURCE);
+                        Loader.getResourceAsStream(DeploymentConstants.AXIS2_CONFIGURATION_RESOURCE);
             }
             axisConfig = populateAxisConfiguration(axis2xmlSream);
         } catch (FileNotFoundException e) {

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/URLBasedAxisConfigurator.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/URLBasedAxisConfigurator.java?view=diff&rev=530881&r1=530880&r2=530881
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/URLBasedAxisConfigurator.java
(original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/URLBasedAxisConfigurator.java
Fri Apr 20 11:34:59 2007
@@ -1,6 +1,7 @@
 package org.apache.axis2.deployment;
 
 import org.apache.axis2.AxisFault;
+import org.apache.axis2.util.Loader;
 import org.apache.axis2.description.Parameter;
 import org.apache.axis2.engine.AxisConfiguration;
 import org.apache.axis2.engine.AxisConfigurator;
@@ -44,9 +45,8 @@
         InputStream axis2xmlStream;
         try {
             if (axis2xml == null) {
-                ClassLoader cl = Thread.currentThread().getContextClassLoader();
                 axis2xmlStream =
-                        cl.getResourceAsStream(DeploymentConstants.AXIS2_CONFIGURATION_RESOURCE);
+                        Loader.getResourceAsStream(DeploymentConstants.AXIS2_CONFIGURATION_RESOURCE);
             } else {
                 axis2xmlStream = axis2xml.openStream();
             }

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/WarBasedAxisConfigurator.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/WarBasedAxisConfigurator.java?view=diff&rev=530881&r1=530880&r2=530881
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/WarBasedAxisConfigurator.java
(original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/WarBasedAxisConfigurator.java
Fri Apr 20 11:34:59 2007
@@ -2,6 +2,7 @@
 
 import org.apache.axis2.AxisFault;
 import org.apache.axis2.Constants;
+import org.apache.axis2.util.Loader;
 import org.apache.axis2.context.ConfigurationContext;
 import org.apache.axis2.deployment.repository.util.ArchiveReader;
 import org.apache.axis2.description.AxisServiceGroup;
@@ -129,9 +130,8 @@
             } // catch
 
             if (axis2Stream == null) {
-                ClassLoader cl = Thread.currentThread().getContextClassLoader();
                 axis2Stream =
-                        cl.getResourceAsStream(DeploymentConstants.AXIS2_CONFIGURATION_RESOURCE);
+                        Loader.getResourceAsStream(DeploymentConstants.AXIS2_CONFIGURATION_RESOURCE);
             }
             axisConfig = populateAxisConfiguration(axis2Stream);
 

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/Loader.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/Loader.java?view=diff&rev=530881&r1=530880&r2=530881
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/Loader.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/Loader.java Fri
Apr 20 11:34:59 2007
@@ -24,6 +24,7 @@
 import java.lang.reflect.InvocationTargetException;
 import java.net.URL;
 import java.security.PrivilegedAction;
+import java.io.InputStream;
 
 /**
  * Loads resources (or images) from various sources.
@@ -100,6 +101,90 @@
             log.warn("Caught Exception while in Loader.getResource. This may be innocuous.",
t);
         }
         return getResource(resource);
+    }
+
+    /**
+     * Searches for <code>resource</code> in different
+     * places. The search order is as follows:
+     * <ol>
+     * <p><li>Search for <code>resource</code> using the thread context
+     * class loader under Java2. If that fails, search for
+     * <code>resource</code> using the class loader that loaded this
+     * class (<code>Loader</code>).
+     * <p><li>Try one last time with
+     * <code>ClassLoader.getSystemResourceAsStream(resource)</code>, that is
is
+     * using the system class loader in JDK 1.2 and virtual machine's
+     * built-in class loader in JDK 1.1.
+     * </ol>
+     * <p/>
+     *
+     * @param resource
+     * @return Returns URL
+     */
+    static public InputStream getResourceAsStream(String resource) {
+        ClassLoader classLoader = null;
+        try {
+            // Let's try the Thread Context Class Loader
+            classLoader = getTCL();
+            if (classLoader != null) {
+                log.debug("Trying to find [" + resource + "] using " + classLoader +
+                        " class loader.");
+                InputStream is = classLoader.getResourceAsStream(resource);
+                if (is != null) {
+                    return is;
+                }
+            }
+        } catch (Throwable t) {
+            log.warn("Caught Exception while in Loader.getResourceAsStream. This may be innocuous.",
t);
+        }
+
+        try {
+            // We could not find resource. Ler us now try with the
+            // classloader that loaded this class.
+            classLoader = Loader.class.getClassLoader();
+            if (classLoader != null) {
+                log.debug("Trying to find [" + resource + "] using " + classLoader +
+                        " class loader.");
+                InputStream is = classLoader.getResourceAsStream(resource);
+                if (is != null) {
+                    return is;
+                }
+            }
+        } catch (Throwable t) {
+            log.warn("Caught Exception while in Loader.getResourceAsStream. This may be innocuous.",
t);
+        }
+
+        // Last ditch attempt: get the resource from the class path. It
+        // may be the case that clazz was loaded by the Extentsion class
+        // loader which the parent of the system class loader. Hence the
+        // code below.
+        log.debug("Trying to find [" + resource + "] using ClassLoader.getSystemResourceAsStream().");
+        return ClassLoader.getSystemResourceAsStream(resource);
+    }
+
+
+    /**
+     * Gets the resource with the specified class loader.
+     *
+     * @param loader
+     * @param resource
+     * @return Returns URL.
+     * @throws ClassNotFoundException
+     */
+    static public InputStream getResourceAsStream(ClassLoader loader, String resource)
+            throws ClassNotFoundException {
+        try {
+            if (loader != null) {
+                log.debug("Trying to find [" + resource + "] using " + loader + " class loader.");
+                InputStream is = loader.getResourceAsStream(resource);
+                if (is != null) {
+                    return is;
+                }
+            }
+        } catch (Throwable t) {
+            log.warn("Caught Exception while in Loader.getResource. This may be innocuous.",
t);
+        }
+        return getResourceAsStream(resource);
     }
 
     /**



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


Mime
View raw message