Commons Configuration
  1. Commons Configuration
  2. CONFIGURATION-478

Cannot write to files within an app server directory

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Invalid
    • Affects Version/s: 1.7, 1.8
    • Fix Version/s: 1.9
    • Component/s: Build
    • Environment:

      Java , Linux, Jboss

      Description

      Hi

      This issue is really grappling me. I use Apache commons configuration to read the configuration for my application. I expose my configuration through a jmx client so that I can change the configuration at runtime and would like to persist the changes to the original load form.

      I have multiple configuration sources so I use a CombinedConfiguration object to read in my config.xml file. I have wrapped custom logic and rules to save the confgiuration to the persistent store.
      I use Jboss AS5 to deploy my application.

      All is well when I have configuration files in the filesystem outside $JBOSS-HOME/server/default/deploy. I am able to read fine and write back to the config files fine too.
      but the problem is when I bring in the Config files in the following directoy $JBOSS-HOME/server/default/deploy/

      {application-name}

      /..
      I can read the configuration fine, but when I try to write the configuration back to the persistent store using the save method of the respective configuration(like PropertiesConfiguration & XMLConfiguration) using a jmx client(I also tried to harcode and save within code immediatly after reading my configuration). I keep getting the follwing exception :

      java.net.UnknownServiceException: protocol doesn't support output
      at java.net.URLConnection.getOutputStream(URLConnection.java:792)
      at org.apache.commons.configuration.DefaultFileSystem.getOutputStream(DefaultFileSystem.java:113)
      at org.apache.commons.configuration.AbstractFileConfiguration.save(AbstractFileConfiguration.java:461)
      at org.apache.commons.configuration.AbstractFileConfiguration.save(AbstractFileConfiguration.java:402)
      at org.apache.commons.configuration.AbstractFileConfiguration.possiblySave(AbstractFileConfiguration.java:737)
      at org.apache.commons.configuration.AbstractFileConfiguration.clearProperty(AbstractFileConfiguration.java:784)
      at org.apache.commons.configuration.AbstractConfiguration.setProperty(AbstractConfiguration.java:483)
      at org.apache.commons.configuration.AbstractFileConfiguration.setProperty(AbstractFileConfiguration.java:774)
      ......

      Please throw some light on the exception because it is helping me nowhere in understanding the issue
      If I am able to read it, I should also be able to save it back..but it is not happening within JBOSS directory(I can only read). Moment I shift my configurations outside that to a different place in the Filesystem say /home/../Config and also keep the config.xml(containing the reference to the Configuration sources)it is perfectly working fine.

      This is being a blocker for me. I may have completely misread the scenario, so please throw light on the same if I am missing anything or more details are needed.

      Following is the piece of code used to read the configuration :

      ...
      builder.setFile(new File(Path to CONFIG_DIRECTORY +
      CONFIG_DEFINITION_FILENAME(config.xml)));
      CombinedConfiguration combinedConfig = builder.getConfiguration(true);

      sample config.xml file :

      <?xml version="1.0" encoding="ISO-8859-1"?>
      <configuration>
      <header />
      <override>
      <properties
      fileName="db.properties"
      autoSave="true" config-name="properties1" />
      <properties
      fileName="jms.properties"
      autoSave="true" config-name="properties2" />
      <properties
      fileName="test.xml"
      autoSave="true" config-name="properties3" />
      <xml fileName="gui.xml"
      autoSave="true" config-name="xml1" />
      </override>
      <additional />
      </configuration>

      Following is sample code used to write back updated values to the persistent store :

      xmlConfig = (XMLConfiguration) combinedConfig.getConfiguration("configuration source name");;
      if (xmlConfig.containsKey(key)) {
      try {

      // Update the value.
      xmlConfig.setProperty(key, value);
      xmlConfig.save();

        Activity

        Hide
        Oliver Heger added a comment -

        Can you log the URL of the configuration you want to save: xmlConfig.getURL() ?

        Without knowing too many details about JBoss's deployment mechanism, I assume that your application is not directly executed from the deploy folder, but copied into a working directory. Therefore, you probably end up with a URL pointing to a file in a virtual JBoss file system. That this file cannot be written is pretty clear.

        In general, I do not think that it is a good idea to manipulate content of an application folder which has been deployed to a server. The directory is under control of the application server, and changing it - if possible at all - may have undesired side effects.

        Further, I doubt that this issue is specific to Commons Configuration. You can check whether you are able to read, manipulate, and save any other file from your application directory.

        Show
        Oliver Heger added a comment - Can you log the URL of the configuration you want to save: xmlConfig.getURL() ? Without knowing too many details about JBoss's deployment mechanism, I assume that your application is not directly executed from the deploy folder, but copied into a working directory. Therefore, you probably end up with a URL pointing to a file in a virtual JBoss file system. That this file cannot be written is pretty clear. In general, I do not think that it is a good idea to manipulate content of an application folder which has been deployed to a server. The directory is under control of the application server, and changing it - if possible at all - may have undesired side effects. Further, I doubt that this issue is specific to Commons Configuration. You can check whether you are able to read, manipulate, and save any other file from your application directory.
        Hide
        Oliver Heger added a comment -

        Any news here? I tend to close this ticket as I do not think we can do anything about it.

        Show
        Oliver Heger added a comment - Any news here? I tend to close this ticket as I do not think we can do anything about it.
        Hide
        Oliver Heger added a comment -

        Got no more feedback, so closing as invalid.

        Show
        Oliver Heger added a comment - Got no more feedback, so closing as invalid.

          People

          • Assignee:
            Unassigned
            Reporter:
            raghutpk
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Time Tracking

              Estimated:
              Original Estimate - 24h
              24h
              Remaining:
              Remaining Estimate - 24h
              24h
              Logged:
              Time Spent - Not Specified
              Not Specified

                Development