Skip to content

Source and Connector Map Variables ​

Each connector type automatically populates certain map variables with metadata about the connection and message. These variables are available in transformers, filters, and scripts.

Source connector map variables ​

TCP Listener ​

VariableDescription
remoteAddressIP address of the sending system
remotePortPort of the sending system
localAddressLocal IP address
localPortLocal listening port

HTTP Listener ​

VariableDescription
remoteAddressIP address of the HTTP client
remotePortPort of the HTTP client
localAddressLocal IP address
localPortLocal listening port
methodHTTP method (GET, POST, PUT, DELETE)
urlRequest URL from the scheme through the path, without the query string
uriRequest path with its query string, or the whole URI when the request line carries an absolute URI
protocolHTTP protocol version
queryQuery string
contextPathPath portion of the request URL
parametersMessageParameters object wrapping the query and form parameters. getParameter(name) returns the first value, getParameterList(name) every value, getKeys() the parameter names
headersMessageHeaders object wrapping the request headers, with header names matched case-insensitively. getHeader(name) returns the first value, getHeaderList(name) every value, getKeys() the header names

File Reader ​

VariableDescription
originalFilenameOriginal filename of the file being read
fileDirectoryDirectory the file was read from
fileSizeSize of the file in bytes
fileLastModifiedLast modified time of the file, in milliseconds since the epoch
pollIdID of the current poll cycle
pollSequenceIdSequence number within the current poll
pollCompletetrue on the last message in the poll cycle, absent on the others

Database Reader ​

No automatic source map variables.

Channel Reader ​

VariableDescription
sourceChannelIdChannel ID of the sending channel
sourceChannelIdsList of source channel IDs (when routed through multiple channels)
sourceMessageIdMessage ID from the sending channel
sourceMessageIdsList of source message IDs (when routed through multiple channels)

JMS Listener ​

No automatic source map variables.

DICOM Listener ​

VariableDescription
localApplicationEntityTitleLocal AE title
remoteApplicationEntityTitleRemote AE title
localAddressLocal IP address
localPortLocal listening port
remoteAddressIP address of the sending DICOM node
remotePortPort of the sending node
associateACProtocolVersionASSOCIATE-AC protocol version
associateACImplClassUIDASSOCIATE-AC implementation class UID
associateACImplVersionNameASSOCIATE-AC implementation version name
associateACApplicationContextASSOCIATE-AC application context
associateACPresentationContextsMap of ASSOCIATE-AC presentation contexts
associateRQProtocolVersionASSOCIATE-RQ protocol version
associateRQImplClassUIDASSOCIATE-RQ implementation class UID
associateRQImplVersionNameASSOCIATE-RQ implementation version name
associateRQApplicationContextASSOCIATE-RQ application context
associateRQPresentationContextsMap of ASSOCIATE-RQ presentation contexts
usernameUser identity username (if provided)
passcodeUser identity passcode (if provided)
userIdentityTypeUser identity type (if provided)

Web Service Listener ​

No automatic source map variables.

JavaScript Reader ​

No automatic variables. The script's return value becomes the message: a string, a RawMessage from com.mirth.connect.server.userutil, or a java.util.List of either. A RawMessage built with a source map carries it into the message; a string return has an empty source map. Returning undefined, null, or an empty string produces no message.

Destination connector map variables ​

A destination connector writes these into its own connectorMap while it sends, after the destination's filter and transformer have run. They are readable in the destination's response transformer. In the destination's filter or transformer they are still null.

HTTP Sender ​

VariableDescription
responseStatusLineHTTP response status line
responseStatusCodeHTTP response status code
responseHeadersMessageHeaders object wrapping the response headers, with the same methods and case-insensitive matching as the HTTP Listener headers entry

TCP Sender (Server mode) ​

VariableDescription
localAddressLocal IP address of the server socket
localPortLocal port of the server socket
numberOfClientsTotal number of connected clients
successfulSendsCount of successful message sends
allResponsesList of Response objects from each connected client

Accessing map variables ​

Every preprocessor, filter, transformer and response transformer script sees the maps as the scope variables sourceMap, channelMap, connectorMap and responseMap. They are Java Map objects: .get(key) reads a value and .put(key, value) writes one. The shorthand functions $s(key), $c(key), $co(key) and $r(key) call .get() on the same four maps, and with a second argument they call .put(). A key the connector did not populate returns null.

In a filter or transformer ​

This runs in a source or destination filter or transformer step on a channel whose source connector is a TCP Listener, which populates remoteAddress and remotePort. sourceMap and channelMap come from the script scope. Storing the value in the channel map keeps it with the message, where the Message Browser shows it.

javascript
var remoteAddress = sourceMap.get('remoteAddress');
var remotePort = sourceMap.get('remotePort');
channelMap.put('sender', remoteAddress + ':' + remotePort);

In a response transformer ​

The HTTP Sender writes responseStatusCode, responseStatusLine and responseHeaders into its connector map while it sends, and the send happens after the destination's filter and transformer have run. The destination's response transformer runs after the send and reads the same connectorMap; in the destination's transformer the key is still null. A value the response transformer puts into channelMap is stored with this destination's message. Whether it reaches the next destination in the chain depends on the queue: the next destination's channel map is copied from this one as soon as this destination finishes its turn in the processing thread. With the queue off, or with Send first on and an empty queue, the send and the response transformer run inside that turn, so the value travels down the chain. A destination that queues the message hands its channel map on before the send, and the value then stays on this destination's message only.

javascript
var statusCode = connectorMap.get('responseStatusCode');
channelMap.put('httpStatus', statusCode);

In templates (Velocity) ​

Destination connector fields that accept Velocity, such as the File Writer's file name and template or the HTTP Sender's URL and content, resolve ${key} against the source map, channel map, connector map and response map of the connector message, in that order, so a later map wins when two hold the same key. This template runs in a File Writer on a channel whose source connector is a File Reader, which populates originalFilename and fileSize. ${originalFilename} has a fallback: when no map holds it, the replacer substitutes the current time in milliseconds followed by .dat. A key that no map holds and that has no fallback is left as the literal ${key} text.

velocity
Original file: ${originalFilename}
Size: ${fileSize}

In the postprocessor ​

The postprocessor runs against the merged message rather than one connector, so its scope holds sourceMap, channelMap and responseMap and no connectorMap. sourceMap and channelMap are read-only there: .put() on either, and $c(key, value), throws UnsupportedOperationException. The postprocessor reads what earlier steps stored; it cannot add to those maps.

Custom map variables ​

A transformer step stores its own values with .put() on the writable maps. channelMap and connectorMap come from the script scope. DateUtil is com.mirth.connect.server.userutil.DateUtil, imported into every script scope; getCurrentDate(pattern) formats the current time with a SimpleDateFormat pattern.

javascript
channelMap.put('processedTimestamp', DateUtil.getCurrentDate('yyyy-MM-dd HH:mm:ss'));
connectorMap.put('customFlag', 'URGENT');

The channel map is copied from the source connector to the first destination of each chain, and from each destination to the next one in its chain, so a later step reads processedTimestamp with channelMap.get('processedTimestamp') or $c('processedTimestamp') and a Velocity field resolves it as ${processedTimestamp}. The connector map belongs to one connector: customFlag is visible only within the connector that wrote it.

INFO

The sourceMap is read-only in every script: sourceMap.put() and $s(key, value) throw UnsupportedOperationException. Use channelMap for values every connector in the channel needs, and connectorMap for values scoped to the current connector.