wicket.properties cannot be found in OSGi
-----------------------------------------

                 Key: WICKET-1371
                 URL: https://issues.apache.org/jira/browse/WICKET-1371
             Project: Wicket
          Issue Type: Bug
          Components: wicket
    Affects Versions: 1.3.1
         Environment: Windows XP, Java 5, Wicket 1.3.1, Equinox OSGi 3.3.1
            Reporter: Adam Harris


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();
                                }
                        }
                }
        }
    } 

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to