When viewing or scheduling a report, JReport Server enables you to call your Java application before or after the process.
In JReport Server, a TaskListener interface has been provided in the package jet.server.api for receiving task events before or after running. You can specify one Java class to implement this interface for a task event. When the event of this task occurs, the corresponding methods in the listener will be invoked. The interface contains two methods: beforeRun and afterRun, enabling you to set your Java application call before or after the process of viewing a report or setting up a schedule. Your applications will return true or false. For true, JReport Server will go on running. While for false, JReport Server will stop there.
Below is an example illustrating how to add TaskListener when setting up a schedule on a report.
<install_root>\help\samples\APITaskListener
. <install_root>\bin
. Assuming that TestTaskListener has been saved in C:\JReport\Server\tasklistener
, add the path of the class file (C:\JReport\Server\tasklistener
) to the ADDCLASSPATH variable in setenv.bat.Print out the task and schedule properties before and after running the task. You will then get task and schedule information in the command window before and after the task is run.
You can also define properties of your own and transmit them through ServerInfo. To do this, use APIConst.TAG_USERDEFINED_PROPERTY_PREFIX as the prefix for the properties.
For example, if you want to transmit the properties host_name, host_ip and hosp_protocol, you will need to insert the properties, before calling the method runTask, into the properties named prop, as follows:
|
You can get the value of the properties listed above through the server info object, serverInfo, in the method beforeRun or afterRun of the TaskListener class. See the example below:
|
Note: All properties without the prefix APIConst.TAG_USERDEFINED_PROPERTY_PREFIX will be denied and discarded by JReport Server.