Felix
  1. Felix
  2. FELIX-2780

Extension bundle implementation relies on urlhandlers service to start extension bundles

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: framework-3.0.7
    • Fix Version/s: framework-4.2.0
    • Component/s: Framework
    • Labels:
      None
    • Environment:

      Description

      I am trying to start the felix security framework extension bundle with the urlhandler service disabled in the Felix framework.

      COMMAND:
      ======
      /usr/local/jamvm/bin/jamvm -Xmx256M -Dfelix.service.urlhandlers=false -Dorg.osgi.framework.security="osgi" -Dpolicy.provider=gnu.java.security.PolicyFile -Djava.security.policy=file:///home/samba/wurk/downloads/osgi/felix-framework-3.0.7/conf/java.policy -jar bin/felix.jar

      Policy file:
      ========
      grant

      { permission java.security.AllPermission; }

      grant codeBase "http://felix.extensions:9/" { permission java.security.AllPermission; }

      ;

      I get the following error and the security framework does not start
      WARNING: Unable to start Felix Extension Activator (java.nio.channels.UnresolvedAddressException)

      Stack trace where the exception occurs

      at java.lang.Thread.dumpStack(Thread.java:522)
      at java.nio.channels.UnresolvedAddressException.<init>(UnresolvedAddressException.java:55)
      at gnu.java.nio.SocketChannelImpl.connect(SocketChannelImpl.java:160)
      at gnu.java.net.PlainSocketImpl.connect(PlainSocketImpl.java:281)
      at java.net.Socket.connect(Socket.java:454)
      at java.net.Socket.connect(Socket.java:414)
      at gnu.java.net.protocol.http.HTTPConnection.getSocket(HTTPConnection.java:721)
      at gnu.java.net.protocol.http.HTTPConnection.getOutputStream(HTTPConnection.java:802)
      at gnu.java.net.protocol.http.Request.dispatch(Request.java:292)
      at gnu.java.net.protocol.http.HTTPURLConnection.connect(HTTPURLConnection.java:219)
      at gnu.java.net.protocol.http.HTTPURLConnection.getHeaderField(HTTPURLConnection.java:582)
      at java.net.URLConnection.getHeaderFieldInt(URLConnection.java:426)
      at java.net.URLConnection.getContentLength(URLConnection.java:302)
      at gnu.java.net.loader.RemoteURLLoader.getResource(RemoteURLLoader.java:79)
      at java.net.URLClassLoader.findClass(URLClassLoader.java:528)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:341)
      at java.lang.ClassLoader$1.loadClass(ClassLoader.java:1112)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:293)
      at org.apache.felix.framework.ExtensionManager.startExtensionBundle(ExtensionManager.java:381)
      at org.apache.felix.framework.Felix.installBundle(Felix.java:2610)
      at org.apache.felix.framework.Felix.installBundle(Felix.java:2429)
      at org.apache.felix.framework.BundleContextImpl.installBundle(BundleContextImpl.java:121)
      at org.apache.felix.framework.BundleContextImpl.installBundle(BundleContextImpl.java:107)
      at org.apache.felix.main.AutoProcessor.processAutoDeploy(AutoProcessor.java:173)
      at org.apache.felix.main.AutoProcessor.process(AutoProcessor.java:78)
      at org.apache.felix.main.Main.main(Main.java:291)

      at java.lang.reflect.VMMethod.invoke(Native Method)
      at java.lang.reflect.Method.invoke(Method.java:327)
      at jamvm.java.lang.JarLauncher.main(JarLauncher.java:50)

      1. patch.diff
        0.6 kB
        Sylvain RIBEYRON

        Activity

        Hide
        Jan van Oosterom added a comment -

        This just became much more importent
        Seams felix is now no longer usable in java 6 update 24 / webstart
        http://forums.oracle.com/forums/thread.jspa?threadID=2179127

        Show
        Jan van Oosterom added a comment - This just became much more importent Seams felix is now no longer usable in java 6 update 24 / webstart http://forums.oracle.com/forums/thread.jspa?threadID=2179127
        Hide
        Karl Pauls added a comment -

        Interesting. I need to look into what is going on there. I doubt that it is related. Looks more like a new issue.

        Show
        Karl Pauls added a comment - Interesting. I need to look into what is going on there. I doubt that it is related. Looks more like a new issue.
        Hide
        Psique added a comment -

        Hi Guys, any news on this?

        I have not being able to work around this problem, this exception is what I
        got due to update 24.

        This happens in static code inside javax.imageio.ImageIO when its trying to
        load the image handlers.

        Caused by: java.lang.SecurityException: Permission denied:
        http://felix.extensions:9/META-INF/services/javax.imageio.spi.ImageInputStreamSpi
        at
        com.sun.deploy.security.DeployURLClassPath$UrlLoader.findResource(Unknown
        Source)
        at com.sun.deploy.security.DeployURLClassPath$1.next(Unknown Source)
        at com.sun.deploy.security.DeployURLClassPath$1.hasMoreElements(Unknown
        Source)
        at java.net.URLClassLoader$3$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader$3.next(Unknown Source)
        at java.net.URLClassLoader$3.hasMoreElements(Unknown Source)
        at sun.misc.CompoundEnumeration.next(Unknown Source)
        at sun.misc.CompoundEnumeration.hasMoreElements(Unknown Source)
        at sun.misc.CompoundEnumeration.next(Unknown Source)
        at sun.misc.CompoundEnumeration.hasMoreElements(Unknown Source)
        at sun.misc.Service$LazyIterator.hasNext(Unknown Source)
        at
        javax.imageio.spi.IIORegistry.registerApplicationClasspathSpis(Unknown
        Source)
        at javax.imageio.spi.IIORegistry.<init>(Unknown Source)
        at javax.imageio.spi.IIORegistry.getDefaultInstance(Unknown Source)
        at javax.imageio.ImageIO.<clinit>(Unknown Source)

        Let me know if I can help in any way.

        Thank you for your efforts.

        Show
        Psique added a comment - Hi Guys, any news on this? I have not being able to work around this problem, this exception is what I got due to update 24. This happens in static code inside javax.imageio.ImageIO when its trying to load the image handlers. Caused by: java.lang.SecurityException: Permission denied: http://felix.extensions:9/META-INF/services/javax.imageio.spi.ImageInputStreamSpi at com.sun.deploy.security.DeployURLClassPath$UrlLoader.findResource(Unknown Source) at com.sun.deploy.security.DeployURLClassPath$1.next(Unknown Source) at com.sun.deploy.security.DeployURLClassPath$1.hasMoreElements(Unknown Source) at java.net.URLClassLoader$3$1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader$3.next(Unknown Source) at java.net.URLClassLoader$3.hasMoreElements(Unknown Source) at sun.misc.CompoundEnumeration.next(Unknown Source) at sun.misc.CompoundEnumeration.hasMoreElements(Unknown Source) at sun.misc.CompoundEnumeration.next(Unknown Source) at sun.misc.CompoundEnumeration.hasMoreElements(Unknown Source) at sun.misc.Service$LazyIterator.hasNext(Unknown Source) at javax.imageio.spi.IIORegistry.registerApplicationClasspathSpis(Unknown Source) at javax.imageio.spi.IIORegistry.<init>(Unknown Source) at javax.imageio.spi.IIORegistry.getDefaultInstance(Unknown Source) at javax.imageio.ImageIO.<clinit>(Unknown Source) Let me know if I can help in any way. Thank you for your efforts.
        Hide
        Jan van Oosterom added a comment - - edited

        this snippet of code seem so be the source of the problem
        why is this an illegal URL?

        class ExtensionManager extends URLStreamHandler implements Content
        {
        // The private instance that is added to Felix.class.getClassLoader() -
        // will be null if extension bundles are not supported (i.e., we are not
        // loaded by an instance of URLClassLoader)
        static final ExtensionManager m_extensionManager;

        static
        {
        // pre-init the url sub-system as otherwise we don't work on gnu/classpath
        ExtensionManager extensionManager = new ExtensionManager();
        try

        { (new URL("http://felix.extensions:9/")).openConnection(); }

        catch (Throwable t)

        <edit, fix typo>

        Show
        Jan van Oosterom added a comment - - edited this snippet of code seem so be the source of the problem why is this an illegal URL? class ExtensionManager extends URLStreamHandler implements Content { // The private instance that is added to Felix.class.getClassLoader() - // will be null if extension bundles are not supported (i.e., we are not // loaded by an instance of URLClassLoader) static final ExtensionManager m_extensionManager; static { // pre-init the url sub-system as otherwise we don't work on gnu/classpath ExtensionManager extensionManager = new ExtensionManager(); try { (new URL("http://felix.extensions:9/")).openConnection(); } catch (Throwable t) <edit, fix typo>
        Hide
        Ingo Bauersachs added a comment -

        I use Felix in a WebStart application and got the same error as Psique. The change introduced by Java 6u24 is that com.sun.deploy.security.DeployURLClassPath$UrlLoader.findResource calls URLUtil.checkTargetUrl with http://felix.extensions:9 as a parameter.

        As a "workaround" I managed to get the application running by patching Felix and replacing the http://felix.extensions:9 URL by file:///felix.extensions/9 (org.apache.felix.framework.ExtensionManager#static initializer)
        I have no idea what other consequences this might have (especially on issue FELIX-844), but at least I got my application running.

        Regards,
        Ingo

        Show
        Ingo Bauersachs added a comment - I use Felix in a WebStart application and got the same error as Psique. The change introduced by Java 6u24 is that com.sun.deploy.security.DeployURLClassPath$UrlLoader.findResource calls URLUtil.checkTargetUrl with http://felix.extensions:9 as a parameter. As a "workaround" I managed to get the application running by patching Felix and replacing the http://felix.extensions:9 URL by file:///felix.extensions/9 (org.apache.felix.framework.ExtensionManager#static initializer) I have no idea what other consequences this might have (especially on issue FELIX-844 ), but at least I got my application running. Regards, Ingo
        Hide
        Benoit F. added a comment -

        I confirm that replacing the "http" url by a local "file" one seems to work. I modified org.apache.felix.framework.ExtensionManager.java, line 94 (which seems to be used only in URLHandlersStreamHandler.java, line 27 ?).

        I also use Felix as a jar deployed by webstart and using it in "embedded" mode. Please note that I only use "Felix framework".

        Please, has anyone an idea about when Felix could fix it ? (3.0.10..?)

        Show
        Benoit F. added a comment - I confirm that replacing the "http" url by a local "file" one seems to work. I modified org.apache.felix.framework.ExtensionManager.java, line 94 (which seems to be used only in URLHandlersStreamHandler.java, line 27 ?). I also use Felix as a jar deployed by webstart and using it in "embedded" mode. Please note that I only use "Felix framework". Please, has anyone an idea about when Felix could fix it ? (3.0.10..?)
        Hide
        Psique added a comment -

        Thank you Ingo,

        I changed the http for file in my Felix jar and my 25 bundles are now working Maybe there are some consequences but I don't think they are in this context.

        http://www.psiqueware.com/girasolEditor/launch.jnlp

        Show
        Psique added a comment - Thank you Ingo, I changed the http for file in my Felix jar and my 25 bundles are now working Maybe there are some consequences but I don't think they are in this context. http://www.psiqueware.com/girasolEditor/launch.jnlp
        Hide
        Sylvain RIBEYRON added a comment -

        Hi all.

        I've had the same issue running Felix on Web Start.

        I've resolved the issue by patching the ExtensionManager.java.

        At line 510, replace the line:

        throw new IOException("Resource not provided by any extension!");

        By the following code:

        // JDK6u24 issue
        return new URLConnection(url) {
        @Override
        public void connect() throws IOException

        { throw new IOException("Resource not provided by any extension!"); }

        };
        // End JDK6u24 issue

        The issue occurs when looking up classes, because IOException is thrown on URL.openConnection when classes (or resources) are not found. The IOException should not be thrown on the openConnection method, but later on the connect method on URLConnection (this streamHandler should work as any other http handler: when a file does not exist, the http server sends a 404 response. This response can only occur when URLconnection is established, not when URLConnection is initialized).

        This patch work fine for me.

        Show
        Sylvain RIBEYRON added a comment - Hi all. I've had the same issue running Felix on Web Start. I've resolved the issue by patching the ExtensionManager.java. At line 510, replace the line: throw new IOException("Resource not provided by any extension!"); By the following code: // JDK6u24 issue return new URLConnection(url) { @Override public void connect() throws IOException { throw new IOException("Resource not provided by any extension!"); } }; // End JDK6u24 issue The issue occurs when looking up classes, because IOException is thrown on URL.openConnection when classes (or resources) are not found. The IOException should not be thrown on the openConnection method, but later on the connect method on URLConnection (this streamHandler should work as any other http handler: when a file does not exist, the http server sends a 404 response. This response can only occur when URLconnection is established, not when URLConnection is initialized). This patch work fine for me.
        Hide
        Sylvain RIBEYRON added a comment - - edited

        Here is the patch that work for me (see attached file patch.diff). It throws the IOException only on the URLConnection.connect method, not on the URL.openConnection method.

        Show
        Sylvain RIBEYRON added a comment - - edited Here is the patch that work for me (see attached file patch.diff). It throws the IOException only on the URLConnection.connect method, not on the URL.openConnection method.
        Hide
        Karl Pauls added a comment -

        Grrr, another one. I don't think i see why the exception should not be thrown on the openConnection method to being with. Really, its still a bug in the jdk imo. This is somewhat annoying as i remember that there where problems with throwing it to late in the game as other implementations didn't expect that but oh well, that will be there problem as the jdk wins that one

        Great find! We'll include the fix - thanks a lot.

        Show
        Karl Pauls added a comment - Grrr, another one. I don't think i see why the exception should not be thrown on the openConnection method to being with. Really, its still a bug in the jdk imo. This is somewhat annoying as i remember that there where problems with throwing it to late in the game as other implementations didn't expect that but oh well, that will be there problem as the jdk wins that one Great find! We'll include the fix - thanks a lot.
        Hide
        Karl Pauls added a comment -

        i added your changes but against a new issue: FELIX-2877. Thanks again.

        Show
        Karl Pauls added a comment - i added your changes but against a new issue: FELIX-2877 . Thanks again.
        Hide
        Sylvain RIBEYRON added a comment -

        Thank you too !

        Show
        Sylvain RIBEYRON added a comment - Thank you too !
        Hide
        Karl Pauls added a comment -

        I think this one has been fixed.

        Show
        Karl Pauls added a comment - I think this one has been fixed.

          People

          • Assignee:
            Karl Pauls
            Reporter:
            Samba
          • Votes:
            1 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development