Uploaded image for project: 'Weld'
  1. Weld
  2. WELD-589

org.jboss.weld.environment.se.discovery.URLScanner does not work with resources inside OSGI bundles

    XMLWordPrintable

Details

    • Bug
    • Resolution: Obsolete
    • Major
    • None
    • None
    • Java SE Support
    • None
    • Hide

      Make a hello world OSGI bundle, add beans.xml and weld-se.jar, and set Bundle-ClassPath to include the weld-se.jar in the bundle, then add this to you activator (workaround for the classloader bug in WeldSE):

      try {
      Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());

      Weld weld = new Weld();
      WeldContainer weldContainer = weld.initialize();

      MyWeldApp weldApp = weldContainer.instance().select(MyWeldApp.class).get();
      } finally {
      Thread.currentThread().setContextClassLoader(orgContextClassLoader);
      }

      Show
      Make a hello world OSGI bundle, add beans.xml and weld-se.jar, and set Bundle-ClassPath to include the weld-se.jar in the bundle, then add this to you activator (workaround for the classloader bug in WeldSE): try { Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader()); Weld weld = new Weld(); WeldContainer weldContainer = weld.initialize(); MyWeldApp weldApp = weldContainer.instance().select(MyWeldApp.class).get(); } finally { Thread.currentThread().setContextClassLoader(orgContextClassLoader); }

    Description

      The class org.jboss.weld.environment.se.discovery.URLScanner does no work with resources inside OSGI bundles. So if one try to start WeldSe inside an OSGI bundle and get around the classloader bug in WeldSE by tempoarily setting the ContextClassLoader you will get an NullPointerException.

      The problem is OSGI resource url related. For a OSGI bundle you will f.x. get "bundleresource://4.fwk1362875764:1/META-INF/beans.xml" from bundleClassLoader.getResources("META-INF/beans.xml" but this is not a valid filename as URLScanner assumes so one will get this exception:

      java.lang.NullPointerException
      at org.jboss.weld.environment.se.discovery.URLScanner.handleDirectory(URLScanner.java:177)
      at org.jboss.weld.environment.se.discovery.URLScanner.handleDirectory(URLScanner.java:183)
      at org.jboss.weld.environment.se.discovery.URLScanner.handleDirectory(URLScanner.java:160)
      at org.jboss.weld.environment.se.discovery.URLScanner.handle(URLScanner.java:122)
      at org.jboss.weld.environment.se.discovery.URLScanner.scanResources(URLScanner.java:107)
      at org.jboss.weld.environment.se.discovery.SEWeldDiscovery.scan(SEWeldDiscovery.java:71)
      at org.jboss.weld.environment.se.discovery.SEWeldDiscovery.<init>(SEWeldDiscovery.java:45)

      Attachments

        Activity

          People

            ajustin@redhat.com Ales Justin
            mmc41 Morten Christensen (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: