public class TcpMessageMapper extends Object implements InboundMessageMapper<TcpConnection>, OutboundMessageMapper<Object>, BeanFactoryAware
TcpConnection
to a Message
.
If StringToBytes is true (default),
payloads of type String are converted to a byte[] using the supplied
charset (UTF-8 by default).
Inbound messages include headers representing the remote end of the
connection as well as a connection id that can be used by a TcpSender
to correlate which connection to send a reply. If applySequence is set, adds
standard correlationId/sequenceNumber headers allowing for downstream (unbounded)
resequencing.
*Constructor and Description |
---|
TcpMessageMapper() |
Modifier and Type | Method and Description |
---|---|
protected void |
addCustomHeaders(TcpConnection connection,
MessageHeaders messageHeaders) |
protected void |
addStandardHeaders(TcpConnection connection,
MessageHeaders messageHeaders) |
Object |
fromMessage(Message<?> message) |
protected MessageBuilderFactory |
getMessageBuilderFactory() |
void |
setAddContentTypeHeader(boolean addContentTypeHeader)
Set to true to add a content type header; default false.
|
void |
setApplySequence(boolean applySequence) |
void |
setBeanFactory(BeanFactory beanFactory) |
void |
setBytesMessageMapper(BytesMessageMapper bytesMessageMapper)
Set a
BytesMessageMapper to use when mapping byte[]. |
void |
setCharset(String charset)
Set the charset to use when converting outbound String messages to
byte[] . |
void |
setContentType(String contentType)
Set the content type header value to add to inbound messages when
addContentTypeHeader is true. |
void |
setStringToBytes(boolean stringToBytes)
Sets whether outbound String payloads are to be converted
to byte[].
|
protected Map<String,?> |
supplyCustomHeaders(TcpConnection connection)
Override to provide additional headers.
|
Message<?> |
toMessage(TcpConnection connection,
Map<String,Object> headers)
Convert a provided object to the
Message
and supply with headers if necessary and provided. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
toMessage
protected final Log logger
public void setCharset(String charset)
byte[]
.charset
- the charset to setpublic void setStringToBytes(boolean stringToBytes)
BytesMessageMapper
is provided.stringToBytes
- The stringToBytes to set.setBytesMessageMapper(BytesMessageMapper)
public void setApplySequence(boolean applySequence)
applySequence
- The applySequence to set.public void setContentType(String contentType)
addContentTypeHeader
is true.
Default application/octet-stream;charset=UTF-8
. This default is not
modified by setCharset(String)
.contentType
- the content type header value to set.setAddContentTypeHeader(boolean)
,
setCharset(String)
public void setAddContentTypeHeader(boolean addContentTypeHeader)
addContentTypeHeader
- true to add a content type header.setContentType(String)
public void setBeanFactory(BeanFactory beanFactory) throws BeansException
setBeanFactory
in interface BeanFactoryAware
BeansException
public void setBytesMessageMapper(BytesMessageMapper bytesMessageMapper)
BytesMessageMapper
to use when mapping byte[].
setStringToBytes(boolean)
is ignored when a BytesMessageMapper
is provided.bytesMessageMapper
- the mapper.setStringToBytes(boolean)
protected MessageBuilderFactory getMessageBuilderFactory()
public Message<?> toMessage(TcpConnection connection, @Nullable Map<String,Object> headers)
InboundMessageMapper
Message
and supply with headers if necessary and provided.toMessage
in interface InboundMessageMapper<TcpConnection>
connection
- the object for message payload or some other conversion logicheaders
- additional headers for building message. Can be nullprotected final void addStandardHeaders(TcpConnection connection, MessageHeaders messageHeaders)
protected final void addCustomHeaders(TcpConnection connection, MessageHeaders messageHeaders)
@Nullable protected Map<String,?> supplyCustomHeaders(TcpConnection connection)
connection
- the connection.<String, ?>
headers to be added to the message.public Object fromMessage(Message<?> message)
fromMessage
in interface OutboundMessageMapper<Object>