Message body

 

This section discusses the encoding of the message body itself. The encoding depends on the type of JMS message:

ObjectMessage

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

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 WebSphere MQ Java. 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 WebSphere MQ header (or MQMD if there are no headers). For JMS messages, the last header is usually the MQRFH2.

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 rightmost WebSphere MQ header (or MQMD if there are no headers). For JMS messages, the rightmost 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 WebSphere 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

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 3. The default data type is string, and so the attribute dt="string" is omitted for string elements.

Previous versions of the WebSphere MQ JMS client encoded the body of a map message in the following format:

<map>
  <elementname1 dt="datatype1">value1</elementname1>
  <elementname2 dt="datatype2">value2</elementname2>
  ...
</map>

The current version and V5.3 of the WebSphere MQ JMS client can interpret either format, but versions of the WebSphere MQ JMS client earlier than V5.3 cannot interpret the current format. If an application must be able to receive map messages encoded in the current format, the application must use the current version or V5.3 of the WebSphere MQ JMS client.

If an application needs to send map messages to another application that is using a WebSphere MQ JMS client earlier than V5.3, the sending application must call the connection factory method setMapNameStyle(JMSC.MAP_NAME_STYLE_COMPATIBLE) to specify that the map messages are sent in the previous format, which can be interpreted by any WebSphere MQ JMS client. By default, all map messages are sent in the current format.

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.

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 3. 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.


uj25520_