Class PayloadFromTemplateService
- java.lang.Object
-
- com.adaptris.core.ServiceImp
-
- com.adaptris.core.services.metadata.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 insetMetadataTokens(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.
-
-
Field Summary
-
Fields inherited from class com.adaptris.core.ServiceImp
log
-
-
Constructor Summary
Constructors Constructor Description PayloadFromTemplateService()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
closeService()
void
doService(AdaptrisMessage msg)
Apply the service to the message.KeyValuePairSet
getMetadataTokens()
java.lang.Boolean
getMultiLineExpression()
java.lang.Boolean
getQuiet()
java.lang.Boolean
getQuoteReplacement()
java.lang.String
getTemplate()
protected void
initService()
protected boolean
multiLineExpression()
void
prepare()
Prepare for initialisation.protected boolean
quoteReplacement()
void
setMetadataTokens(KeyValuePairSet metadataTokens)
Set the metadata tokens that will be used to perform metadata substitution.void
setMultiLineExpression(java.lang.Boolean b)
Whether or not to handle expressions usingPattern#DOTALL
mode for matching.void
setQuiet(java.lang.Boolean quiet)
Normally this service logs everything that is being replaced with can lead to excessive logging.void
setQuoteReplacement(java.lang.Boolean b)
If any metadata value contains special characters then ensure that they are escaped.void
setTemplate(java.lang.String s)
Set the template document that will be used as the template for generating a new document.<T extends PayloadFromTemplateService>
TwithMetadataTokens(KeyValuePairSet tokens)
<T extends PayloadFromTemplateService>
TwithMetadataTokens(java.util.Map<java.lang.String,java.lang.String> tokens)
<T extends PayloadFromTemplateService>
TwithMultiLineExpression(java.lang.Boolean b)
<T extends PayloadFromTemplateService>
TwithQuietMode(java.lang.Boolean quiet)
<T extends PayloadFromTemplateService>
TwithQuoteReplacement(java.lang.Boolean b)
<T extends PayloadFromTemplateService>
TwithTemplate(java.lang.String b)
-
Methods inherited from class com.adaptris.core.ServiceImp
changeState, close, continueOnFailure, createName, createQualifier, getContinueOnFail, getIsTrackingEndpoint, getUniqueId, init, isBranching, isTrackingEndpoint, requestClose, requestInit, requestStart, requestStop, retrieveComponentState, setContinueOnFail, setIsTrackingEndpoint, setUniqueId, start, stop
-
-
-
-
Method Detail
-
doService
public void doService(AdaptrisMessage msg) throws ServiceException
Description copied from interface:Service
Apply the service to the message.
- Parameters:
msg
- theAdaptrisMessage
to process- Throws:
ServiceException
- wrapping any underlyingException
s
-
initService
protected void initService() throws CoreException
- Specified by:
initService
in classServiceImp
- Throws:
CoreException
-
closeService
protected void closeService()
- Specified by:
closeService
in classServiceImp
-
prepare
public void prepare() throws CoreException
Description copied from interface:ComponentLifecycleExtension
Prepare for initialisation.- Throws:
CoreException
-
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(KeyValuePairSet tokens)
-
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}
).
-
withTemplate
public <T extends PayloadFromTemplateService> T withTemplate(java.lang.String b)
-
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)
-
withQuoteReplacement
public <T extends PayloadFromTemplateService> T withQuoteReplacement(java.lang.Boolean b)
-
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.
-
withQuietMode
public <T extends PayloadFromTemplateService> T withQuietMode(java.lang.Boolean quiet)
-
getMultiLineExpression
public java.lang.Boolean getMultiLineExpression()
-
setMultiLineExpression
public void setMultiLineExpression(java.lang.Boolean b)
Whether or not to handle expressions usingPattern#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.
-
withMultiLineExpression
public <T extends PayloadFromTemplateService> T withMultiLineExpression(java.lang.Boolean b)
-
multiLineExpression
protected boolean multiLineExpression()
-
-