I The PowerShell script The following PowerShell script can be used, with slight modification, to test Live Score output:
$url = "http://localhost:8081/LiveScore" #Typical URL to a Live Score install when testing from the server itself.
$user = "hostname\score" #Username and password for Live Score user
$pass = "Password"
$input = "c:\temp\request.xml" # Create the c:\temp\ location if it does not exist. The request.xml is the Live Score xml that is used for testing.
$output = "c:\temp\response.xml" # This file is created and provides the response of the test
$outerr = "c:\temp\response-error.xml" # File is created only if there is an error with the Live Score request
$body = (get-content $input) # Get the xml file to use in the test
$pair = "$($user):$($pass)"
$encodedCredentials = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($Pair))
$headers = @{ Authorization = "Basic $encodedCredentials" }
# Invoke-WebRequest will throw an exception on 4xx/5xx HTTP response;
# make sure we still collect the response
# https://stackoverflow.com/questions/19122378/powershell-web-request-without-throwing-exception-on-4xx-5xx
# TODO: -ErrorAction Stop
# NOTE: "-OutFile $output" will prevent Invoke-WebRequest from returning the response object
Write-Host "Calling: $($url)"
#$res = (Invoke-WebRequest -Uri $url -Method Post -Headers $headers -Body $body) #The main part of the Powershell script that makes the request
#Write-Host "Result: $res"
#$res
try
{
Invoke-WebRequest -Uri $url -Method Post -Headers $headers -Body $body -OutFile $output
}
catch [System.Net.WebException] #Catch any/all errors
{
Write-Warning "An exception was caught: $($_.Exception.Message)"
$res = $_.Exception.Response.GetResponseStream()
$reader = New-Object System.IO.StreamReader($res)
$reader.BaseStream.Position = 0
$reader.DiscardBufferedData()
$responseBody = $reader.ReadToEnd()
Write-Warning "Server response: $responseBody"
# example of parsing the response (or error response in this case) for XML content
$parsedData = $responseBody | Select-Xml '//faultstring' | % { $_.Node."#text" }
Write-Warning "Live Score error: $parsedData"
# e.g. send an email about this error with $parsedData as the explanation
# or e.g. save the whole response body $responseBody to file
$responseBody | Out-File -FilePath $outerr
}
Write-Host "Done"
Exit # Notes:
The output of the response is sent to a file. Also, any error messages are sent to a file as well.
II. Implementing the PowerShell script 1. Open the Powershell ISE on the Live Score server by clicking Start and typing PowerShell. Select the Windows PowerShell ISE:
2. Copy the request.xml file to the C:\temp\ folder. The request.xml is specific to your Live Score model. There is an attached request.xml, which is an example. It is assumed that a model is built and deployed in Statistica Enterprise. Also, the WFID in the example request.xml will have to match the model deployed in Enterprise. For more information, see
https://support.tibco.com/s/article/How-to-build-a-workspace-with-Input-and-Output-nodes-for-Live-Score-deployment 3. Open the .ps1 file and click the green error to run the script (an example of the type of ps1 script is attached, below, as InvkWebReqWithErrorHandling_Exp.ps1):
Note that the script can be modified in the PowerShell ISE and saved.
4. Check to see if the response.xml file has been created (note that the response-error.xml will only exist when an error is generated by the script):
5. Automate the PowerScript in Windows Task Scheduler:
Now periodically the temp folder can be checked to see if a response-error.xml has been created. If so, the file can be opened with Notepad (or most any text editor) to view the contents: