geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject svn commit: r500995 - in /geronimo/server/trunk/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/classloader: JarResourceLocation.java UrlResourceFinder.java
Date Mon, 29 Jan 2007 10:15:23 GMT
Author: dims
Date: Mon Jan 29 02:15:23 2007
New Revision: 500995

URL: http://svn.apache.org/viewvc?view=rev&rev=500995
Log:
finally got irriated enough to add this hack to get the server to start-up/work even when
JarFile fails due to long file path problem. hack kicks in only if JarFile throws a ZipException,
so there should be no performance hit

Modified:
    geronimo/server/trunk/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/classloader/JarResourceLocation.java
    geronimo/server/trunk/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/classloader/UrlResourceFinder.java

Modified: geronimo/server/trunk/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/classloader/JarResourceLocation.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/classloader/JarResourceLocation.java?view=diff&rev=500995&r1=500994&r2=500995
==============================================================================
--- geronimo/server/trunk/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/classloader/JarResourceLocation.java
(original)
+++ geronimo/server/trunk/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/classloader/JarResourceLocation.java
Mon Jan 29 02:15:23 2007
@@ -16,41 +16,131 @@
  */
 package org.apache.geronimo.kernel.classloader;
 
-import java.util.jar.Manifest;
-import java.util.jar.JarFile;
-import java.util.jar.JarEntry;
-import java.net.URL;
+import java.io.*;
 import java.net.MalformedURLException;
-import java.io.IOException;
+import java.net.URL;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
+import java.util.jar.JarInputStream;
+import java.util.jar.Manifest;
+import java.util.zip.ZipException;
 
 /**
  * @version $Rev$ $Date$
  */
