Example 2: Working with ScheduleDemo.java

This example is designed for submitting a schedule without using a GUI to generate a report version every hour from 9:00 to 17:00 daily. Also, the version manager will keep each of the generated results for 30 days from the day that they are generated.

To schedule the task, follow the steps below:

  1. Import the classes of the Client API by adding the following import statements to the beginning of your program.

    import jet.client.api.*;

  2. Set the connection information with the same methods used in Example 1 after you have obtained the values of command line arguments such as report URL, user, and password.
    //set the HTTP proxy for the client.if (proxyHost != null) 
    {      
        JRClient.setProxy(proxyHost, proxyPort)
    }
    //set the user ID for the client.JRClient.setUser(user);
    //set the password for the client.JRClient.setPassword(password);
    
  3. Log onto the server with the same method used in Example 1.
  4. Set the task and time properties.

    Hashtable htTask = new Hashtable(); //set properties about task info htTask.put("jrs.task_class", "jet.server.schedule.jrtasks.UpdateRptTask"); htTask.put("jrs.catalog", "/SampleReports/SampleReports.cat"); htTask.put("jrs.report", "InvoiceReport.cls"); htTask.put("jrs.expire_days", "30"); htTask.put("jrs.if_print", "false"); //set parameter values htTask.put("jrs.param$Country", "Australia"); htTask.put("jrs.param$State", "New South Wales"); htTask.put("jrs.param$City", "Sydney"); //set properties about time info htTask.put("jrs.launch_type", "8"); htTask.put("jrs.days_id", "0"); htTask.put("jrs.day", "1"); htTask.put("jrs.is_weekday", "false"); htTask.put("jrs.is_hourly", "true"); htTask.put("jrs.hours", "1"); htTask.put("jrs.is_between", "true"); htTask.put("jrs.is_pm", "false"); htTask.put("jrs.hour", "9"); htTask.put("jrs.min", "0"); htTask.put("jrs.at_min", "0"); htTask.put("jrs.is_pm2", "true"); htTask.put("jrs.hour2", "5"); htTask.put("jrs.min2", "0");
  5. Get scheduled tasks from the server using Vector tasks = JRClient.getScheduled(null, server);

    The method getScheduled(Frame frame, String jrsvrURL) returns the scheduled tasks from the report server.

    Parameters:

  6. Compile and run the demo program as with Example 1. For example, use the following command to compile:
    C:\JReport\Server\help\samples\APIClient\ScheduleTask> javac 
    -classpath C:\JReport\Server\lib\JRViewer.jar;C:\JReport\Server\lib\log4j-1.2.8.jar 
    ScheduleDemo.java
    

    When you run the programs, you should provide the parameter -server= which indicates the server URL. For example, use the following command to run the demo program.

    C:\JReport\Server\help\samples\APIClient\ScheduleTask> java 
    -classpath "C:\JReport\Server\lib\JRViewer.jar;C:\JReport\Server\lib\log4j-1.2.8.jar;"
     ScheduleDemo -server=http://localhost:8888/jrserver -user=admin -password=admin
    

    There are also the following optional parameters:

    By running the program, you will submit a scheduled task and obtain information about this task.