Introduction
Easit ProcessRunner, or EPR for short, makes it possible to integrate Easit GO with your existing PowerShell scripts.
EPR consist of a java application running in an instance of Apache Tomcat, installed as a Windows service.
Once started, EPR listens for incoming request using a REST service. When a request is received, the JSON body of the request is passed on as a argument to a script file with the same name as the value of "importHandlerIdentifier" in the body. We also send a base64 representation of the JSON body via stdin.
|  1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30 |     {
        "importHandlerIdentifier":"testService.ps1",
        "itemToImport":[
            {
                "property":[
                    {
                        "content":"123456",
                        "name":"requestId",
                        "rawValue":null
                    },{
                        "content":"aValue",
                        "name":"aProperty",
                        "rawValue":null
                    }
                ],
                "attachment":[],
                "id":"123456:2",
                "uid":"123456"
            }
        ],
        "genericRequestProperty":[
            {
                "content":"testService.ps1",
                "name":"identifier"
            },{
                "content":"MC0CFHnd2e81XFZezdFIHPj5i+A/6dbPAhUAkUKMTyjRZtJ7SZ6c/3KL0aeZKd4=",
                "name":"initializedByXmlExport"
            }
        ]
    }
 | 
To put in to context, the command executed by the java application, with the example above would be as shows below.
|  |     C:\Users\administrator> pwsh.exe -File "Path/To/Scripts/scriptName.ps1 requestJsonBody"
 | 
To further exemplify this, our script scriptName.ps1 looks like this:
|  |     [CmdletBinding()]
    param(
        [Parameter(Mandatory,Position=0)]
        [string]$StringInput,
        [Parameter(Mandatory,Position=1)]
        [string]$Base64StringFromStdIn
    )
    $easitGOItem = Convert-EasitGOExportString -InputString $Base64StringFromStdIn
    # Write message and object to console
    "Received exported item $($easitGOItem.uid)"
    $easitGOItem
 | 
and will produce this output:
|  |     Received exported item 123456
    requestId aProperty
    --------- --------
    123456    aValue
 | 
OR (before version 1.1.0 of Easit ProcessRunner)
This will be deprecated in the future, please use the approach above. In a future release of ProcessRunner we will move to only sending input to the script via the stdin stream.
|  1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14 |     [CmdletBinding()]
    param(
        [Parameter(Mandatory,Position=0)]
        [string]$StringInput
    )
    # Requires version 1.2.0 of Easit.ProcessRunner.GlobalFunctions
    $easitGOItem = Convert-EasitGOExportString -InputString $Base64StringFromStdIn -Raw
    Write-Host "Received exported item $($easitGOItem.uid)"
    # To access the properties..
    foreach ($property in $easitGOItem.property) {
        Write-Host "$($property.Name) = $($property.Content) (rawValue: $($property.rawValue))"
    }
    # Access a specific property
    $easitGOItem.property | Where-Object {$_.Name -like "requestId"}
 | 
and will produce this output:
|  |     Received exported item 123456
    requestId = 123456
    aProperty = aValue
    content name      rawValue
    ------- ----      --------
    123456  requestId
 | 
Once the script have completed, EPR will evaluate LASTEXITCODE. If LASTEXITCODE is anything else than 0 the java application will treat it as an error or failure.