public class TcpMessageMapper extends java.lang.Object implements InboundMessageMapper<TcpConnection>, OutboundMessageMapper<java.lang.Object>, org.springframework.beans.factory.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.
*| Modifier and Type | Field and Description |
|---|---|
protected org.apache.commons.logging.Log |
logger |
| Constructor and Description |
|---|
TcpMessageMapper() |
| Modifier and Type | Method and Description |
|---|---|
protected void |
addCustomHeaders(TcpConnection connection,
org.springframework.messaging.MessageHeaders messageHeaders) |
protected void |
addStandardHeaders(TcpConnection connection,
org.springframework.messaging.MessageHeaders messageHeaders) |
java.lang.Object |
fromMessage(org.springframework.messaging.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(org.springframework.beans.factory.BeanFactory beanFactory) |
void |
setBytesMessageMapper(BytesMessageMapper bytesMessageMapper)
Set a
BytesMessageMapper to use when mapping byte[]. |
void |
setCharset(java.lang.String charset)
Set the charset to use when converting outbound String messages to
byte[]. |
void |
setContentType(java.lang.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 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)
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, waittoMessagepublic void setCharset(java.lang.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(java.lang.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(org.springframework.beans.factory.BeanFactory beanFactory)
throws org.springframework.beans.BeansException
setBeanFactory in interface org.springframework.beans.factory.BeanFactoryAwareorg.springframework.beans.BeansExceptionpublic 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 org.springframework.messaging.Message<?> toMessage(TcpConnection connection, @Nullable java.util.Map<java.lang.String,java.lang.Object> headers) throws java.lang.Exception
InboundMessageMapperMessage
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 nulljava.lang.Exception - the exception thrown by the underlying mapper implementationprotected final void addStandardHeaders(TcpConnection connection, org.springframework.messaging.MessageHeaders messageHeaders)
protected final void addCustomHeaders(TcpConnection connection, org.springframework.messaging.MessageHeaders messageHeaders)
protected java.util.Map<java.lang.String,?> supplyCustomHeaders(TcpConnection connection)
connection - the connection.<String, ?> headers to be added to the message.public java.lang.Object fromMessage(org.springframework.messaging.Message<?> message)
throws java.lang.Exception
fromMessage in interface OutboundMessageMapper<java.lang.Object>java.lang.Exception