public abstract class AbstractHeaderMapper<T> extends Object implements RequestReplyHeaderMapper<T>, BeanClassLoaderAware
RequestReplyHeaderMapper
implementations.Modifier and Type | Class and Description |
---|---|
protected static class |
AbstractHeaderMapper.CompositeHeaderMatcher
A composite
AbstractHeaderMapper.HeaderMatcher that matches if one of provided
AbstractHeaderMapper.HeaderMatcher s matches to the headerName . |
protected static class |
AbstractHeaderMapper.ContentBasedHeaderMatcher
A content-based
AbstractHeaderMapper.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-based
AbstractHeaderMapper.HeaderMatcher that matches if the specified
header matches one of the specified simple patterns. |
protected static class |
AbstractHeaderMapper.PrefixBasedMatcher
A prefix-based
AbstractHeaderMapper.HeaderMatcher that matches if the specified
header starts with a configurable prefix. |
protected static class |
AbstractHeaderMapper.SinglePatternBasedHeaderMatcher
A pattern-based
AbstractHeaderMapper.HeaderMatcher that matches if the specified
header matches the specified simple pattern. |
Modifier and Type | Field and 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.
|
Modifier | Constructor and Description |
---|---|
protected |
AbstractHeaderMapper(String standardHeaderPrefix,
Collection<String> requestHeaderNames,
Collection<String> replyHeaderNames)
Create a new instance.
|
Modifier and Type | Method and Description |
---|---|
protected AbstractHeaderMapper.HeaderMatcher |
createDefaultHeaderMatcher(String standardHeaderPrefix,
Collection<String> headerNames)
Create the initial
AbstractHeaderMapper.HeaderMatcher based on the specified headers and
standard header prefix. |
protected AbstractHeaderMapper.HeaderMatcher |
createHeaderMatcher(Collection<String> patterns)
Create a
AbstractHeaderMapper.HeaderMatcher that match if any of the specified patterns
match. |
protected String |
createTargetPropertyName(String propertyName,
boolean fromMessageHeaders)
Alter the specified
propertyName 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 given
MessageHeaders to the specified reply target. |
void |
fromHeadersToRequest(MessageHeaders headers,
T target)
Map from the given
MessageHeaders 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 a
MessageHeaders . |
void |
setRequestHeaderNames(String... requestHeaderNames)
Provide the header names that should be mapped from a request
to a
MessageHeaders . |
Map<String,Object> |
toHeadersFromReply(T source)
Map from the given reply object to abstracted
MessageHeaders . |
Map<String,Object> |
toHeadersFromRequest(T source)
Map from the given request object to abstracted
MessageHeaders . |
public static final String STANDARD_REQUEST_HEADER_NAME_PATTERN
public static final String STANDARD_REPLY_HEADER_NAME_PATTERN
public static final String NON_STANDARD_HEADER_NAME_PATTERN
protected final Log logger
protected AbstractHeaderMapper(String standardHeaderPrefix, Collection<String> requestHeaderNames, Collection<String> replyHeaderNames)
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 to MessageHeaders
replyHeaderNames
- the header names that should be mapped to a response from MessageHeaders
public void setBeanClassLoader(ClassLoader classLoader)
setBeanClassLoader
in interface BeanClassLoaderAware
protected ClassLoader getClassLoader()
public void setRequestHeaderNames(String... requestHeaderNames)
MessageHeaders
.
The values can also contain simple wildcard patterns (e.g. "foo*" or "*foo") to be matched.
requestHeaderNames
- The request header names.public void setReplyHeaderNames(String... replyHeaderNames)
MessageHeaders
.
The values can also contain simple wildcard patterns (e.g. "foo*" or "*foo") to be matched.
replyHeaderNames
- The reply header names.protected AbstractHeaderMapper.HeaderMatcher createDefaultHeaderMatcher(String standardHeaderPrefix, Collection<String> headerNames)
AbstractHeaderMapper.HeaderMatcher
based on the specified headers and
standard header prefix.standardHeaderPrefix
- the prefix for standard headers.headerNames
- the collection of header names to map.AbstractHeaderMapper.HeaderMatcher
instance.protected AbstractHeaderMapper.HeaderMatcher createHeaderMatcher(Collection<String> patterns)
AbstractHeaderMapper.HeaderMatcher
that match if any of the specified patterns
match. The pattern can be a header name, a wildcard pattern such as
foo*
, *foo
, or within*foo
.
Special patterns are also recognized: STANDARD_REQUEST_HEADER_NAME_PATTERN
,
STANDARD_REQUEST_HEADER_NAME_PATTERN
and NON_STANDARD_HEADER_NAME_PATTERN
.
patterns
- the patterns to applypublic void fromHeadersToRequest(MessageHeaders headers, T target)
RequestReplyHeaderMapper
MessageHeaders
to the specified request target.fromHeadersToRequest
in interface RequestReplyHeaderMapper<T>
headers
- the abstracted MessageHeaderstarget
- the native target requestpublic void fromHeadersToReply(MessageHeaders headers, T target)
RequestReplyHeaderMapper
MessageHeaders
to the specified reply target.fromHeadersToReply
in interface RequestReplyHeaderMapper<T>
headers
- the abstracted MessageHeaderstarget
- the native target replypublic Map<String,Object> toHeadersFromRequest(T source)
RequestReplyHeaderMapper
MessageHeaders
.toHeadersFromRequest
in interface RequestReplyHeaderMapper<T>
source
- the native target requestpublic Map<String,Object> toHeadersFromReply(T source)
RequestReplyHeaderMapper
MessageHeaders
.toHeadersFromReply
in interface RequestReplyHeaderMapper<T>
source
- the native target reply@Nullable protected <V> V getHeaderIfAvailable(Map<String,Object> headers, String name, Class<V> type)
protected String createTargetPropertyName(String propertyName, boolean fromMessageHeaders)
propertyName
if necessary. By default, the original
propertyName
is returned.propertyName
- the original name of the property.fromMessageHeaders
- specify if the property originates from a MessageHeaders
instance (true) or from the type managed by this mapper (false).protected Collection<String> getTransientHeaderNames()
protected abstract Map<String,Object> extractStandardHeaders(T source)
source
- the source object to extract standard headers.protected abstract Map<String,Object> extractUserDefinedHeaders(T source)
source
- the source object to extract user defined headers.protected abstract void populateStandardHeaders(Map<String,Object> headers, T target)
headers
- the map of standard headers to be populated.target
- the target object to populate headers.protected void populateStandardHeaders(@Nullable Map<String,Object> allHeaders, Map<String,Object> subset, T target)
populateStandardHeaders(Map, Object)
.allHeaders
- all headers including transient.subset
- the map of standard headers to be populated.target
- the target object to populate headers.protected abstract void populateUserDefinedHeader(String headerName, Object headerValue, T target)
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.