Uploaded image for project: 'Commons Configuration'
  1. Commons Configuration
  2. CONFIGURATION-381

Support automatic reloading for configuration files in JBoss VFS

    Details

    • Type: Improvement
    • Status: Open
    • Priority: Minor
    • Resolution: Unresolved
    • Affects Version/s: 1.6
    • Fix Version/s: None
    • Component/s: File reloading
    • Labels:
      None

      Description

      Using Commons Configuration with JBoss 5 presents problems when storing files in the JBoss directories and referencing them with relative paths. This applies to configuration files stored in the traditional spot for JBoss configuration, like JBOSS_HOME/server/default/conf/. More specifically, when FileChangedReloadingStrategy tries to resolve the file path it gets a vfsfile: URL from the JBoss-modified context classloader, that it can't parse. The following patch adds support for this URL scheme by fixing the resource URL to avoid VFS, and allows Commons Configuration to properly recognize file modifications in the file system.

      FileChangedReloadingStrategy.java
      Index: FileChangedReloadingStrategy.java
      ===================================================================
      --- FileChangedReloadingStrategy.java	(revision 764760)
      +++ FileChangedReloadingStrategy.java	(working copy)
      @@ -46,6 +46,9 @@
           /** Constant for the jar URL protocol.*/
           private static final String JAR_PROTOCOL = "jar";
       
      +    /** Constant for the JBoss MC VFSFile URL protocol.*/
      +    private static final String VFSFILE_PROTOCOL = "vfsfile";
      +
           /** Constant for the default refresh delay.*/
           private static final int DEFAULT_REFRESH_DELAY = 5000;
       
      @@ -161,7 +164,8 @@
       
           /**
            * Helper method for transforming a URL into a file object. This method
      -     * handles file: and jar: URLs.
      +     * handles file: and jar: URLs, as well as JBoss VFS-specific vfsfile:
      +     * URLs.
            *
            * @param url the URL to be converted
            * @return the resulting file or <b>null </b>
      @@ -181,6 +185,18 @@
                       return null;
                   }
               }
      +        else if (VFSFILE_PROTOCOL.equals(url.getProtocol()))
      +        {
      +            String path = url.getPath();
      +            try
      +            {
      +                return ConfigurationUtils.fileFromURL(new URL("file:" + path));
      +            }
      +            catch (MalformedURLException mex)
      +            {
      +                return null;
      +            }
      +        }
               else
               {
                   return ConfigurationUtils.fileFromURL(url);
      

        Activity

        Hide
        past Panagiotis Astithas added a comment -

        Attached the patch for easier evaluation.

        Show
        past Panagiotis Astithas added a comment - Attached the patch for easier evaluation.
        Hide
        ralph.goers@dslextreme.com Ralph Goers added a comment -

        I don't suppose there is any way to unit test this? I'm looking in to applying this. It seems safe enough. I'm curious though if you have tried using the VFS FileSystem in trunk to see if it has similar issues. I'd appreciate the feedback.

        Show
        ralph.goers@dslextreme.com Ralph Goers added a comment - I don't suppose there is any way to unit test this? I'm looking in to applying this. It seems safe enough. I'm curious though if you have tried using the VFS FileSystem in trunk to see if it has similar issues. I'd appreciate the feedback.
        Hide
        past Panagiotis Astithas added a comment -

        Can't think of an easy way to unit test this, sorry. As for the VFS FileSystem, I haven't used it, since I haven't found a use for Commons VFS in combination with configuration files, yet. From a cursory glance at the code however, I don't see anything similar to this issue, so there doesn't appear do be any need for concern.

        Show
        past Panagiotis Astithas added a comment - Can't think of an easy way to unit test this, sorry. As for the VFS FileSystem, I haven't used it, since I haven't found a use for Commons VFS in combination with configuration files, yet. From a cursory glance at the code however, I don't see anything similar to this issue, so there doesn't appear do be any need for concern.

          People

          • Assignee:
            Unassigned
            Reporter:
            past Panagiotis Astithas
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:

              Development