Class AbstractHeaderMapper<T>
java.lang.Object
org.springframework.integration.mapping.AbstractHeaderMapper<T>
- All Implemented Interfaces:
org.springframework.beans.factory.Aware,org.springframework.beans.factory.BeanClassLoaderAware,RequestReplyHeaderMapper<T>
public abstract class AbstractHeaderMapper<T> extends java.lang.Object implements RequestReplyHeaderMapper<T>, org.springframework.beans.factory.BeanClassLoaderAware
Abstract base class for
RequestReplyHeaderMapper implementations.- Since:
- 2.1
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classAbstractHeaderMapper.CompositeHeaderMatcherA compositeAbstractHeaderMapper.HeaderMatcherthat matches if one of providedAbstractHeaderMapper.HeaderMatchers matches to theheaderName.protected static classAbstractHeaderMapper.ContentBasedHeaderMatcherA content-basedAbstractHeaderMapper.HeaderMatcherthat matches if the specified header is contained within a list of candidates.static interfaceAbstractHeaderMapper.HeaderMatcherStrategy interface to determine if a given header name matches.protected static classAbstractHeaderMapper.PatternBasedHeaderMatcherA pattern-basedAbstractHeaderMapper.HeaderMatcherthat matches if the specified header matches one of the specified simple patterns.protected static classAbstractHeaderMapper.PrefixBasedMatcherA prefix-basedAbstractHeaderMapper.HeaderMatcherthat matches if the specified header starts with a configurable prefix.protected static classAbstractHeaderMapper.SinglePatternBasedHeaderMatcherA pattern-basedAbstractHeaderMapper.HeaderMatcherthat matches if the specified header matches the specified simple pattern. -
Field Summary
Fields Modifier and Type Field Description protected org.apache.commons.logging.Logloggerstatic java.lang.StringNON_STANDARD_HEADER_NAME_PATTERNA special pattern that matches any header that is not a standard header (i.e.static java.lang.StringSTANDARD_REPLY_HEADER_NAME_PATTERNA special pattern that only matches standard reply headers.static java.lang.StringSTANDARD_REQUEST_HEADER_NAME_PATTERNA special pattern that only matches standard request headers. -
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractHeaderMapper(java.lang.String standardHeaderPrefix, java.util.Collection<java.lang.String> requestHeaderNames, java.util.Collection<java.lang.String> replyHeaderNames)Create a new instance. -
Method Summary
Modifier and Type Method Description protected AbstractHeaderMapper.HeaderMatchercreateDefaultHeaderMatcher(java.lang.String standardHeaderPrefix, java.util.Collection<java.lang.String> headerNames)Create the initialAbstractHeaderMapper.HeaderMatcherbased on the specified headers and standard header prefix.protected AbstractHeaderMapper.HeaderMatchercreateHeaderMatcher(java.util.Collection<java.lang.String> patterns)Create aAbstractHeaderMapper.HeaderMatcherthat match if any of the specifiedpatternsmatch.protected java.lang.StringcreateTargetPropertyName(java.lang.String propertyName, boolean fromMessageHeaders)Alter the specifiedpropertyNameif necessary.protected abstract java.util.Map<java.lang.String,java.lang.Object>extractStandardHeaders(T source)Extract the standard headers from the specified source.protected abstract java.util.Map<java.lang.String,java.lang.Object>extractUserDefinedHeaders(T source)Extract the user-defined headers from the specified source.voidfromHeadersToReply(org.springframework.messaging.MessageHeaders headers, T target)Map from the givenMessageHeadersto the specified reply target.voidfromHeadersToRequest(org.springframework.messaging.MessageHeaders headers, T target)Map from the givenMessageHeadersto the specified request target.protected java.lang.ClassLoadergetClassLoader()protected <V> VgetHeaderIfAvailable(java.util.Map<java.lang.String,java.lang.Object> headers, java.lang.String name, java.lang.Class<V> type)protected java.util.Collection<java.lang.String>getTransientHeaderNames()Return the transient header names.protected voidpopulateStandardHeaders(java.util.Map<java.lang.String,java.lang.Object> allHeaders, java.util.Map<java.lang.String,java.lang.Object> subset, T target)Populate the specified standard headers to the specified source.protected abstract voidpopulateStandardHeaders(java.util.Map<java.lang.String,java.lang.Object> headers, T target)Populate the specified standard headers to the specified source.protected abstract voidpopulateUserDefinedHeader(java.lang.String headerName, java.lang.Object headerValue, T target)Populate the specified user-defined headers to the specified source.voidsetBeanClassLoader(java.lang.ClassLoader classLoader)voidsetReplyHeaderNames(java.lang.String... replyHeaderNames)Provide the header names that should be mapped to a response from aMessageHeaders.voidsetRequestHeaderNames(java.lang.String... requestHeaderNames)Provide the header names that should be mapped from a request to aMessageHeaders.java.util.Map<java.lang.String,java.lang.Object>toHeadersFromReply(T source)Map from the given reply object to abstractedMessageHeaders.java.util.Map<java.lang.String,java.lang.Object>toHeadersFromRequest(T source)Map from the given request object to abstractedMessageHeaders.
-
Field Details
-
STANDARD_REQUEST_HEADER_NAME_PATTERN
public static final java.lang.String STANDARD_REQUEST_HEADER_NAME_PATTERNA special pattern that only matches standard request headers.- See Also:
- Constant Field Values
-
STANDARD_REPLY_HEADER_NAME_PATTERN
public static final java.lang.String STANDARD_REPLY_HEADER_NAME_PATTERNA special pattern that only matches standard reply headers.- See Also:
- Constant Field Values
-
NON_STANDARD_HEADER_NAME_PATTERN
public static final java.lang.String NON_STANDARD_HEADER_NAME_PATTERNA 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
protected final org.apache.commons.logging.Log logger
-
-
Constructor Details
-
AbstractHeaderMapper
protected AbstractHeaderMapper(java.lang.String standardHeaderPrefix, java.util.Collection<java.lang.String> requestHeaderNames, java.util.Collection<java.lang.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 toMessageHeadersreplyHeaderNames- the header names that should be mapped to a response fromMessageHeaders
-
-
Method Details
-
setBeanClassLoader
public void setBeanClassLoader(java.lang.ClassLoader classLoader)- Specified by:
setBeanClassLoaderin interfaceorg.springframework.beans.factory.BeanClassLoaderAware
-
getClassLoader
protected java.lang.ClassLoader getClassLoader() -
setRequestHeaderNames
public void setRequestHeaderNames(java.lang.String... requestHeaderNames)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
public void setReplyHeaderNames(java.lang.String... replyHeaderNames)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(java.lang.String standardHeaderPrefix, java.util.Collection<java.lang.String> headerNames)Create the initialAbstractHeaderMapper.HeaderMatcherbased 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.HeaderMatcherinstance.
-
createHeaderMatcher
protected AbstractHeaderMapper.HeaderMatcher createHeaderMatcher(java.util.Collection<java.lang.String> patterns)Create aAbstractHeaderMapper.HeaderMatcherthat match if any of the specifiedpatternsmatch. 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_PATTERNandNON_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:RequestReplyHeaderMapperMap from the givenMessageHeadersto the specified request target.- Specified by:
fromHeadersToRequestin interfaceRequestReplyHeaderMapper<T>- Parameters:
headers- the abstracted MessageHeaderstarget- the native target request
-
fromHeadersToReply
Description copied from interface:RequestReplyHeaderMapperMap from the givenMessageHeadersto the specified reply target.- Specified by:
fromHeadersToReplyin interfaceRequestReplyHeaderMapper<T>- Parameters:
headers- the abstracted MessageHeaderstarget- the native target reply
-
toHeadersFromRequest
Description copied from interface:RequestReplyHeaderMapperMap from the given request object to abstractedMessageHeaders.- Specified by:
toHeadersFromRequestin interfaceRequestReplyHeaderMapper<T>- Parameters:
source- the native target request- Returns:
- the abstracted MessageHeaders
-
toHeadersFromReply
Description copied from interface:RequestReplyHeaderMapperMap from the given reply object to abstractedMessageHeaders.- Specified by:
toHeadersFromReplyin interfaceRequestReplyHeaderMapper<T>- Parameters:
source- the native target reply- Returns:
- the abstracted MessageHeaders
-
getHeaderIfAvailable
@Nullable protected <V> V getHeaderIfAvailable(java.util.Map<java.lang.String,java.lang.Object> headers, java.lang.String name, java.lang.Class<V> type) -
createTargetPropertyName
protected java.lang.String createTargetPropertyName(java.lang.String propertyName, boolean fromMessageHeaders)Alter the specifiedpropertyNameif necessary. By default, the originalpropertyNameis returned.- Parameters:
propertyName- the original name of the property.fromMessageHeaders- specify if the property originates from aMessageHeadersinstance (true) or from the type managed by this mapper (false).- Returns:
- the property name for mapping.
-
getTransientHeaderNames
protected java.util.Collection<java.lang.String> getTransientHeaderNames()Return the transient header names. Transient headers are never mapped.- Returns:
- the names of headers to be skipped from mapping.
-
extractStandardHeaders
protected abstract java.util.Map<java.lang.String,java.lang.Object> extractStandardHeaders(T source)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
protected abstract java.util.Map<java.lang.String,java.lang.Object> extractUserDefinedHeaders(T source)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
protected abstract void populateStandardHeaders(java.util.Map<java.lang.String,java.lang.Object> headers, T target)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 java.util.Map<java.lang.String,java.lang.Object> allHeaders, java.util.Map<java.lang.String,java.lang.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
protected abstract void populateUserDefinedHeader(java.lang.String headerName, java.lang.Object headerValue, T target)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.
-