Class DefaultPahoMessageConverter

java.lang.Object
org.springframework.integration.mqtt.support.DefaultPahoMessageConverter
All Implemented Interfaces:
org.springframework.beans.factory.Aware, org.springframework.beans.factory.BeanFactoryAware, MqttMessageConverter, org.springframework.messaging.converter.MessageConverter

public class DefaultPahoMessageConverter
extends java.lang.Object
implements MqttMessageConverter, org.springframework.beans.factory.BeanFactoryAware
Default implementation for mapping to/from Messages.
Since:
4.0
  • Constructor Summary

    Constructors 
    Constructor Description
    DefaultPahoMessageConverter()
    Construct a converter with default options (qos=0, retain=false, charset=UTF-8).
    DefaultPahoMessageConverter​(int defaultQos, boolean defaultRetained)
    Construct a converter to create outbound messages with the supplied default qos and retain settings and a UTF-8 charset for converting outbound String payloads to byte[] and inbound byte[] to String (unless payloadAdBytes is true).
    DefaultPahoMessageConverter​(int defaultQos, boolean defaultRetained, java.lang.String charset)
    Construct a converter to create outbound messages with the supplied default qos and retain settings and the supplied charset.
    DefaultPahoMessageConverter​(int defaultQos, org.springframework.integration.handler.MessageProcessor<java.lang.Integer> qosProcessor, boolean defaultRetained, org.springframework.integration.handler.MessageProcessor<java.lang.Boolean> retainedProcessor)
    Construct a converter to create outbound messages with the supplied default qos and retained message processors and a UTF-8 charset for converting outbound String payloads to byte[] and inbound byte[] to String (unless payloadAdBytes is true).
    DefaultPahoMessageConverter​(int defaultQos, org.springframework.integration.handler.MessageProcessor<java.lang.Integer> qosProcessor, boolean defaultRetained, org.springframework.integration.handler.MessageProcessor<java.lang.Boolean> retainedProcessor, java.lang.String charset)
    Construct a converter to create outbound messages with the supplied default qos and retain settings and the supplied charset.
    DefaultPahoMessageConverter​(java.lang.String charset)
    Construct a converter with default options (qos=0, retain=false) and the supplied charset.
  • Method Summary

    Modifier and Type Method Description
    org.eclipse.paho.client.mqttv3.MqttMessage fromMessage​(org.springframework.messaging.Message<?> message, java.lang.Class<?> targetClass)  
    protected org.springframework.beans.factory.BeanFactory getBeanFactory()  
    protected org.springframework.integration.support.MessageBuilderFactory getMessageBuilderFactory()  
    boolean isPayloadAsBytes()  
    protected byte[] messageToMqttBytes​(org.springframework.messaging.Message<?> message)
    Subclasses can override this method to convert the payload to a byte[].
    protected java.lang.Object mqttBytesToPayload​(org.eclipse.paho.client.mqttv3.MqttMessage mqttMessage)
    Subclasses can override this method to convert the byte[] to a payload.
    void setBeanFactory​(org.springframework.beans.factory.BeanFactory beanFactory)  
    void setBytesMessageMapper​(org.springframework.integration.mapping.BytesMessageMapper bytesMessageMapper)
    Set a BytesMessageMapper to use when mapping byte[].
    void setPayloadAsBytes​(boolean payloadAsBytes)
    True if the converter should not convert the message payload to a String.
    org.springframework.messaging.Message<?> toMessage​(java.lang.Object mqttMessage, org.springframework.messaging.MessageHeaders headers)  
    org.springframework.integration.support.AbstractIntegrationMessageBuilder<?> toMessageBuilder​(java.lang.String topic, org.eclipse.paho.client.mqttv3.MqttMessage mqttMessage)
    Convert to a message builder.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface org.springframework.integration.mqtt.support.MqttMessageConverter

    toMessage
  • Constructor Details

    • DefaultPahoMessageConverter

      public DefaultPahoMessageConverter()
      Construct a converter with default options (qos=0, retain=false, charset=UTF-8).
    • DefaultPahoMessageConverter

      public DefaultPahoMessageConverter​(int defaultQos, boolean defaultRetained)
      Construct a converter to create outbound messages with the supplied default qos and retain settings and a UTF-8 charset for converting outbound String payloads to byte[] and inbound byte[] to String (unless payloadAdBytes is true).
      Parameters:
      defaultQos - the default qos.
      defaultRetained - the default retained.
    • DefaultPahoMessageConverter

      public DefaultPahoMessageConverter​(java.lang.String charset)
      Construct a converter with default options (qos=0, retain=false) and the supplied charset.
      Parameters:
      charset - the charset used to convert outbound String payloads to byte[] and inbound byte[] to String (unless payloadAdBytes is true).
      Since:
      4.1.2
    • DefaultPahoMessageConverter

      public DefaultPahoMessageConverter​(int defaultQos, boolean defaultRetained, java.lang.String charset)
      Construct a converter to create outbound messages with the supplied default qos and retain settings and the supplied charset.
      Parameters:
      defaultQos - the default qos.
      defaultRetained - the default retained.
      charset - the charset used to convert outbound String payloads to byte[] and inbound byte[] to String (unless payloadAdBytes is true).
    • DefaultPahoMessageConverter

      public DefaultPahoMessageConverter​(int defaultQos, org.springframework.integration.handler.MessageProcessor<java.lang.Integer> qosProcessor, boolean defaultRetained, org.springframework.integration.handler.MessageProcessor<java.lang.Boolean> retainedProcessor)
      Construct a converter to create outbound messages with the supplied default qos and retained message processors and a UTF-8 charset for converting outbound String payloads to byte[] and inbound byte[] to String (unless payloadAdBytes is true).
      Parameters:
      defaultQos - the default qos.
      qosProcessor - a message processor to determine the qos.
      defaultRetained - the default retained.
      retainedProcessor - a message processor to determine the retained flag.
      Since:
      5.0
    • DefaultPahoMessageConverter

      public DefaultPahoMessageConverter​(int defaultQos, org.springframework.integration.handler.MessageProcessor<java.lang.Integer> qosProcessor, boolean defaultRetained, org.springframework.integration.handler.MessageProcessor<java.lang.Boolean> retainedProcessor, java.lang.String charset)
      Construct a converter to create outbound messages with the supplied default qos and retain settings and the supplied charset.
      Parameters:
      defaultQos - the default qos.
      qosProcessor - a message processor to determine the qos.
      defaultRetained - the default retained.
      retainedProcessor - a message processor to determine the retained flag.
      charset - the charset used to convert outbound String payloads to byte[] and inbound byte[] to String (unless payloadAdBytes is true).
      Since:
      5.0
  • Method Details

    • setBeanFactory

      public final void setBeanFactory​(org.springframework.beans.factory.BeanFactory beanFactory)
      Specified by:
      setBeanFactory in interface org.springframework.beans.factory.BeanFactoryAware
    • getBeanFactory

      protected org.springframework.beans.factory.BeanFactory getBeanFactory()
    • getMessageBuilderFactory

      protected org.springframework.integration.support.MessageBuilderFactory getMessageBuilderFactory()
    • setPayloadAsBytes

      public void setPayloadAsBytes​(boolean payloadAsBytes)
      True if the converter should not convert the message payload to a String. Ignored if a BytesMessageMapper is provided.
      Parameters:
      payloadAsBytes - The payloadAsBytes to set.
      See Also:
      setBytesMessageMapper(BytesMessageMapper)
    • isPayloadAsBytes

      public boolean isPayloadAsBytes()
    • setBytesMessageMapper

      public void setBytesMessageMapper​(org.springframework.integration.mapping.BytesMessageMapper bytesMessageMapper)
      Set a BytesMessageMapper to use when mapping byte[]. setPayloadAsBytes(boolean) is ignored when a BytesMessageMapper is provided.
      Parameters:
      bytesMessageMapper - the mapper.
      Since:
      5.0
      See Also:
      setPayloadAsBytes(boolean)
    • toMessage

      public org.springframework.messaging.Message<?> toMessage​(java.lang.Object mqttMessage, org.springframework.messaging.MessageHeaders headers)
      Specified by:
      toMessage in interface org.springframework.messaging.converter.MessageConverter
    • toMessageBuilder

      public org.springframework.integration.support.AbstractIntegrationMessageBuilder<?> toMessageBuilder​(java.lang.String topic, org.eclipse.paho.client.mqttv3.MqttMessage mqttMessage)
      Description copied from interface: MqttMessageConverter
      Convert to a message builder.
      Specified by:
      toMessageBuilder in interface MqttMessageConverter
      Parameters:
      topic - the topic.
      mqttMessage - the MQTT message.
      Returns:
      the builder.
    • fromMessage

      public org.eclipse.paho.client.mqttv3.MqttMessage fromMessage​(org.springframework.messaging.Message<?> message, java.lang.Class<?> targetClass)
      Specified by:
      fromMessage in interface org.springframework.messaging.converter.MessageConverter
    • mqttBytesToPayload

      protected java.lang.Object mqttBytesToPayload​(org.eclipse.paho.client.mqttv3.MqttMessage mqttMessage)
      Subclasses can override this method to convert the byte[] to a payload. The default implementation creates a String (default) or byte[].
      Parameters:
      mqttMessage - The inbound message.
      Returns:
      The payload for the Spring integration message
    • messageToMqttBytes

      protected byte[] messageToMqttBytes​(org.springframework.messaging.Message<?> message)
      Subclasses can override this method to convert the payload to a byte[]. The default implementation accepts a byte[] or String payload. If a BytesMessageMapper is provided, conversion to byte[] is delegated to it, so any payload that it can handle is supported.
      Parameters:
      message - The outbound Message.
      Returns:
      The byte[] which will become the payload of the MQTT Message.