axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject svn commit: r351835 - /webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/deployment/DeploymentClassLoader.java
Date Fri, 02 Dec 2005 20:55:06 GMT
Author: dims
Date: Fri Dec  2 12:54:57 2005
New Revision: 351835

URL: http://svn.apache.org/viewcvs?rev=351835&view=rev
Log:
Patch from Alex and Ralf

This patch does not include any attempts at optimization.  It addresses the
following issues:

1) Resources cannot be loaded from jars inside of the service .aar
getResourceAsStream() has been overridden to allow this.

2) ZipInputStreams were left open by getBytes() if the target was not found.
An additional try/catch block has been added after the search loop to make
sure this happens.

3) Minor change in findLibJars() to normalize the path for startsWith() and
endsWith() checks.


What's missing from this patch is optimization code to address the extended
loading times of the DeploymentClassLoader.  We still don't know how to best
deal with this.

We forgot to extend a big "Thank You" to everyone out there working on this
project in the last post.  Thanks!

--Alex & Ralf
 aartigues@picturemarketing.com
 rsantiago@picturemarketing.com
 

Modified:
    webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/deployment/DeploymentClassLoader.java

Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/deployment/DeploymentClassLoader.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/deployment/DeploymentClassLoader.java?rev=351835&r1=351834&r2=351835&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/deployment/DeploymentClassLoader.java
(original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/deployment/DeploymentClassLoader.java
Fri Dec  2 12:54:57 2005
@@ -23,6 +23,7 @@
 import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.ByteArrayInputStream;
 import java.net.URL;
 import java.net.URLClassLoader;
 import java.util.ArrayList;
@@ -79,9 +80,9 @@
                  * id the entry name start with /lib and end with .jar
                  * then those entry name will be added to the arraylist
                  */
-                if (entryName != null && (entryName.startsWith("lib/") ||
-                        entryName.startsWith("Lib/")) &&
-                        entryName.endsWith(".jar")) {
+                if (entryName != null &&
+                        entryName.toLowerCase().startsWith("lib/") &&
+                        entryName.toLowerCase().endsWith(".jar")) {
                     lib_jars_list.add(entryName);
                 }
             }
@@ -187,6 +188,10 @@
                         return raw;
                     }
                 }
+                try {
+                    zin.close();
+                } catch (IOException ioe) {//already closed
+                }
             } catch (IOException e) {
                 throw e;
             }
@@ -194,6 +199,53 @@
         }
         throw new ClassNotFoundException(Messages.getMessage(
                 DeploymentErrorMsgs.CLASS_NOT_FOUND, filename));
+    }
+
+    /*
+     * This override locates resources similar to the way that getBytes() locates classes.
+     * We do not store the bytes from resources in memory, as
+     * the size of resources is generally unpredictable
+     *
+     * @param name
+     * @return inputstream
+     */
+    public InputStream getResourceAsStream(String name) {
+        if (name == null)
+            return null;
+
+        InputStream is = super.getResourceAsStream(name);
+        if (is == null) {
+            for (int i = 0; i < lib_jars_list.size(); i++) {
+                String libjar_name = (String) lib_jars_list.get(i);
+                try {
+                    InputStream in = super.getResourceAsStream(libjar_name);
+                    ZipInputStream zin = new ZipInputStream(in);
+                    ZipEntry entry;
+                    String entryName = "";
+                    while ((entry = zin.getNextEntry()) != null) {
+                        entryName = entry.getName();
+                        if (entryName != null && entryName.equals(name)) {
+                            byte data[] = new byte[2048];
+                            ByteArrayOutputStream out = new ByteArrayOutputStream();
+                            int count;
+                            while ((count = zin.read(data, 0, 2048)) != -1) {
+                                out.write(data, 0, count);
+                            }
+                            byte raw[] = out.toByteArray();
+                            out.close();
+                            zin.close();
+                            return new ByteArrayInputStream(raw);
+                        }
+                    }
+                    try {
+                        zin.close();
+                    } catch (IOException ioe) {//already closed
+                    }
+                } catch (IOException e) {
+                }
+            }
+        }
+        return is;
     }
 }
 



Mime
View raw message