The JMS message body

This topic contains information about the encoding of the message body itself. The encoding depends on the type of JMS message.

    ObjectMessage
    An ObjectMessage is an object serialized by the Java Runtime in the normal way.

    TextMessage
    A TextMessage is an encoded string. For an outgoing message, the string is encoded in the character set given by the destination object. This defaults to UTF8 encoding (the UTF8 encoding starts with the first character of the message; there is no length field at the start). It is, however, possible to specify any other character set supported by IBM MQ classes for JMS. Such character sets are used mainly when you send a message to a non-JMS application.

    If the character set is a double-byte set (including UTF16), the destination object's integer encoding specification determines the order of the bytes.

    An incoming message is interpreted using the character set and encoding that are specified in the message itself. These specifications are in the last IBM MQ header (or MQMD if there are no headers). For JMS messages, the last header is usually the MQRFH2.

    BytesMessage
    A BytesMessage is, by default, a sequence of bytes as defined by the JMS 1.0.2 specification and associated Java documentation.

    For an outgoing message that was assembled by the application itself, the destination object's encoding property can be used to override the encodings of integer and floating point fields contained in the message. For example, we can request that floating point values are stored in S/390 rather than IEEE format).

    An incoming message is interpreted using the numeric encoding specified in the message itself. This specification is in the last IBM MQ header (or MQMD if there are no headers). For JMS messages, the last header is usually the MQRFH2.

    If a BytesMessage is received, and is re-sent without modification, its body is transmitted byte for byte, as it was received. The destination object's encoding property has no effect on the body. The only string-like entity that can be sent explicitly in a BytesMessage is a UTF8 string. This is encoded in Java UTF8 format, and starts with a 2-byte length field. The destination object's character set property has no effect on the encoding of an outgoing BytesMessage. The character set value in an incoming IBM MQ message has no effect on the interpretation of that message as a JMS BytesMessage.

    Non-Java applications are unlikely to recognize the Java UTF8 encoding. Therefore, for a JMS application to send a BytesMessage that contains text data, the application itself must convert its strings to byte arrays, and write these byte arrays into the BytesMessage.

    MapMessage
    A MapMessage is a string containing XML name/type/value triplets encoded as:
    <map>
      <elt name="elementname1" dt="datatype1">value1</elt>
      <elt name="elementname2" dt="datatype2">value2</elt>
      ...
    </map>
    
    where datatype is one of the data types listed in Table 6. The default data type is string, and so the attribute dt=string is omitted for string elements.

    The character set used to encode or interpret the XML string that forms the body of a map message is determined according to the rules that apply to a text message.

    Versions of IBM MQ classes for JMS earlier than Version 5.3 encoded the body of a map message in the following format:
    <map>
      <elementname1 dt="datatype1">value1</elementname1>
      <elementname2 dt="datatype2">value2</elementname2>
      ...
    </map>
    

    Version 5.3 and later versions of IBM MQ classes for JMS can interpret either format, but versions of IBM MQ classes for JMS earlier than Version 5.3 cannot interpret the current format.

    If an application needs to send map messages to another application that is using a version of IBM MQ classes for JMS earlier than Version 5.3, the sending application must call the connection factory method setMapNameStyle(WMQConstants.WMQ_MAP_NAME_STYLE_COMPATIBLE) to specify that the map messages are sent in the previous format. By default, all map messages are sent in the current format.

    StreamMessage
    A StreamMessage is like a map message, but without element names:
    <stream>
      <elt dt="datatype1">value1</elt>
      <elt dt="datatype2">value2</elt>
      ...
    </stream>
    
    where datatype is one of the data types listed in Table 6. The default data type is string, and so the attribute dt=string is omitted for string elements.

    The character set used to encode or interpret the XML string that makes up the StreamMessage body is determined following the rules that apply to a TextMessage.

The MQRFH2.format field is set as follows:

    MQFMT_NONE
    for ObjectMessage, BytesMessage, or messages with no body.

    MQFMT_STRING
    for TextMessage, StreamMessage, or MapMessage.

Parent topic: Mapping JMS messages onto IBM MQ messages