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 |
---|---|
|
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. |
|
Read-write property. Gets or sets the body of the message as a byte array. |
|
Read-write property. Gets or sets the connection identifier as an integer. |
|
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. |
|
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 |
---|---|
|
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. |
|
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 |
|
Adds an error message to the message. This will cause the message to go to the error connector. |
|
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
To preserve trailing zeros after the decimal point in a numerical value, specify the value as a string, for example: |
|
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 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 |
|
Indexes a property for output (deprecated). |
|
Indexes a property for output. |
|
Indexes a property for input. |
|
Removes all indexing for the specified property. |
|
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. |
|
Gets the internal Symphonia Refer to Parsing EDI Messages for details. |
|
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)); }