-public class JarResourceLocation extends AbstractUrlResourceLocation  {
-    private final JarFile jarFile;
+public class JarResourceLocation extends AbstractUrlResourceLocation {
+    private JarFile jarFile;
+    private byte content[];
 
-    public JarResourceLocation(URL codeSource, JarFile jarFile) {
+    public JarResourceLocation(URL codeSource, File cacheFile) throws IOException {
         super(codeSource);
-        this.jarFile = jarFile;
+        try {
+            jarFile = new JarFile(cacheFile);
+        } catch (ZipException ze) {
+            // We get this exception on windows when the
+            // path to the jar file gets too long (Bug ID: 6374379)
+            InputStream is = null;
+            try {
+                is = new FileInputStream(cacheFile);
+                ByteArrayOutputStream baos = new ByteArrayOutputStream();
+                byte[] buffer = new byte[2048];
+                int bytesRead = -1;
+                while ((bytesRead = is.read(buffer)) != -1) {
+                    baos.write(buffer, 0, bytesRead);
+                }
+                this.content = baos.toByteArray();
+            } finally {
+                if (is != null) {
+                    is.close();
+                }
+            }
+        }
     }
 
     public ResourceHandle getResourceHandle(String resourceName) {
-        JarEntry jarEntry = jarFile.getJarEntry(resourceName);
-        if (jarEntry != null) {
+        if (jarFile != null) {
+            JarEntry jarEntry = jarFile.getJarEntry(resourceName);
+            if (jarEntry != null) {
+                try {
+                    URL url = new URL(getCodeSource(), resourceName);
+                    return new JarResourceHandle(jarFile, jarEntry, getCodeSource());
+                } catch (MalformedURLException e) {
+                }
+            }
+        } else {
             try {
-                URL url = new URL(getCodeSource(), resourceName);
-                return new JarResourceHandle(jarFile, jarEntry, getCodeSource());
-            } catch (MalformedURLException e) {
+                final JarInputStream is = new JarInputStream(new ByteArrayInputStream(this.content));
+                JarEntry jarEntry = null;
+                while ((jarEntry = is.getNextJarEntry()) != null) {
+                    if (jarEntry.getName().equals(resourceName)) {
+                        try {
+                            URL url = new URL(getCodeSource(), resourceName);
+                            final JarEntry jarEntry2 = jarEntry;
+                            return new JarEntryResourceHandle(jarEntry2, is);
+                        } catch (MalformedURLException e) {
+                        }
+                    }
+                }
+            } catch (IOException e) {
             }
         }
         return null;
     }
 
     public Manifest getManifest() throws IOException {
-        return jarFile.getManifest();
+        if (jarFile != null) {
+            return jarFile.getManifest();
+        } else {
+            try {
+                JarInputStream is = new JarInputStream(new ByteArrayInputStream(this.content));
+                return is.getManifest();
+            } catch (IOException e) {
+            }
+        }
+        return null;
     }
 
     public void close() {
-        IoUtil.close(jarFile);
+        if (jarFile != null) {
+            IoUtil.close(jarFile);
+        }
+    }
+
+    private class JarEntryResourceHandle extends AbstractResourceHandle {
+        private final JarEntry jarEntry2;
+        private final JarInputStream is;
+
+        public JarEntryResourceHandle(JarEntry jarEntry2, JarInputStream is) {
+            this.jarEntry2 = jarEntry2;
+            this.is = is;
+        }
+
+        public String getName() {
+            return jarEntry2.getName();
+        }
+
+        public URL getUrl() {
+            try {
+                return new URL("jar", "", -1, getCodeSource() + "!/" + jarEntry2.getName());
+            } catch (MalformedURLException e) {
+                throw new RuntimeException(e);
+            }
+        }
+
+        public boolean isDirectory() {
+            return jarEntry2.isDirectory();
+        }
+
+        public URL getCodeSourceUrl() {
+            return getCodeSource();
+        }
+
+        public InputStream getInputStream() throws IOException {
+            return is;
+        }
+
+        public int getContentLength() {
+            return (int) jarEntry2.getSize();
+        }
     }
 }

Modified: geronimo/server/trunk/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/classloader/UrlResourceFinder.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/classloader/UrlResourceFinder.java?view=diff&rev=500995&r1=500994&r2=500995
==============================================================================
--- geronimo/server/trunk/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/classloader/UrlResourceFinder.java
(original)
+++ geronimo/server/trunk/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/classloader/UrlResourceFinder.java
Mon Jan 29 02:15:23 2007
@@ -16,12 +16,9 @@
  */
 package org.apache.geronimo.kernel.classloader;
 
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
 import java.io.File;
-import java.io.IOException;
 import java.io.FileNotFoundException;
+import java.io.IOException;
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.util.ArrayList;
@@ -35,16 +32,13 @@
 import java.util.List;
 import java.util.Map;
 import java.util.StringTokenizer;
-import java.util.zip.ZipException;
 import java.util.jar.Attributes;
 import java.util.jar.Manifest;
-import java.util.jar.JarFile;
 
 /**
  * @version $Rev$ $Date$
  */
 public class UrlResourceFinder implements ResourceFinder {
-    private static final Log log = LogFactory.getLog(UrlResourceFinder.class);
     private final Object lock = new Object();
 
     private final LinkedHashSet urls = new LinkedHashSet();
@@ -258,16 +252,7 @@
             // do not user the DirectoryResourceLocation for non file based urls
             resourceLocation = new DirectoryResourceLocation(cacheFile);
         } else {
-            JarFile jarFile;
-            try {
-                jarFile = new JarFile(cacheFile);
-            } catch (ZipException ze){
-                // We get this exception on windows when the
-                // path to the jar file gets too long (Bug ID: 6374379)
-                log.info("File is unusable: " + cacheFile.getAbsolutePath());
-                throw ze;
-            }
-            resourceLocation = new JarResourceLocation(codeSource, jarFile);
+            resourceLocation = new JarResourceLocation(codeSource, cacheFile);
         }
         return resourceLocation;
     }



Mime
View raw message