camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r680794 - /activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ResolverUtil.java
Date Tue, 29 Jul 2008 18:11:55 GMT
Author: davsclaus
Date: Tue Jul 29 11:11:55 2008
New Revision: 680794

URL: http://svn.apache.org/viewvc?rev=680794&view=rev
Log:
CAMEL-522: Loading jars from http for java webstart support

Modified:
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ResolverUtil.java

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ResolverUtil.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ResolverUtil.java?rev=680794&r1=680793&r2=680794&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ResolverUtil.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ResolverUtil.java
Tue Jul 29 11:11:55 2008
@@ -19,9 +19,11 @@
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.IOException;
+import java.io.InputStream;
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Method;
 import java.net.URL;
+import java.net.URLConnection;
 import java.net.URLDecoder;
 import java.util.Arrays;
 import java.util.Enumeration;
@@ -356,10 +358,23 @@
                     }
                     loadImplementationsInDirectory(test, packageName, file);
                 } else {
+                    InputStream stream;
+                    if (urlPath.startsWith("http:")) {
+                        // load resources using http such as java webstart
+                        LOG.debug("The current jar is accessed via http");
+                        URL urlStream = new URL(urlPath);
+                        URLConnection con = urlStream.openConnection();
+                        // disable cache mainly to avoid jar file locking on Windows
+                        con.setUseCaches(false);
+                        stream = con.getInputStream();
+                    } else {
+                        stream = new FileInputStream(file);
+                    }
+
                     if (LOG.isDebugEnabled()) {
                         LOG.debug("Loading from jar: " + file);
                     }
-                    loadImplementationsInJar(test, packageName, file);
+                    loadImplementationsInJar(test, packageName, stream, urlPath);
                 }
             } catch (IOException ioe) {
                 LOG.warn("Could not read entries in url: " + url, ioe);
@@ -469,11 +484,13 @@
      * @param parent  the parent package under which classes must be in order to
      *                be considered
      * @param jarfile the jar file to be examined for classes
+     * @param stream  the inputstream of the jar file to be examined for classes
+     * @param urlPath the url of the jar file to be examined for classes
      */
-    private void loadImplementationsInJar(Test test, String parent, File jarfile) {
+    private void loadImplementationsInJar(Test test, String parent, InputStream stream, String
urlPath) {
         JarInputStream jarStream = null;
         try {
-            jarStream = new JarInputStream(new FileInputStream(jarfile));
+            jarStream = new JarInputStream(stream);
 
             JarEntry entry;
             while ((entry = jarStream.getNextJarEntry()) != null) {
@@ -486,10 +503,10 @@
                 }
             }
         } catch (IOException ioe) {
-            LOG.error("Could not search jar file '" + jarfile + "' for classes matching criteria:
" + test
+            LOG.error("Could not search jar file '" + urlPath + "' for classes matching criteria:
" + test
                 + " due to an IOException: " + ioe.getMessage(), ioe);
         } finally {
-            ObjectHelper.close(jarStream, jarfile.getPath(), LOG);
+            ObjectHelper.close(jarStream, urlPath, LOG);
         }
     }
 



Mime
View raw message