Automating tasks
IBM i Access for Web provides a program to automate the running of tasks. By automating the running of tasks, those tasks can also be scheduled to run when you need them to run. This topic discusses how to automate and schedule IBM i Access for Web tasks.
Even though the invocation of these tasks can be simplified to a single click of an icon on a web page or the invocation of a web browser address, an interactive action by a workstation user is required.
Overview
The /QIBM/ProdData/Access/Web2/lib/iWATask.jar file is a java program that will read an input properties file, parse the contents of the properties file, and invoke the task defined. The properties file will contain:- The web browser address of the IBM i Access for Web servlet/task to invoke
- An IBM i user ID and password that IBM i Access for Web will use to authenticate to IBM i
- Any additional parameters for the task that will be invoked
- An output file to write results of the task
This iWATask.jar java program can be run from any platform where Java™ Runtime Environment Version 1.5 is available. This would include IBM i, Microsoft Windows, Linux®, etc.
Requirements
To run the iWATask.jar program, the following is required on the platform where the program will run:- Java Runtime Environment Version 1.5.
- IBM i Access for Web servlets configured and running on an IBM i system.
- Communications connection from the platform running the iWATask.jar program to the IBM i system where IBM i Access for Web servlets are configured.
- The IBM i
Access for Web environment
must be configured for Application authentication or Application Server
authentication that uses Basic authentication.
IBM i Access for Web is configured to the web application server using the
CFGACCWEB/cfgaccweb
command. When this command is run, the method used to authenticate to IBM i can be specified. Authentication can be performed by either the web application (IBM i Access for Web) or by the web application server (WebSphere® Application Server).The
CFGACCWEB/cfgaccweb
command's default action is web application authentication. This can also be specified using the AUTHTYPE(*APP) parameter on theCFGACCWEB/cfgaccweb
command.If the web application server is to handle authentication, IBM i Access for Web task automation requires basic authentication be performed. This can be specified on the
CFGACCWEB/cfgaccweb
command using the parameter combination AUTHTYPE(*APPSVR) AUTHMETHOD(*BASIC).
Running the program
The syntax for running the iWATask.jar program is shown below. As mentioned, Java Runtime Environment v1.5 is required to run the iWATask.jar program. You can verify the version of java available by running the commandjava –version
. If the version
of java displayed is not 1.5, or later, you may need to provide the
path to the java program.java –jar iWATask.jar <property_file> <property_file> <property_file>
- Where the <property_file> parameter is one or more optional property files.
java –jar -Dcom.ibm.as400.webaccess.iWATask.log.category=information,diagnostic,warning,error,all
iWATask.jar <property_file>
- Where the category parameter can be any combination of the comma separated values listed. Specifying all will log all categories.
- Where the <property_file> parameter is one or more optional property files.
- The default log file name is: iWATask.log.
java –jar -Dcom.ibm.as400.webaccess.iWATask.log.category=information,diagnostic,warning,error,all
-Dcom.ibm.as400.webaccess.iWATask.log.file=<file_name> iWATask.jar <property_file>
- Where the file_name parameter is the name of the file where information will be logged.
- Where the <property_file> parameter is one or more optional property files.
As the iWATask.jar runs, output from the program will be written to standard output. An example of the output is shown below.
Output | Output description |
---|---|
Processing property file ping_text_output.properties. |
Name of property file being processed. |
Connecting to http://<IBMi_system_name>:<port>/webaccess/iWAPing |
Complete web address of the task |
Connection completed, waiting for a
response... |
Connection was successful, waiting for task to complete |
Connection response code: 200 |
Response code returned by the task |
Connection response code message: OK |
Response code message |
The URL connection completed successfully. |
Indicates connection to the task was successful |
Returned content type: text/plain |
Type of data returned |
Output being written to: ping_text_output.txt. |
File where output was written |
Total bytes written to output file:
89 |
Number of bytes written to the output file |
Processing completed for property file
ping_text_output.properties. |
Done processing the property file |
Properties file format
The properties file defines the IBM i Access for Web task to run. Several parameters must be specified including an IBM i user ID and password. Care should be taken to secure the properties file on the platform where the file is stored so that only authorized users can access them.The content of the properties file includes the following key=value pairs:
- url
- This property defines which IBM i
Access for Web task to invoke. Example
values for this property are:
- http://<IBMi_system_name>:<port>/webaccess/iWAPing
- https://<IBMi_system_name>:<port>/webaccess/iWAPing
- user/password
- These properties will be used to authenticate to the IBM i system specified in the url property and invoke the task.
- parm. <parameter_name>
- This property defines a parameter name and it's value that
is to be passed into the task specified in the url property. The IBM i
Access for Web servlet will use this
parameter/value to perform the task. See IBM i Access for Web URL interfaces for
complete information on parameters. Example values for this property
are:
Table 2. Example <parameter_name> values Parameter name Parameter description parm.request=inventory
parameter for iWADbExec task parm.jobInfo=123456/JOE/QPADEV0001
parameter for iWAJobLog task parm.queue=QPRINT
parameter for iWASpool task - output
- This property defines the name of a file where output from the task will be written.
url=http://myIBMisystem/webaccess/iWADbExec
user=JOE
password=VIKINGS
parm.request=inventory
output=task.txt
Considerations
Using parameter information:
Many of the IBM i Access for Web tasks allow for the input of parameter information. This input allows the caller to customize what actions the task will perform or how data will be returned. See IBM i Access for Web URL interfaces for complete information on parameters
iWATask.jar file:
It is recommended that a copy of /QIBM/ProdData/Access/Web2/lib/iWATask.jar be used to automate IBM i Access for Web tasks. Using a copy of the file will help prevent accidental changes to the shipped file. If IBM i Access for Web PTFs are applied to your IBM i system, you may need to get the latest copy of /QIBM/ProdData/Access/Web2/lib/iWATask.jar after applying PTFs.
Automating multiple tasks:
The properties file can only contain information for automating a single task. If multiple tasks are to be automated, multiple properties files must be used. Multiple properties files can be input to a single invocation of the iWATask.jar program. See the Running the program section for more detail on inputting multiple properties files to iWATask.jar. An alternative would be to invoke the iWATask.jar program multiple times with a single properties file.
User ID/Password:
The properties file contains IBM i user ID and password information. Care should be taken to secure the properties file on the platform where the file is stored so that only authorized users can access them.
Default properties file:
jar –uf iWATask.jar task.properties
You
would then invoke iWATask.jar without inputting a properties file.
The program will look for task.properties within the archive. There
are two benefits of doing this:- By putting the properties file within the iWATask.jar archive, it will be less obvious that the properties file contains user ID/password information.
- You can rename iWATask.jar to a name more descriptive of the task being automated. This can help you organize the automation of your tasks.
Handling errors:
Many IBM i Access for Web tasks complete with an HTTP status code of 200, indicating success, even if there is an error during processing. This is because the error information was successfully generated. To determine if a task completed successfully, the information returned by the iWATask.jar program and the information written to the output file need to be examined. The IBM i Access for Web Information example below discusses how to examine the information returned.
HTTPS/SSL:
The IBM i Access for Web tasks can be used with the iWATask.jar program for either HTTP or HTTPS/SSL environments. To use IBM i Access for Web tasks that are secured using HTTPS/SSL, additional setup is required. Please refer to the documentation found on the IBM i Access for Web site for additional information.
Restrictions
Intermediate web pages:The IBM i Access for Web task being automated, when combined with specified parameters, cannot display any intermediate web pages or prompt a user for information.
Authentication:
The IBM i
Access for Web environment must be
configured for Application authentication or Application Server authentication
that uses Basic authentication. The authentication type is specified
when the CFGACCWEB/cfgaccweb
command
is run. Specifying the AUTHTYPE(*APP) parameter or the AUTHTYPE(*APPSVR)
AUTHMETHOD(*BASIC) parameters are supported environments.
IBM i Access for Web Information example
IBM i Access for Web provides a servlet/task that displays information about IBM i Access for Web. The iWAInfo servlet can be used to display version information, properties used by the product, HTML information, etc. This is a simple example to show you how you can automate the use of IBM i Access for Web functions.- Open a web-browser on the workstation.
- Type the web-browser address http://<IBMi_system_name>:<port>/webaccess/iWAInfo
- You will be prompted to enter your IBM i user ID and password.
- The web page will be refreshed displaying copyright/version information, Product information, Request information, etc. This verifies the workstation can connect to IBM i Access for Web functions. The information returned is of type HTML and rendered in the web-browser.
- Close the web-browser.
- Copy the /QIBM/ProdData/Access/Web2/lib/iWATask.jar file to a directory on the workstation
- In the same directory where you copied iWATask.jar, create a file
named iwainfo.properties and add the following properties to the file:
url=http://<IBMi_system_name>:<port>/webaccess/iWAInfo user=<your_IBMi_user_ID> password=<your_IBMi_password> output=iwainfo.txt
- Save and close the iwainfo.properties file.
- Run the iWATask.jar program using the syntax shown below. You
must use the Java Runtime Environment
v1.5 java command.
To run the program and log information to the log file iWATask.log, use the syntax below:java –jar iWATask.jar iwainfo.properities
java –jar -Dcom.ibm.as400.webaccess.iWATask.log.category=all iWATask.jar iwainfo.properties
- When the program runs, output will be written to standard out
and will look similar to the following:
Processing property file iwainfo.properties Connecting to http://<IBMi_system_name>:<port>/webaccess/iWAInfo Connection completed, waiting for a response... Connection response code: 200 Connection response code message: OK The URL connection completed successfully. Returned content type: text/html; charset=utf-8 The returned HTML content type does not match the output file extension. This may indicate an error page was returned. Output being written to: iwainfo.txt Total bytes written to output file: 34270 Processing completed for property file iwainfo.properties
- Notice the message “Returned content type: text/html; charset=utf-8”.
This message indicates the output data that was returned is of type
HTML, a web page. In the iwainfo.properties file, the output property
was set to write the output data to file iwainfo.txt, a text file.
Because the returned type (HTML) did not match the expected type
(TXT), the message “The returned HTML content type does not match
the output file extension. This may indicate an error page was returned.”
was displayed.
In this particular case, it's not an error. Changing the extension of the output file specified in iwainfo.properties will resolve the issue. We will do this in a later step. This would be an error condition if the output type was HTML but PDF was expected. If this were the case, the received HTML output likely contains error information and would need to be reviewed.
- Edit iwainfo.properties and modify the output property:
output=iwainfo.html
- Save and close the iwainfo.properties file.
- Run the iWATask.jar program as you did above.
- Note that the message “The returned HTML content type does not match the output file extension. This may indicate an error page was returned.” was not displayed.
- You can now open iwainfo.html using a browser to display the output from the iWAInfo servlet.
- To automate the running of this task, you would use the workstation's scheduling function to invoke the iWATask.jar program as you did above.
IBM i Access for Web database request example
IBM i Access for Web provides a servlet/task that runs an SQL database query. The result of the query can be written to a variety of formats. This is a simple example to show you how you can automate the use of IBM i Access for Web functions.- Open a web-browser on the workstation.
- Type the web-browser address http://<IBMi_system_name>:<port>/webaccess/iWAInfo
- You will be prompted to enter your IBM i user ID and password.
- Click the Database tab.
- Click the Run SQL link.
- In the SQL statement field, type: SELECT * FROM QIWS.QCUSTCDT
- In the SQL Output->Type pulldown menu, select: Portable Document Format (.pdf)
- Click the Save Request button.
- In the Request name field, type: Inventory
- Click the Save Request button.
- Click the My requests link.
- Click the Run action icon for the Inventory request.
- The result of the database request should be displayed/available as a PDF document within the web-browser.
- Return to the My requests list.
- Move the cursor over the Run action icon. In the browser window,
usually at the bottom, the web-browser address the Run action icon
represents will be displayed. The address should be similar to:
http://<IBMi_system_name>:<port>/webaccess/iWADbExec/sqlOutput.pdf?request=Inventory
- Make note of the web-browser address, you will need it in a later step. You may be able to right click on the Run action icon to display a menu for the icon. On that menu you may be able to select an option to copy the link location that the icon represents and then use that in a later step.
- Close the web-browser.
- Copy the /QIBM/ProdData/Access/Web2/lib/iWATask.jar file to a directory on the workstation
- In the same directory where you copied iWATask.jar, create a file
named iwapdf.properties and add the following properties to the file:
url=http://<IBMi_system_name>:<port>/webaccess/iWADbExec user=<your_IBMi_user_ID> password=<your_IBMi_password> parm.request=Inventory output=iwapdf.pdf
- Save and close the iwapdf.properties file.
- Run the iWATask.jar program using the syntax shown below. You
must use the Java Runtime Environment
v1.5 java command.
To run the program and log information to the log file iWATask.log, use the syntax below:java –jar iWATask.jar iwapdf.properities
java –jar -Dcom.ibm.as400.webaccess.iWATask.log.category=all iWATask.jar iwapdf.properties
- When the program runs, output will be written to standard out
and will look similar to the following:
Processing property file iwapdf.properties Connecting to http://<IBMi_system_name>:<port>/webaccess/iWADbExec?request=Inventory Connection completed, waiting for a response... Connection response code: 200 Connection response code message: OK The URL connection completed successfully. Returned content type: application/pdf Output being written to: iwapdf.pdf Total bytes written to output file: 4590 Processing completed for property file iwapdf.properties
- You can now open iwapdf.pdf using a PDF reader to display the output from the iWADbExec servlet.
- To automate the running of this task, you would use the workstation's scheduling function to invoke the iWATask.jar program as you did above.