Class AbstractHeaderMapper<T>
java.lang.Object
org.springframework.integration.mapping.AbstractHeaderMapper<T>
- All Implemented Interfaces:
Aware
,BeanClassLoaderAware
,RequestReplyHeaderMapper<T>
- Direct Known Subclasses:
DefaultAmqpHeaderMapper
,DefaultSoapHeaderMapper
,DefaultXmppHeaderMapper
public abstract class AbstractHeaderMapper<T> extends Object implements RequestReplyHeaderMapper<T>, BeanClassLoaderAware
Abstract base class for
RequestReplyHeaderMapper
implementations.- Since:
- 2.1
- Author:
- Mark Fisher, Oleg Zhurakousky, Stephane Nicoll, Gary Russell, Artem Bilan
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
AbstractHeaderMapper.CompositeHeaderMatcher
A compositeAbstractHeaderMapper.HeaderMatcher
that matches if one of providedAbstractHeaderMapper.HeaderMatcher
s matches to theheaderName
.protected static class
AbstractHeaderMapper.ContentBasedHeaderMatcher
A content-basedAbstractHeaderMapper.HeaderMatcher
that matches if the specified header is contained within a list of candidates.static interface
AbstractHeaderMapper.HeaderMatcher
Strategy interface to determine if a given header name matches.protected static class
AbstractHeaderMapper.PatternBasedHeaderMatcher
A pattern-basedAbstractHeaderMapper.HeaderMatcher
that matches if the specified header matches one of the specified simple patterns.protected static class
AbstractHeaderMapper.PrefixBasedMatcher
A prefix-basedAbstractHeaderMapper.HeaderMatcher
that matches if the specified header starts with a configurable prefix.protected static class
AbstractHeaderMapper.SinglePatternBasedHeaderMatcher
A pattern-basedAbstractHeaderMapper.HeaderMatcher
that matches if the specified header matches the specified simple pattern. -
Field Summary
Fields Modifier and Type Field Description protected Log
logger
static String
NON_STANDARD_HEADER_NAME_PATTERN
A special pattern that matches any header that is not a standard header (i.e.static String
STANDARD_REPLY_HEADER_NAME_PATTERN
A special pattern that only matches standard reply headers.static String
STANDARD_REQUEST_HEADER_NAME_PATTERN
A special pattern that only matches standard request headers. -
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractHeaderMapper(String standardHeaderPrefix, Collection<String> requestHeaderNames, Collection<String> replyHeaderNames)
Create a new instance. -
Method Summary
Modifier and Type Method Description protected AbstractHeaderMapper.HeaderMatcher
createDefaultHeaderMatcher(String standardHeaderPrefix, Collection<String> headerNames)
Create the initialAbstractHeaderMapper.HeaderMatcher
based on the specified headers and standard header prefix.protected AbstractHeaderMapper.HeaderMatcher
createHeaderMatcher(Collection<String> patterns)
Create aAbstractHeaderMapper.HeaderMatcher
that match if any of the specifiedpatterns
match.protected String
createTargetPropertyName(String propertyName, boolean fromMessageHeaders)
Alter the specifiedpropertyName
if necessary.protected abstract Map<String,Object>
extractStandardHeaders(T source)
Extract the standard headers from the specified source.protected abstract Map<String,Object>
extractUserDefinedHeaders(T source)
Extract the user-defined headers from the specified source.void
fromHeadersToReply(MessageHeaders headers, T target)
Map from the givenMessageHeaders
to the specified reply target.void
fromHeadersToRequest(MessageHeaders headers, T target)
Map from the givenMessageHeaders
to the specified request target.protected ClassLoader
getClassLoader()
protected <V> V
getHeaderIfAvailable(Map<String,Object> headers, String name, Class<V> type)
protected Collection<String>
getTransientHeaderNames()
Return the transient header names.protected void
populateStandardHeaders(Map<String,Object> allHeaders, Map<String,Object> subset, T target)
Populate the specified standard headers to the specified source.protected abstract void
populateStandardHeaders(Map<String,Object> headers, T target)
Populate the specified standard headers to the specified source.protected abstract void
populateUserDefinedHeader(String headerName, Object headerValue, T target)
Populate the specified user-defined headers to the specified source.void
setBeanClassLoader(ClassLoader classLoader)
void
setReplyHeaderNames(String... replyHeaderNames)
Provide the header names that should be mapped to a response from aMessageHeaders
.void
setRequestHeaderNames(String... requestHeaderNames)
Provide the header names that should be mapped from a request to aMessageHeaders
.Map<String,Object>
toHeadersFromReply(T source)
Map from the given reply object to abstractedMessageHeaders
.Map<String,Object>
toHeadersFromRequest(T source)
Map from the given request object to abstractedMessageHeaders
.
-
Field Details
-
STANDARD_REQUEST_HEADER_NAME_PATTERN
A special pattern that only matches standard request headers.- See Also:
- Constant Field Values
-
STANDARD_REPLY_HEADER_NAME_PATTERN
A special pattern that only matches standard reply headers.- See Also:
- Constant Field Values
-
NON_STANDARD_HEADER_NAME_PATTERN
A special pattern that matches any header that is not a standard header (i.e. any header that does not start with the configured standard header prefix)- See Also:
- Constant Field Values
-
logger
-
-
Constructor Details
-
AbstractHeaderMapper
protected AbstractHeaderMapper(String standardHeaderPrefix, Collection<String> requestHeaderNames, Collection<String> replyHeaderNames)Create a new instance.- Parameters:
standardHeaderPrefix
- the header prefix that identifies standard header. Such prefix helps to differentiate user-defined headers from standard headers. If set, user-defined headers are also mapped by defaultrequestHeaderNames
- the header names that should be mapped from a request toMessageHeaders
replyHeaderNames
- the header names that should be mapped to a response fromMessageHeaders
-
-
Method Details
-
setBeanClassLoader
- Specified by:
setBeanClassLoader
in interfaceBeanClassLoaderAware
-
getClassLoader
-
setRequestHeaderNames
Provide the header names that should be mapped from a request to aMessageHeaders
.The values can also contain simple wildcard patterns (e.g. "foo*" or "*foo") to be matched.
- Parameters:
requestHeaderNames
- The request header names.
-
setReplyHeaderNames
Provide the header names that should be mapped to a response from aMessageHeaders
.The values can also contain simple wildcard patterns (e.g. "foo*" or "*foo") to be matched.
- Parameters:
replyHeaderNames
- The reply header names.
-
createDefaultHeaderMatcher
protected AbstractHeaderMapper.HeaderMatcher createDefaultHeaderMatcher(String standardHeaderPrefix, Collection<String> headerNames)Create the initialAbstractHeaderMapper.HeaderMatcher
based on the specified headers and standard header prefix.- Parameters:
standardHeaderPrefix
- the prefix for standard headers.headerNames
- the collection of header names to map.- Returns:
- the default
AbstractHeaderMapper.HeaderMatcher
instance.
-
createHeaderMatcher
Create aAbstractHeaderMapper.HeaderMatcher
that match if any of the specifiedpatterns
match. The pattern can be a header name, a wildcard pattern such asfoo*
,*foo
, orwithin*foo
.Special patterns are also recognized:
STANDARD_REQUEST_HEADER_NAME_PATTERN
,STANDARD_REQUEST_HEADER_NAME_PATTERN
andNON_STANDARD_HEADER_NAME_PATTERN
.- Parameters:
patterns
- the patterns to apply- Returns:
- a header mapper that match if any of the specified patters match
-
fromHeadersToRequest
Description copied from interface:RequestReplyHeaderMapper
Map from the givenMessageHeaders
to the specified request target.- Specified by:
fromHeadersToRequest
in interfaceRequestReplyHeaderMapper<T>
- Parameters:
headers
- the abstracted MessageHeaderstarget
- the native target request
-
fromHeadersToReply
Description copied from interface:RequestReplyHeaderMapper
Map from the givenMessageHeaders
to the specified reply target.- Specified by:
fromHeadersToReply
in interfaceRequestReplyHeaderMapper<T>
- Parameters:
headers
- the abstracted MessageHeaderstarget
- the native target reply
-
toHeadersFromRequest
Description copied from interface:RequestReplyHeaderMapper
Map from the given request object to abstractedMessageHeaders
.- Specified by:
toHeadersFromRequest
in interfaceRequestReplyHeaderMapper<T>
- Parameters:
source
- the native target request- Returns:
- the abstracted MessageHeaders
-
toHeadersFromReply
Description copied from interface:RequestReplyHeaderMapper
Map from the given reply object to abstractedMessageHeaders
.- Specified by:
toHeadersFromReply
in interfaceRequestReplyHeaderMapper<T>
- Parameters:
source
- the native target reply- Returns:
- the abstracted MessageHeaders
-
getHeaderIfAvailable
-
createTargetPropertyName
Alter the specifiedpropertyName
if necessary. By default, the originalpropertyName
is returned.- Parameters:
propertyName
- the original name of the property.fromMessageHeaders
- specify if the property originates from aMessageHeaders
instance (true) or from the type managed by this mapper (false).- Returns:
- the property name for mapping.
-
getTransientHeaderNames
Return the transient header names. Transient headers are never mapped.- Returns:
- the names of headers to be skipped from mapping.
-
extractStandardHeaders
Extract the standard headers from the specified source.- Parameters:
source
- the source object to extract standard headers.- Returns:
- the map of headers to be mapped.
-
extractUserDefinedHeaders
Extract the user-defined headers from the specified source.- Parameters:
source
- the source object to extract user defined headers.- Returns:
- the map of headers to be mapped.
-
populateStandardHeaders
Populate the specified standard headers to the specified source.- Parameters:
headers
- the map of standard headers to be populated.target
- the target object to populate headers.
-
populateStandardHeaders
protected void populateStandardHeaders(@Nullable Map<String,Object> allHeaders, Map<String,Object> subset, T target)Populate the specified standard headers to the specified source. If not implemented, callspopulateStandardHeaders(Map, Object)
.- Parameters:
allHeaders
- all headers including transient.subset
- the map of standard headers to be populated.target
- the target object to populate headers.- Since:
- 5.1
-
populateUserDefinedHeader
Populate the specified user-defined headers to the specified source.- Parameters:
headerName
- the user defined header name to be populated.headerValue
- the user defined header value to be populated.target
- the target object to populate headers.
-