Class PayloadFromTemplateService

  • All Implemented Interfaces:
    AdaptrisComponent, ComponentLifecycle, ComponentLifecycleExtension, MessageEventGenerator, Service, StateManagedComponent

    @ComponentProfile(summary="Construct a new payload based on metadata and a template",
                      tag="service,metadata",
                      since="3.10.0")
    public class PayloadFromTemplateService
    extends ServiceImp
    Replaces the payload with something built from a template and optional metadata keys.

    Takes the template stored in setTemplate(String) and replaces parts of the template either by resolving the %message expression language or with values from various metadata keys specified in setMetadataTokens(KeyValuePairSet) to create a new payload.

    Since under the covers it uses the JDK regular expression engine, take care when your replacement may contain special regular expression characters (such as \ and $

    In the adapter configuration file this class is aliased as payload-from-template which is the preferred alternative to the fully qualified classname when building your configuration.

    • Constructor Detail

      • PayloadFromTemplateService

        public PayloadFromTemplateService()
    • Method Detail

      • doService

        public void doService​(AdaptrisMessage msg)
                       throws ServiceException
        Description copied from interface: Service

        Apply the service to the message.

        Parameters:
        msg - the AdaptrisMessage to process
        Throws:
        ServiceException - wrapping any underlying Exceptions
      • getMetadataTokens

        public KeyValuePairSet getMetadataTokens()
        Returns:
        the metadataTokens
      • setMetadataTokens

        public void setMetadataTokens​(KeyValuePairSet metadataTokens)
        Set the metadata tokens that will be used to perform metadata substitution.

        For the purposes of this service, the key to the key-value-pair is the metadata key, and the value is the token that will be replaced within the template

        Parameters:
        metadataTokens - the metadataTokens to set
      • withMetadataTokens

        public <T extends PayloadFromTemplateService> T withMetadataTokens​(java.util.Map<java.lang.String,​java.lang.String> tokens)
      • getTemplate

        public java.lang.String getTemplate()
        Returns:
        the template
      • setTemplate

        public void setTemplate​(java.lang.String s)
        Set the template document that will be used as the template for generating a new document.
        Parameters:
        s - the template to set (supports metadata expansion via %message{key}).
      • getQuoteReplacement

        public java.lang.Boolean getQuoteReplacement()
      • setQuoteReplacement

        public void setQuoteReplacement​(java.lang.Boolean b)
        If any metadata value contains special characters then ensure that they are escaped.

        Set this flag to make sure that special characters are treated literally by the regular expression engine.

        Parameters:
        b - the value to set, defaults to true if not explicitly configured.
        See Also:
        Matcher.quoteReplacement(String)
      • quoteReplacement

        protected boolean quoteReplacement()
      • getQuiet

        public java.lang.Boolean getQuiet()
      • setQuiet

        public void setQuiet​(java.lang.Boolean quiet)
        Normally this service logs everything that is being replaced with can lead to excessive logging.
        Parameters:
        quiet - true or false, default false if not specified.
      • getMultiLineExpression

        public java.lang.Boolean getMultiLineExpression()
      • setMultiLineExpression

        public void setMultiLineExpression​(java.lang.Boolean b)
        Whether or not to handle expressions using Pattern#DOTALL mode for matching.

        The value here is passed to InterlokMessage.resolve(String, boolean). True will allow you to do replacements on multi-line templates; It defaults to true which means that multi-line templates along the lines of will be supported.

         
         {
           "key": "%message{metadataKey}",
           "key2: "%message{anotherMetadatKey}",
         }
         
         

        Parameters:
        b - true/false, default is true if not specified.
      • multiLineExpression

        protected boolean multiLineExpression()