Announcement Announcement Module
Collapse
No announcement yet.
Missing call to convertProperties (and convertPropertyValue) Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Missing call to convertProperties (and convertPropertyValue)

    I was pleasantly surprise to find that the API have been enhanced in Spring 1.1.3 to provide for a callback function to convert properties entries in the form of convertProperties and convertPropertyValue methods in PropertyResourceConfigurer.

    Alas... the callback function was not working. Further checking of the source reveal that the method was not call at all by any class.

    There seemed to be some missing lines in the PropertyPlaceholderConfigurer class that did not class.

    I have made some changes to the parseString method in the PropertyPlaceholderConfigurer class to intercept the call to invoke the converPropertyValue method. However I am not sure when and how the convertProperties method should be called.

    Below is the simple source changes I made to call the converPropertyValue in the parseString method. I hope the originator or someone in this group can shade some light of their right usage. Thanks in advance.


    Code:
      protected String parseString(Properties props, String strVal, String originalPlaceholder)
                throws BeansException {
                     ...
                    String propVal = null;
                    if (systemPropertiesMode == 2)
                        propVal = System.getProperty(placeholder);
                    if (propVal == null)
                        propVal = resolvePlaceholder(placeholder, props);
                    if (propVal == null && systemPropertiesMode == 1)
                        propVal = System.getProperty(placeholder);
                    if (propVal != null) {
                        //  modified to call the convertProertyValue here
                        [b]propVal = this.convertPropertyValue(parseString(props, propVal, originalPlaceholderToUse));[/b]
                        //  original called below
                        //  propVal = parseString(props, propVal, originalPlaceholderToUse);
                        if (logger.isDebugEnabled())
                            logger.debug("Resolving placeholder '" + placeholder + "' to [" + propVal + "]");
                        buf.replace(startIndex, endIndex + placeholderSuffix.length(), propVal);
                        startIndex = buf.toString().indexOf(placeholderPrefix, startIndex + propVal.length());
                    } else if (ignoreUnresolvablePlaceholders)
                        startIndex = buf.toString().indexOf(placeholderPrefix, endIndex + placeholderSuffix.length());
                    else
                        throw new BeanDefinitionStoreException("Could not resolve placeholder '" + placeholder + "'");
                } else {
                    startIndex = -1;
                }
            }

  • #2
    Still Missing, so here's a workaround

    As an alternative to changing the source code (or waiting for it to be changed for you), you can also override the parseString method in addition to the convertPropertyValue method as follows:

    Code:
      protected String parseString(Properties props, String strVal,
          String originalPlaceholder) throws BeansException {
        String propVal = super.parseString(props, strVal, originalPlaceholder);
        if (strVal.startsWith(".encrypted}")) {
          propVal = convertPropertyValue(propVal);
        }
        return propVal;
      }
    I use the ".encrypted" suffix for all my encrypted properties: that way the convertPropertyValue method's decryption process is only applied when needed.

    Comment


    • #3
      I have added a bug for this in the Issue Tracker. It is still a problem in 1.1.5. Although overriding parseString has an additional benefit: You can suppress log messages related to the encrypted properties. :?

      Comment

      Working...
      X