This component is used for executing Python Script. The Python Script to be executed is specified using the Custom Property Sheet (CPS). This component executes the script on documents it receives as input and returns the result.
Points to note
- Input message content and properties can be accessed using document object.For example, 'document.getText()' returns input message content.To access a message property named 'TestProperty, 'document.getRecord().getProperty('TestProperty')' returns the value of the property.
- Message properties can be set using 'setProperty' method.
- Message properties which are set on input message also appear on output message unless they are changed in the script.For example, if a property named 'TestProperty' is present on input message then output message also contains the property unless it is changed in script provided.
- Output message content can be set either by using 'setText(String value)' of document object or by specifying a return value(using 'print') in the script provided.If both present, return value is set as message content.
Configuration and Testing
Interaction Configuration
Figure 1: Interaction Configurations panel in Python CPS
Attributes
Read Script from file?
If enabled, Script file path property appears where you can provide the location where the script file is saved.
Script File Path
Provide the complete path of the Python Script file (file should have .py extension) which you want to execute.
Figure 2: Script file path property to provide the location where the script file is saved
PythonScript
If Read Script from file ? property is disabled, populate the PythonScript property with the Python Script.
Scheduler Configuration
Please refer the respective section in Common Configurations page.
Transport Configurations
Please refer the respective section in Common Configurations page.
Error Handling
Please refer the sections Request Processing Error and Invalid Request Error in the Error Handling section of Common Configurations page for details.
Sample Input and Output
The configuration can be tested by clicking the Test button in the interaction Configuration panel.
Below is a sample Python script.
Figure 3: Sample Python Script
Below are the sample input and the output respectively for the above script.
Figure 4: Sample Input Message
Figure 5: Response Generated
Functional Demonstration
Scenario 1
Execution of Python Script provided.
Configure the Python Script adapter as described in Configuration and Testing section and use feeder and display component to send sample input and to check the response respectively.
Figure 6: Scenario demonstration with sample input and output
Scenario 2
This sample demonstrates accessing an input message.
Configure the component with the following script.
Figure 7: Sample Python Script
Figure 8: Sample Input Message
Figure 9: Response Generated