Uploaded image for project: 'Wicket'
  1. Wicket
  2. WICKET-1371

wicket.properties cannot be found in OSGi

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.3.1
    • 1.4-M1
    • wicket
    • None
    • Windows XP, Java 5, Wicket 1.3.1, Equinox OSGi 3.3.1

    Description

      The wicket.properties file is not being loaded by the Application class due to exclusive use of the thread context classloader in Wicket 1.3.1 when used in an OSGi environment.

      From looking at Wicket's Application code, it appears that multiple wicket.properties files can exist, and it will load them all. So, the wicket.properties in wicket.jar should always be loaded as well as any other wicket.properties that are application specific. This will work in a traditional WAR file.

      However, in OSGi, each bundle has its own classloader. So, if Wicket is in its own bundle and my web application is in its own bundle, the current implementation of Application will not work. Using only the thread context classloader will not accomodate loading multiple wicket.properties. Multiple classloaders must be checked.

      Here's a reference to an mail list thread:
      http://www.nabble.com/NPE-in-PropertyResolver.getGetAndSetter%28%29-td11194510.html#a15647641

      I've put together and tested a modified Application.java which works in OSGi. Would something like this be acceptable?

      public final void initializeComponents()
      {
      // Load any wicket properties files we can find
      try

      { Set loadedFiles = new HashSet(); // Load properties files used by all libraries // Try the classloader for the wicket jar/bundle Enumeration resources = Application.class.getClassLoader() .getResources("wicket.properties"); loadResources(resources, loadedFiles); // Try the classloader for the user's application jar/bundle resources = getClass().getClassLoader() .getResources("wicket.properties"); loadResources(resources, loadedFiles); // Try the context class loader resources = Thread.currentThread() .getContextClassLoader() .getResources("wicket.properties"); loadResources(resources, loadedFiles); }

      catch (IOException e)

      { throw new WicketRuntimeException("Unable to load initializers file", e); }

      // now call any initializers we read
      callInitializers();
      }

      private void loadResources(Enumeration resources, Set loadedFiles) throws IOException
      {
      if (resources != null)
      {
      while (resources.hasMoreElements())
      {
      InputStream in = null;
      try
      {
      final URL url = (URL)resources.nextElement();
      if (!loadedFiles.contains(url))
      {
      log.info("resource url: {} ", url);
      final Properties properties = new Properties();
      in = url.openStream();
      properties.load(in);
      load(properties);
      loadedFiles.add(url);
      }
      }
      finally
      {
      if (in != null)

      { in.close(); }

      }
      }
      }
      }

      Attachments

        1. classresolverpatch.txt
          6 kB
          Johan Compagner

        Activity

          People

            jcompagner Johan Compagner
            aharris Adam Harris
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: