public class MappedKeyMetadataFilter extends MetadataFilterImpl
MetadataFilter
implementation that modifies keys matching a specific regular expression to another key name.
Note that this implementation will include all items of metadata. Any keys that match the specified prefix will be replaced using
Matcher.replaceAll(String)
by getReplacement()
.
This specific filter is only useful when used as part of a producer that supports filtering which allows you to map header key
that are prefixed with a specific text into another header key. This could be useful if you are doing multiple HTTP calls within
the same workflow, and you need to keep track of all the individual headers that are returned by each request. So if you have
preserved some HTTP headers prefixed with InboundRequest_
then you might want to send specifically those headers back to
the requesting client without the prefix. Configure prefix="^InboundRequest_(.*)$"
and replacement="$1"
which
means that InboundRequest_User-Agent would become User-Agent
at the point you trigger the producer, but can be treated as
InboundRequest_User-Agent
throughout the rest of the workflow.
In the adapter configuration file this class is aliased as mapped-key-metadata-filter which is the preferred alternative to the fully qualified classname when building your configuration.
Constructor and Description |
---|
MappedKeyMetadataFilter() |
MappedKeyMetadataFilter(java.lang.String prefix,
java.lang.String replacement) |
Modifier and Type | Method and Description |
---|---|
MetadataCollection |
filter(MetadataCollection original)
Return all the metadata that matches the filter.
|
java.lang.String |
getPrefix() |
java.lang.String |
getReplacement() |
void |
setPrefix(java.lang.String s)
Set the prefix
|
void |
setReplacement(java.lang.String s)
Set the replacement
|
filter, filter
public MappedKeyMetadataFilter()
public MappedKeyMetadataFilter(java.lang.String prefix, java.lang.String replacement)
public MetadataCollection filter(MetadataCollection original)
MetadataFilter
original
- the original set of metadata.MetadataCollection
instance that has been filtered.public java.lang.String getPrefix()
public void setPrefix(java.lang.String s)
s
- the prefix, may be a JDK regular expression (e.g. ^myPrefix(.*)
)public java.lang.String getReplacement()
public void setReplacement(java.lang.String s)
s
- the replacement value; again may be a match group from your original setPrefix(String)
- e.g. $1