@ComponentProfile(summary="Construct a new payload based on metadata and a template", tag="service,metadata") public class PayloadFromMetadataService extends ServiceImp
Takes the template stored in setTemplate(String)
and replaces parts of the template with values from various metadata
keys specified in setMetadataTokens(KeyValuePairSet)
to create a new payload.
Uses the JDK regular expression engine, take care when replacing special regular expression values.
In the adapter configuration file this class is aliased as payload-from-metadata-service which is the preferred alternative to the fully qualified classname when building your configuration.
log
CONFIRMATION_ID_KEY
Constructor and Description |
---|
PayloadFromMetadataService() |
PayloadFromMetadataService(java.lang.String template) |
Modifier and Type | Method and Description |
---|---|
protected void |
closeService() |
void |
doService(AdaptrisMessage msg)
Apply the service to the message.
|
java.lang.Boolean |
getEscapeBackslash() |
KeyValuePairSet |
getMetadataTokens() |
java.lang.Boolean |
getMultiLineExpression() |
java.lang.Boolean |
getQuiet() |
java.lang.String |
getTemplate() |
protected void |
initService() |
void |
prepare()
Prepare for initialisation.
|
void |
setEscapeBackslash(java.lang.Boolean b)
If any metadata value contains backslashes then ensure that they are escaped.
|
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 using
Pattern#DOTALL mode for matching. |
void |
setQuiet(java.lang.Boolean quiet)
Normally this service logs everything that is being replaced; set to true to stop it.
|
void |
setTemplate(java.lang.String s)
Set the template document that will be used as the template for generating a new document.
|
PayloadFromMetadataService |
withEscapeBackslash(java.lang.Boolean b) |
PayloadFromMetadataService |
withMultiLineExpression(java.lang.Boolean b) |
PayloadFromMetadataService |
withQuietMode(java.lang.Boolean quiet) |
changeState, close, continueOnFailure, createName, createQualifier, getContinueOnFail, getIsTrackingEndpoint, getLookupName, getUniqueId, init, isBranching, isTrackingEndpoint, requestClose, requestInit, requestStart, requestStop, retrieveComponentState, setContinueOnFail, setIsTrackingEndpoint, setLookupName, setUniqueId, start, stop
public PayloadFromMetadataService()
public PayloadFromMetadataService(java.lang.String template)
public void doService(AdaptrisMessage msg) throws ServiceException
Service
Apply the service to the message.
msg
- the AdaptrisMessage
to processServiceException
- wrapping any underlying Exception
sService.doService(com.adaptris.core.AdaptrisMessage)
protected void initService() throws CoreException
initService
in class ServiceImp
CoreException
protected void closeService()
closeService
in class ServiceImp
public KeyValuePairSet getMetadataTokens()
public void setMetadataTokens(KeyValuePairSet metadataTokens)
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
metadataTokens
- the metadataTokens to setpublic java.lang.String getTemplate()
public void setTemplate(java.lang.String s)
s
- the template to set (supports metadata expansion via %message{key}
).public java.lang.Boolean getEscapeBackslash()
public void setEscapeBackslash(java.lang.Boolean b)
Set this flag to make sure that special characters are treated literally by the regular expression engine.
b
- the value to setMatcher.quoteReplacement(String)
public PayloadFromMetadataService withEscapeBackslash(java.lang.Boolean b)
public java.lang.Boolean getQuiet()
public void setQuiet(java.lang.Boolean quiet)
quiet
- true or false, default false if not specified.public PayloadFromMetadataService withQuietMode(java.lang.Boolean quiet)
public java.lang.Boolean getMultiLineExpression()
public void setMultiLineExpression(java.lang.Boolean b)
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; for backwards compatiblity reasons, it defaults to false. Setting it to true means that multi-line
templates along the lines of will be supported.
{
"key": "%message{metadataKey}",
"key2: "%message{anotherMetadatKey}",
}
b
- true, default is false if not specified.public PayloadFromMetadataService withMultiLineExpression(java.lang.Boolean b)
public void prepare() throws CoreException
ComponentLifecycleExtension
CoreException