The File connector is used to communicate with a native file system not requiring authentication and allows a script to be run after a PUT. Folders and files accessed by this connector use the credentials of the user running the Cleo Harmony process.
If a Root Path is configured in the File properties tab, files and folders at or below this path are accessible while those above are not accessible. If a Root Path is not configured, the file being accessed must be described by an absolute path.
If accessing a UNC path through a URI using this connector and the Root Path is not configured, the short-form URI syntax must be used. For example:
LCOPY ..\outbox\test\test.edi myfiles://filsvr01/public/subdir01/subdir02/test1.edi
where there is a File connector whose System Scheme Name property is set to myfiles.
Post Processing Commands
The Post Processing Command property is a string that supports a replacement token syntax, which allows the name of the file that was just PUT to be placed in the command line arbitrarily. The replacement token mechanism also supports additional tokens and expressions to allow the command line to include formatted timestamps, source metadata, and JavaScript expressions.
Tokens and expressions are embedded in the command line using the ${expression}
syntax, where the simplest expression is a direct token reference. The following tokens and expressions are supported:
Token/Expression | Description |
---|---|
file | the filename including path and full filename |
filename | the full filename, excluding the path |
path | the filename path (filename removed, trailing / or \ included) |
base | the base portion of the filename (path and .extension removed) |
noext | the base portion of the filename (.extension removed) |
ext | the filename extension (including the . prefix) |
date('format') | the current date/time formatted with format string based on Java SimpleDateFormat |
source['metadata'] | metadata propagated from the source (see below) |
expression |
a JavaScript expression, possibly including the above |
The following describes the relationship between the various filename components for /path/to/file/basefilename.extension
file | /path/to/file/basefilename.extension |
filename | basefilename.extension |
path | /path/to/file/ |
base | basefilename |
noext | /path/to/file/basefilename |
ext | .extension |
The following expressions all evaluate to the same result:
${path}${base}${ext}
${noext}${ext}
${file}
${path+base+ext}
As a performance optimization, any JavaScript expression of the form ${token}
for one of the tokens above is expanded without invoking the JavaScript engine. Also, the primitives ${date('string')}
or ${date("string")}
are similarly expanded without invoking JavaScript. This means that although the four examples above produce the same result, the first three execute much more quickly. But the JavaScript engine provides more capability for some use cases.
This (Linux) example renames the file by inserting the last portion of the DocDBTransferID (a GUID) before the extension:/bin/mv ${file} ${noext}.${source.DocDBTransferID.replace(/.*-/,'')}${ext}
A word about source['metadata']
If a script connection is used directly through a URI reference as the inbox of another Harmony connection (or host or mailbox), additional protocol-specific metadata may be available in addition to the file content being stored. The metadata is represented as a JavaScript array (so use square brackets to access the values). For example, values available for AS2 include:
Some examples of source['metadata']:
${source['AS2-From']} |
The AS2-From (partner) name |
${source['AS2-To']} |
The AS2-To (local) name |
${source['ClientServer.Role']} |
"Server" in a typical use case as described |
${source['Content-Disposition']} |
HTTP.header.Content-Disposition |
${source['Content-Type']} |
HTTP.header.Content-Type |
${source['DocDBTransferID']} |
The Harmony REST API transfer ID |
${source['HTTP.header.'+header]} |
The HTTP header header |
${source['Protocol']} |
"AS2" |
${source['Subject']} |
The AS2 Subject |
${source['TransferID']} |
The Harmony transfer ID |
${source['VersaLex.Serial.Number.Short']} |
The Harmony serial number, e.g. "HY1234" |
To inspect the available metadata for a particular configuration, use a post-process command like the following.
- On Linux:
/bin/sh -c 'echo ${JSON.stringify(source)}'
- On Windows:
cmd.exe /c echo.exe ${JSON.stringify(source)}
Command Output Logging
The intent of the Post Processing command is to process the file and indicate success with a process return code of 0 or failure with any nonzero return code. To aid with troubleshooting, the script connector also captures any output, including "standard output" (stdout) and "error output" (stderr) and copies them as detail records to the log, one log message per line.
Standard output records are prefixed with [stdout] and are logged at log level LOW, while standard error records are prefixed with [stderr] and are logged at log level ESSENTIAL.
File Connector Properties
Each instance of the File Connector can be configured using the following settings:
Property | Description | Required |
---|---|---|
Root Path | The file system root path. Custom macros may be used at the beginning of the path. | |
Expand Fie Name On Put | Controls whether ${expressions} should be expanded in destination file names on a PUT. | |
Post Processing Command | The operating system command to be executed after a PUT. Use ${fie} to represent the file to be processed. | |
Post Process Working Directory | The optional working subdirectory of the Root Path in which to run the post processing command. Custom macros may be used at the beginning of the path. | |
Post Process Timeout (seconds) |
The number of seconds to wait for the Post Processing Command to complete before killing the process and forcing an error, or 0 to disable the timeout feature. |
|
Command Retries | The number of tunes the command should be retried when an error or exception occurs. Valid range: [0-5]. |
Yes |
Command Retry Delay (seconds) | The number of seconds to wait between retries. Valid range: [0-120]. |
Yes |
Do Not Send Zero Length Fies | For PUT, a switch that controls whether to send a file if it is zero-length. | |
Delete Received Zero Length Fies | For GET, a switch that controls whether to remove a received file that is zero-length. | |
Retrieve Directory Sort | For PUT, the sorting options for the list of outbound files. | |
Enable Debug | A switch that controls whether to perform debug logging. | |
System Scheme Name | The URI scheme name used as a shortcut to this host. Valid pattern: [[a-zA-Z]{ 1 }[a-zA-Z0-9+\-V]{ 1.23}] . |
|
System Public | A switch that indicates whether the connector is public. |
Comments
0 comments
Please sign in to leave a comment.