source.toString¶
Use when: You want to read values from the original incoming message before any mapping changes. If you need the modified message during mapping, use message.toString.
All other message types¶
Signature: source.toString()
Returns: String sourceString - the message value as a string
Get the message value as a string.
Note
This method only applies to the following formatted messages: HL7, ASTM, CSV, DICOM, EDIFACT, Old Fxd Width, Fxd Length, ISO 8583, JSON, Text, X12, XML.
Parameters¶
None
Example¶
// Convert the source message to its string representation.
var sourceString = source.toString(); // expected: String representation of the message
Binary message types¶
Signature: source.toString()
Returns: String sourceString - the source message as a string
Get the entire source message as a string, decoded with the message type's encoding.
Note
Use this to hold a PDF, image, or other non-text payload in the channel or message cache, which store strings only, and rebuild the exact bytes later. This works only with a single-byte encoding such as ISO-8859-1; a plain text payload simply comes back as readable text.
Note
This returns the same result as source.getNode('/').
Parameters¶
None
Example¶
// Example 1: Hold the received PDF, image, or other non-text payload in a cache and rebuild the exact bytes later.
// A byte-for-byte string requires a single-byte character set, e.g. ISO-8859-1, which is the default encoding for a Binary message.
var originalBytesAsString = source.toString();
// The channel and message caches store strings only, so the payload has to travel as one.
messageCache.setValue('originalBytesAsString', originalBytesAsString);
// ...in a later node...
var cachedBytesAsString = messageCache.getValue('originalBytesAsString');
message.setBytes(new java.lang.String(cachedBytesAsString).getBytes('ISO-8859-1')); // the original received bytes, unchanged
// Example 2: Read a plain text byte array in a Binary channel.
// When the bytes really are text, the decoded string is human-readable
var textPayload = source.toString(); // e.g. "Some plain text here."
if (StringUtils.isBlank(textPayload)) {
qie.warn('The received payload is empty or only whitespace.');
}