You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by io...@apache.org on 2012/09/12 09:04:04 UTC

svn commit: r1383807 - in /karaf/trunk/features/core/src/main: java/org/apache/karaf/features/internal/FeaturesServiceImpl.java resources/OSGI-INF/blueprint/blueprint.xml

Author: iocanel
Date: Wed Sep 12 07:04:04 2012
New Revision: 1383807

URL: http://svn.apache.org/viewvc?rev=1383807&view=rev
Log:
[KARAF-1245] Feature service will now wait for url handlers only when requested.

Modified:
    karaf/trunk/features/core/src/main/java/org/apache/karaf/features/internal/FeaturesServiceImpl.java
    karaf/trunk/features/core/src/main/resources/OSGI-INF/blueprint/blueprint.xml

Modified: karaf/trunk/features/core/src/main/java/org/apache/karaf/features/internal/FeaturesServiceImpl.java
URL: http://svn.apache.org/viewvc/karaf/trunk/features/core/src/main/java/org/apache/karaf/features/internal/FeaturesServiceImpl.java?rev=1383807&r1=1383806&r2=1383807&view=diff
==============================================================================
--- karaf/trunk/features/core/src/main/java/org/apache/karaf/features/internal/FeaturesServiceImpl.java (original)
+++ karaf/trunk/features/core/src/main/java/org/apache/karaf/features/internal/FeaturesServiceImpl.java Wed Sep 12 07:04:04 2012
@@ -74,6 +74,7 @@ import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.BundleException;
 import org.osgi.framework.Constants;
+import org.osgi.framework.Filter;
 import org.osgi.framework.FrameworkEvent;
 import org.osgi.framework.FrameworkListener;
 import org.osgi.framework.FrameworkUtil;
@@ -83,6 +84,7 @@ import org.osgi.framework.startlevel.Bun
 import org.osgi.framework.wiring.FrameworkWiring;
 import org.osgi.service.cm.Configuration;
 import org.osgi.service.cm.ConfigurationAdmin;
+import org.osgi.service.url.URLStreamHandlerService;
 import org.osgi.util.tracker.ServiceTracker;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -844,7 +846,10 @@ public class FeaturesServiceImpl impleme
         String bundleLocation = bundleInfo.getLocation();
         LOGGER.debug("Checking " + bundleLocation);
         try {
-            is = new BufferedInputStream(new URL(bundleLocation).openStream());
+            String protocol = bundleLocation.substring(0, bundleLocation.indexOf(":"));
+            waitForUrlHandler(protocol);
+            URL bundleUrl = new URL(bundleLocation);
+            is = new BufferedInputStream(bundleUrl.openStream());
         } catch (RuntimeException e) {
             LOGGER.error(e.getMessage());
             throw e;
@@ -1473,4 +1478,25 @@ public class FeaturesServiceImpl impleme
         }
         return buffer.toString();
     }
+
+    /**
+     * Will wait for the {@link URLStreamHandlerService} service for the specified protocol to be registered.
+     * @param protocol
+     */
+    private void waitForUrlHandler(String protocol) {
+        try {
+            Filter filter = bundleContext.createFilter("(&(" + Constants.OBJECTCLASS + "=" + URLStreamHandlerService.class.getName() + ")(url.handler.protocol=" + protocol + "))");
+            ServiceTracker urlHandlerTracker = new ServiceTracker(bundleContext, filter, null);
+            try {
+                urlHandlerTracker.open();
+                urlHandlerTracker.waitForService(30000);
+            } catch (InterruptedException e) {
+                LOGGER.debug("Interrupted while waiting for URL handler for protocol {}.", protocol);
+            } finally {
+                urlHandlerTracker.close();
+            }
+        } catch (InvalidSyntaxException ex) {
+            LOGGER.error("Error creating filter for service tracker.", ex);
+        }
+    }
 }

Modified: karaf/trunk/features/core/src/main/resources/OSGI-INF/blueprint/blueprint.xml
URL: http://svn.apache.org/viewvc/karaf/trunk/features/core/src/main/resources/OSGI-INF/blueprint/blueprint.xml?rev=1383807&r1=1383806&r2=1383807&view=diff
==============================================================================
--- karaf/trunk/features/core/src/main/resources/OSGI-INF/blueprint/blueprint.xml (original)
+++ karaf/trunk/features/core/src/main/resources/OSGI-INF/blueprint/blueprint.xml Wed Sep 12 07:04:04 2012
@@ -48,17 +48,15 @@
     <reference id="configAdmin" interface="org.osgi.service.cm.ConfigurationAdmin" />
 
     <reference id="mvnUrlHandler" interface="org.osgi.service.url.URLStreamHandlerService" filter="(url.handler.protocol=mvn)" />
-    <reference id="blueprintUrlHandler" interface="org.osgi.service.url.URLStreamHandlerService" filter="(url.handler.protocol=blueprint)" />
-    <reference id="springUrlHandler" interface="org.osgi.service.url.URLStreamHandlerService" filter="(url.handler.protocol=spring)" />
 
     <service ref="featuresService" interface="org.apache.karaf.features.FeaturesService" />
 
-    <reference id="regionsPersistence" availability="optional" interface="org.apache.karaf.region.persist.RegionsPersistence" >
+    <reference id="regionsPersistence" availability="optional" interface="org.apache.karaf.region.persist.RegionsPersistence">
         <reference-listener ref="featuresService"
                             bind-method="registerRegionsPersistence"
                             unbind-method="unregisterRegionsPersistence" />
     </reference>
-    
+
     <bean id="featuresServiceMBean" class="org.apache.karaf.features.management.internal.FeaturesService">
         <property name="bundleContext" ref="blueprintBundleContext" />
         <property name="featuresService" ref="featuresService" />