Class AbstractKafkaHeaderMapper
- java.lang.Object
-
- org.springframework.kafka.support.AbstractKafkaHeaderMapper
-
- All Implemented Interfaces:
KafkaHeaderMapper
- Direct Known Subclasses:
DefaultKafkaHeaderMapper
,SimpleKafkaHeaderMapper
public abstract class AbstractKafkaHeaderMapper extends java.lang.Object implements KafkaHeaderMapper
Base for Kafka header mappers.- Since:
- 2.1.3
- Author:
- Gary Russell, Artem Bilan
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static interface
AbstractKafkaHeaderMapper.HeaderMatcher
A matcher for headers.protected static class
AbstractKafkaHeaderMapper.NeverMatchHeaderMatcher
A matcher that never matches a set of headers.protected static class
AbstractKafkaHeaderMapper.SimplePatternBasedHeaderMatcher
A pattern-based header matcher that matches if the specified header matches the specified simple pattern.
-
Field Summary
Fields Modifier and Type Field Description protected org.springframework.core.log.LogAccessor
logger
-
Constructor Summary
Constructors Constructor Description AbstractKafkaHeaderMapper(java.lang.String... patterns)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
addMatchers(AbstractKafkaHeaderMapper.HeaderMatcher... matchersToAdd)
Subclasses can invoke this to add customAbstractKafkaHeaderMapper.HeaderMatcher
s.void
addRawMappedHeader(java.lang.String name, boolean toString)
Add a raw mapped header.protected java.nio.charset.Charset
getCharset()
protected java.lang.Object
headerValueToAddIn(org.apache.kafka.common.header.Header header)
Check if the header value should be mapped to a String, if so configured.protected java.lang.Object
headerValueToAddOut(java.lang.String key, java.lang.Object value)
Check if the value is a String and convert to byte[], if so configured.protected boolean
matches(java.lang.String header)
protected boolean
matches(java.lang.String header, java.lang.Object value)
void
setCharset(java.nio.charset.Charset charset)
Set the charset to use when mapping String-valued headers to/from byte[].void
setMapAllStringsOut(boolean mapAllStringsOut)
Set to true to map allString
valued outbound headers tobyte[]
.void
setRawMappedHeaders(java.util.Map<java.lang.String,java.lang.Boolean> rawMappedHeaders)
Set the headers to not perform any conversion on (exceptString
tobyte[]
for outbound).-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.springframework.kafka.support.KafkaHeaderMapper
fromHeaders, toHeaders
-
-
-
-
Method Detail
-
addMatchers
protected final void addMatchers(AbstractKafkaHeaderMapper.HeaderMatcher... matchersToAdd)
Subclasses can invoke this to add customAbstractKafkaHeaderMapper.HeaderMatcher
s.- Parameters:
matchersToAdd
- the matchers to add.- Since:
- 2.3
-
setMapAllStringsOut
public void setMapAllStringsOut(boolean mapAllStringsOut)
Set to true to map allString
valued outbound headers tobyte[]
. To map to aString
for inbound, there must be an entry in the rawMappedHeaders map.- Parameters:
mapAllStringsOut
- true to map all strings.- Since:
- 2.2.5
- See Also:
setRawMappedHeaders(Map)
-
getCharset
protected java.nio.charset.Charset getCharset()
-
setCharset
public void setCharset(java.nio.charset.Charset charset)
Set the charset to use when mapping String-valued headers to/from byte[]. Default UTF-8.- Parameters:
charset
- the charset.- Since:
- 2.2.5
- See Also:
setRawMappedHeaders(Map)
-
setRawMappedHeaders
public void setRawMappedHeaders(java.util.Map<java.lang.String,java.lang.Boolean> rawMappedHeaders)
Set the headers to not perform any conversion on (exceptString
tobyte[]
for outbound). Inbound headers that match will be mapped asbyte[]
unless the corresponding boolean in the map value is true, in which case it will be mapped as a String.- Parameters:
rawMappedHeaders
- the header names to not convert and- Since:
- 2.2.5
- See Also:
setCharset(Charset)
,setMapAllStringsOut(boolean)
-
addRawMappedHeader
public void addRawMappedHeader(java.lang.String name, boolean toString)
Add a raw mapped header.- Parameters:
name
- the header name.toString
- convert to string on inbound when true.- Since:
- 2.7.1
- See Also:
setRawMappedHeaders(Map)
-
matches
protected boolean matches(java.lang.String header, java.lang.Object value)
-
matches
protected boolean matches(java.lang.String header)
-
headerValueToAddOut
protected java.lang.Object headerValueToAddOut(java.lang.String key, java.lang.Object value)
Check if the value is a String and convert to byte[], if so configured.- Parameters:
key
- the header name.value
- the header value.- Returns:
- the value to add.
- Since:
- 2.2.5
-
headerValueToAddIn
protected java.lang.Object headerValueToAddIn(org.apache.kafka.common.header.Header header)
Check if the header value should be mapped to a String, if so configured.- Parameters:
header
- the header.- Returns:
- the value to add.
-
-