Class MicroprofileUtils


  • public class MicroprofileUtils
    extends java.lang.Object
    Utility methods supporting JakartaEE microprofile, esp. org.eclipse.microprofile.config.
    • Method Detail

      • resolveConfigProperties

        public static java.lang.String resolveConfigProperties​(java.lang.String text)
        Calling resolveConfigProperties(String, Pattern) with the default "pubserver" pattern.

        This pattern is defined as

         (?i)\$\{MPCONFIG=(?<key>(pubserver)[_.-][\w.-]+)\}
         
        It will match config properties like e.g. pubserver.foo-BAR or PUBSERVER_FOO_BAR
        Parameters:
        text -
        Returns:
      • resolveConfigProperties

        public static java.lang.String resolveConfigProperties​(java.lang.String text,
                                                               java.util.regex.Pattern mpConfigPropertyPattern)
        Support for microprofile config property stored in Payara.
        Requires Payara 5.183 or higher.

        This will replace patterns like ${MPCONFIG=pubserver.foo.bar} within the input string with the value stored in the microprofile config alias "my.value". Microprofile config is as combination of several config locations including system properties defined in Payara.

        If the value is not found then the input string will be returned unchanged.

        The input text may contain more than one pattern like in "This is pubserver ${MPCONFIG=PUBSERVER_NAME} with instance id ${MPCONFIG=PUBSERVER_INSTANCE_ID}". This may result in "This is pubserver pim-prod-pub with instance id 4"

        mpConfigPropertyPattern must be a regex pattern containing a matcher group called "key". It is the value of the matched "key" that will get replaced. As an example we give the regex that implementations the pattern used in Payara's domain.xml: \$\{ALIAS=(?<key>[\w.-]+)\}.

        For security reasons we strongly recommend to add a prefix to the key, that effectively creates a "namespace" for config properties. Otherwise every configurator might easily read out all passwords values stored in Payara just by changing e.g. configs in ison.

        Regexp can of course deviate from the ${prefix=name} placeholder patterns. An ASP tag like injection like "<%=key %>" could be expressed in regexp "<%=\s*(?<key>\w+)\s*%>".

        Parameters:
        text -
        mpConfigPropertyPattern -
        Returns: