Class TcpMessageMapper
java.lang.Object
org.springframework.integration.ip.tcp.connection.TcpMessageMapper
- All Implemented Interfaces:
org.springframework.beans.factory.Aware,org.springframework.beans.factory.BeanFactoryAware,org.springframework.integration.mapping.InboundMessageMapper<TcpConnection>,org.springframework.integration.mapping.OutboundMessageMapper<java.lang.Object>
- Direct Known Subclasses:
MessageConvertingTcpMessageMapper
public class TcpMessageMapper extends java.lang.Object implements org.springframework.integration.mapping.InboundMessageMapper<TcpConnection>, org.springframework.integration.mapping.OutboundMessageMapper<java.lang.Object>, org.springframework.beans.factory.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
-
Field Summary
Fields Modifier and Type Field Description protected org.apache.commons.logging.Loglogger -
Constructor Summary
Constructors Constructor Description TcpMessageMapper() -
Method Summary
Modifier and Type Method Description protected voidaddCustomHeaders(TcpConnection connection, org.springframework.messaging.MessageHeaders messageHeaders)protected voidaddStandardHeaders(TcpConnection connection, org.springframework.messaging.MessageHeaders messageHeaders)java.lang.ObjectfromMessage(org.springframework.messaging.Message<?> message)protected org.springframework.integration.support.MessageBuilderFactorygetMessageBuilderFactory()voidsetAddContentTypeHeader(boolean addContentTypeHeader)Set to true to add a content type header; default false.voidsetApplySequence(boolean applySequence)voidsetBeanFactory(org.springframework.beans.factory.BeanFactory beanFactory)voidsetBytesMessageMapper(org.springframework.integration.mapping.BytesMessageMapper bytesMessageMapper)Set aBytesMessageMapperto use when mapping byte[].voidsetCharset(java.lang.String charset)Set the charset to use when converting outbound String messages tobyte[].voidsetContentType(java.lang.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[].protected java.util.Map<java.lang.String,?>supplyCustomHeaders(TcpConnection connection)Override to provide additional headers.org.springframework.messaging.Message<?>toMessage(TcpConnection connection, java.util.Map<java.lang.String,java.lang.Object> headers)
-
Field Details
-
logger
protected final org.apache.commons.logging.Log logger
-
-
Constructor Details
-
TcpMessageMapper
public TcpMessageMapper()
-
-
Method Details
-
setCharset
public void setCharset(java.lang.String charset)Set the charset to use when converting outbound String messages tobyte[].- Parameters:
charset- the charset to set
-
setStringToBytes
public 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:
setBytesMessageMapper(BytesMessageMapper)
-
setApplySequence
public void setApplySequence(boolean applySequence)- Parameters:
applySequence- The applySequence to set.
-
setContentType
public void setContentType(java.lang.String contentType)Set 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:
setAddContentTypeHeader(boolean),setCharset(String)
-
setAddContentTypeHeader
public 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:
setContentType(String)
-
setBeanFactory
public void setBeanFactory(org.springframework.beans.factory.BeanFactory beanFactory) throws org.springframework.beans.BeansException- Specified by:
setBeanFactoryin interfaceorg.springframework.beans.factory.BeanFactoryAware- Throws:
org.springframework.beans.BeansException
-
setBytesMessageMapper
public void setBytesMessageMapper(org.springframework.integration.mapping.BytesMessageMapper bytesMessageMapper)Set aBytesMessageMapperto use when mapping byte[].setStringToBytes(boolean)is ignored when aBytesMessageMapperis provided.- Parameters:
bytesMessageMapper- the mapper.- Since:
- 5.0
- See Also:
setStringToBytes(boolean)
-
getMessageBuilderFactory
protected org.springframework.integration.support.MessageBuilderFactory getMessageBuilderFactory() -
toMessage
public org.springframework.messaging.Message<?> toMessage(TcpConnection connection, @Nullable java.util.Map<java.lang.String,java.lang.Object> headers)- Specified by:
toMessagein interfaceorg.springframework.integration.mapping.InboundMessageMapper<TcpConnection>
-
addStandardHeaders
protected final void addStandardHeaders(TcpConnection connection, org.springframework.messaging.MessageHeaders messageHeaders) -
addCustomHeaders
protected final void addCustomHeaders(TcpConnection connection, org.springframework.messaging.MessageHeaders messageHeaders) -
supplyCustomHeaders
@Nullable protected java.util.Map<java.lang.String,?> supplyCustomHeaders(TcpConnection connection)Override 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
public java.lang.Object fromMessage(org.springframework.messaging.Message<?> message)- Specified by:
fromMessagein interfaceorg.springframework.integration.mapping.OutboundMessageMapper<java.lang.Object>
-