Class TcpMessageMapper
java.lang.Object
org.springframework.integration.ip.tcp.connection.TcpMessageMapper
- All Implemented Interfaces:
- Aware,- BeanFactoryAware,- InboundMessageMapper<TcpConnection>,- OutboundMessageMapper<Object>
- Direct Known Subclasses:
- MessageConvertingTcpMessageMapper
public class TcpMessageMapper
extends Object
implements InboundMessageMapper<TcpConnection>, OutboundMessageMapper<Object>, BeanFactoryAware
Maps incoming data from a 
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.
 *- Since:
- 2.0
- Author:
- Gary Russell, Artem Bilan
- 
Field SummaryFields
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionprotected final voidaddCustomHeaders(TcpConnection connection, MessageHeaders messageHeaders) protected final voidaddStandardHeaders(TcpConnection connection, MessageHeaders messageHeaders) fromMessage(Message<?> message) protected MessageBuilderFactoryvoidsetAddContentTypeHeader(boolean addContentTypeHeader) Set to true to add a content type header; default false.voidsetApplySequence(boolean applySequence) voidsetBeanFactory(BeanFactory beanFactory) voidsetBytesMessageMapper(BytesMessageMapper bytesMessageMapper) Set aBytesMessageMapperto use when mapping byte[].voidsetCharset(String charset) Set the charset to use when converting outbound String messages tobyte[].voidsetContentType(String contentType) Set the content type header value to add to inbound messages whenaddContentTypeHeaderis true.voidsetStringToBytes(boolean stringToBytes) Sets whether outbound String payloads are to be converted to byte[].supplyCustomHeaders(TcpConnection connection) Override to provide additional headers.Message<?> toMessage(TcpConnection connection, Map<String, Object> headers) Convert a provided object to theMessageand supply with headers if necessary and provided.Methods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.integration.mapping.InboundMessageMappertoMessage
- 
Field Details- 
logger
 
- 
- 
Constructor Details- 
TcpMessageMapperpublic TcpMessageMapper()
 
- 
- 
Method Details- 
setCharsetSet the charset to use when converting outbound String messages tobyte[].- Parameters:
- charset- the charset to set
 
- 
setStringToBytespublic void setStringToBytes(boolean stringToBytes) Sets whether outbound String payloads are to be converted to byte[]. Default is true. Ignored if aBytesMessageMapperis provided.- Parameters:
- stringToBytes- The stringToBytes to set.
- See Also:
 
- 
setApplySequencepublic void setApplySequence(boolean applySequence) - Parameters:
- applySequence- The applySequence to set.
 
- 
setContentTypeSet the content type header value to add to inbound messages whenaddContentTypeHeaderis true. Defaultapplication/octet-stream;charset=UTF-8. This default is not modified bysetCharset(String).- Parameters:
- contentType- the content type header value to set.
- Since:
- 4.3
- See Also:
 
- 
setAddContentTypeHeaderpublic void setAddContentTypeHeader(boolean addContentTypeHeader) Set to true to add a content type header; default false.- Parameters:
- addContentTypeHeader- true to add a content type header.
- Since:
- 4.3
- See Also:
 
- 
setBeanFactory- Specified by:
- setBeanFactoryin interface- BeanFactoryAware
- Throws:
- BeansException
 
- 
setBytesMessageMapperSet aBytesMessageMapperto use when mapping byte[].setStringToBytes(boolean)is ignored when aBytesMessageMapperis provided.- Parameters:
- bytesMessageMapper- the mapper.
- Since:
- 5.0
- See Also:
 
- 
getMessageBuilderFactory
- 
toMessageDescription copied from interface:InboundMessageMapperConvert a provided object to theMessageand supply with headers if necessary and provided.- Specified by:
- toMessagein interface- InboundMessageMapper<TcpConnection>
- Parameters:
- connection- the object for message payload or some other conversion logic
- headers- additional headers for building message. Can be null
- Returns:
- the message as a result of mapping
 
- 
addStandardHeaders
- 
addCustomHeaders
- 
supplyCustomHeadersOverride to provide additional headers. The standard headers cannot be overridden and any such headers will be ignored if provided in the result.- Parameters:
- connection- the connection.
- Returns:
- A Map of <String, ?>headers to be added to the message.
 
- 
fromMessage- Specified by:
- fromMessagein interface- OutboundMessageMapper<Object>
 
 
-