The Message object provides read-write access to messages in the Rhapsody engine.

For details on parsing EDI messages, refer to Parsing EDI Messages.

Properties

Property

Description

text

Read-write property. Gets or sets the body of the message as a string using the default system encoding. However, when the message body is in XML format, it is encoded using UTF8.

body

Read-write property. Gets or sets the body of the message as a byte array.

connectionId

Read-write property. Gets or sets the connection identifier as an integer.

bodyEncoding

Read-write property. Gets or sets the body encoding as a string. When writing, the message body is reset to the default system encoding if null.

xml

Read-write property. Gets or sets the message body as an E4X XML object. When writing, the message body is encoded using UTF-8.

Methods

In addition to the methods defined in ROMessage object, the following methods are also available:

Method

Description

setText(string body, string encoding)

Sets the body of the message using the string provided. It will be encoded using the specified Java character encoding.

Refer to Supported Encodings for a list of Java supported encoding sets.

setField(string field, object value)

Sets the value of the field in the message to the specified value. The message must be parsable using one of the message definitions associated with the route.

If the message is in XML format and the field being set does not exist in the input message, then the new element will be appended to the end of the child elements of the parent element, ignoring the order defined in the XSD message definition. To ensure that the new element is always inserted in the right place according to the XSD message definition, set nodeInsertionMode to XMLORDERING.

addError(string error)

Adds an error message to the message. This will cause the message to go to the error connector.

setProperty(string propertyName, string value)

Sets the message property with the given name to the given value. If a property with that name already exists then its value is replaced with the new value. If no property with that name exists, then one is created with the given name and value. If the value passed in is null, then the property is removed.

The setProperty() method treats integer values as the numeric type int, and all other numerical values as double, but drops any trailing zeros after the decimal point. For example:

  • next.setProperty("prop", 1) sets the property prop to the int value 1 (as opposed to the double value 1.0 as in versions of Rhapsody before Rhapsody 6.2.2).
  • next.setProperty("prop", 1.11) sets the property prop to the double value 1.11.
  • next.setProperty("prop", 1.1100) sets the property prop to the double value 1.11. However, next.setProperty("prop", 1.00) sets the property prop to the int value 1.

To preserve trailing zeros after the decimal point in a numerical value, specify the value as a string, for example: next.setProperty("prop", "1.0").

addPropertyValue(string propertyName, string value)

Adds the given value to the message property with the given name. If no property with that name exists, then one is created with the given name and value.

When using the addPropertyValue() method to create an array of strings, property lists are serialized using square brackets around the values. This is required to ensure that the deserialization works correctly. Without the square brackets, it is not possible to split the values correctly.

Single property values do not have square brackets. If you know that you are only setting a single value in a property, you should use the setProperty() method. As this does not deal with a property list, it doesn't put square brackets around it.

indexProperty(string propertyName)

Indexes a property for output (deprecated).

indexOutputProperty(string propertyName)

Indexes a property for output.

indexInputProperty(string propertyName)

Indexes a property for input.

removeIndexingForProperty(string propertyName)

Removes all indexing for the specified property.

setBody(byte[] body[, string encoding])

Sets the message body to the body specified (as an array of bytes). The encoding parameter is optional.

Refer to Supported Encodings for a list of Java supported encoding sets.

getWritableEdiMessage()

Gets the internal Symphonia MessageElement for writing if this is an EDI message. Retrieves the root com.orion.symphonia3.MessageElement object representing the entire parsed message. The Symphonia API can then be used to browse and modify the message.

Refer to Parsing EDI Messages for details.

clearLastUsedDefinition()

Clears the definition associated with the message. The method does not re-parse an already parsed message.

Examples

The object returned from the MessageCollection append() method, a mutable copy of the original message that is now a member of the output MessageCollection, is a Message instance. Examples of how its properties and methods can be used in a JavaScript filter are shown below.

The following example demonstrates how the entire message body can be altered using the text property. The text "\r\nPlus some new stuff." is appended to the end of the message body; the previously existing text in the message body is not changed:

for (var i = 0; i < input.length; i++) {
    var next = output.append(input[i]);

    // Set the message body
    next.text = input[i].text + "\r\nPlus some new stuff.";
}

In the following example, the message is changed by setting the value of a field. This requires a message definition with a NK1 message segment containing an ApplicationAcknowledgement field to be associated with the route through which this message is passing. In this example the value of the field is changed to X .

for (var i = 0; i < input.length; i++) {
    var next = output.append(input[i]);

    // Set a field of the message
    next.setField("NK1/ApplicationAcknowledgement","X");
}

The following example sets a property on the message. The property PropertyName has the value PropertyValue set. If the message has no PropertyName property, one is created.

for (var i = 0; i < input.length; i++) {
    var next = output.append(input[i]);

    // Set a property on the message
    next.setProperty("PropertyName","PropertyValue");
}

The following example demonstrates how the message body can be accessed as an array of bytes, and how to iterate through each byte. This example increments each character's ASCII code by one, so A message. would become B!nfttbhf/.

for (var i = 0; i < input.length; i++){
    var next = output.append(input[i]);

    // Get the old body as an array of bytes
    var oldBody = input[i].getBody();

    // Get the new body found by incrementing each char
    var newBody = "";
    for (var i = 0; i < oldBody.length; i++) {
        newBody += String.fromCharCode(oldBody[i] + 1);
    }

    // Set the new body
    next.text = newBody;
}

The following example populates the MyPropList property list with the values qwerty, asdf, fred using the addPropertyValue method, then retrieves the properties using the getPropertyAsList() method and adds the properties to a message using the setProperty method.

// Create the message
var next = output.append(input[0]);

// Add properties to a message
next.addPropertyValue("MyPropList", "qwerty");
next.addPropertyValue("MyPropList", "asdf");
next.addPropertyValue("MyPropList", "fred");

// Retrieve all the properties from the list
var props = next.getPropertyAsList("MyPropList");

// Add these properties individually to the message
for (var i = 0; i < props.size(); ++i) {
    var propName = "Prop" + i;
    next.setProperty(propName, props.get(i));
}