Step 9. Invoke User Agent in Batch Mode
INT004 - Using the LANSA User Agent
The previous steps in this exercise have run the User Agent from Integrator Studio. In this step, you will execute the User Agent in batch mode to send the XLS file. Note: this step requires the User Agent to be installed as a standalone application.
1. The files already created for the User Agent project are in a directory such as:
C:\Program Files\LANSA\Integrator\Studio\workspace\JMI Training\solutions\SendCSVFile
Copy these files from the above directory
SendCSVFile.lih
iii_employee_new_salary.xls
to the \User Agent\workspace folder, such as:
C:\Program Files\LANSA\Integrator\UserAgent\workspace
2. In the following steps you will use C:\Program Files\LANSA\Integrator\UserAgent ). The file iii_UPLOAD.BAT is a DOS batch file which will enable the user agent to be executed without a user interface, by passing the required parameters into the User Agent when the batch file is executed.
to create an iii_UPLOAD.BAT file in the directory where you installed the LANSA User Agent (by default3. Open
and open the file:C:\Program Files\LANSA\Integrator\UserAgent\workspace\upload.bat
Note: You will need to use All Files when opening the file.
This is a shipped example batch file for running User Agent. The code should look like the following:
@echo off000
cls
rem --- Delete previous error log file
if exist useragent.err del useragent.err
rem --- Send
java -Djsf.log=\LANSA\Integrator\useragent\useragent.log com.lansa.jsf.useragent.JSFUserAgent acme.lih order.xls xls-order-response.rsp
if exist useragent.err goto error
rem --- Send
java -Djsf.log=\LANSA\Integrator\useragent\useragent.log com.lansa.jsf.useragent.JSFUserAgent acme.lih order.csv csv-order-response.rsp
if exist useragent.err goto error
goto end
rem -- An error has occured
:error
cls
echo Check useragent.err for possible messages
echo Check useragent.log for possible messages
goto end
:end
Delete the second block of code between "rem --- Send" and "goto error" including this code. The supplied example assumes that the batch file will send two files. The code to delete, is shown in red in the program code above. Your code should now look like the following:
@echo off
cls
rem --- Delete previous error log file
if exist useragent.err del useragent.err
rem --- Send
java -Djsf.log=\LANSA\Integrator\useragent\useragent.log com.lansa.jsf.useragent.JSFUserAgent acme.lih order.xls xls-order-response.rsp
if exist useragent.err goto error
goto end
rem -- An error has occured
:error
cls
echo Check useragent.err for possible messages
echo Check useragent.log for possible messages
goto end
:end
4. The supplied code needs to be extended to operate on your PC. The code you enter will depend on the version of Windows you are using. The examples provided here are for Windows XP. Replace "java" at the start of the command line with a full path. Your code should look like the following. The new code is shown in red. REVIEW THIS. NOT SURE OF CORRECT FORMAT.
rem --- Send
C:\WINDOWS\system32\JAVAW.EXE "-Djava.ext.dirs=..\lib\ext" "-Djava.endorsed.dirs=..\lib\endorsed" "-Djsf.log=.\useragent.log" com.lansa.jsf.useragent.JSFUserAgent acme.lih order.xls xls-order-response.rsp
5. The command line you are editing runs the User Agent in the Java runtime environment (JVM) passing a number of parameters such as the configuration file (.lih) to be used. The first parameter begins "-Djava.ext.dirs= . You need to insert into this parameter the path for the \lib\ext folder. If you examine the folder C:\Program Files\Java using Windows explorer you will probably find it contains folders for a number of versions of Java, which are left in place when Java is updated. See the example following:
You should specify the path for the latest version of Java (or alternatively the actual Java version you have specified in your Integrator settings). For example C:\Program Files\Java\jre6\lib\ext. Add this path into the first parameter as shown. Changes are shown in red:
rem --- Send
C:\WINDOWS\system32\JAVAW.EXE "-Djava.ext.dirs=c:\program files\java\jre6\lib\ext;.\lib\ext" "-Djava.endorsed.dirs=..\lib\endorsed" "-Djsf.log=.\useragent.log" com.lansa.jsf.useragent.JSFUserAgent acme.lih order.xls xls-order-response.rsp
6. This step will specify the correct runtime parameters for the configuration file(lih), the input file (xls) and the response file (csv).
Replace the end of the command string, starting from acme.lih, so that the command looks like the following. Ensure the file names used have your initials. The changes are shown in red:
rem --- Send
C:\WINDOWS\system32\JAVAW.EXE "-Djava.ext.dirs=c:\program files\java\jre6\lib\ext;.\lib\ext" "-Djava.endorsed.dirs=..\lib\endorsed" "-Djsf.log=.\useragent.log" com.lansa.jsf.useragent.JSFUserAgent workspace\SendCSVFile.lih workspace\iii_employee_new_salary.xls workspace\iii_employee_response.csv
Important Note: Remember you are editing a single command line. It is shown here spilt across a number of lines due to width limitations. Using you can view this line as a single line or over a number of lines if word wrap is enabled.
7. The complete iii_upload.bat file should look like the following:
@echo off
cls
rem --- Delete previous error log file
if exist useragent.err del useragent.err
rem --- Send
C:\WINDOWS\system32\JAVAW.EXE "-Djava.ext.dirs=C:\Program files\Java\jre1.6.0_07\lib\ext;.\lib\ext" "-Djava.endorsed.dirs=..\lib\endorsed" "-Djsf.log=.\useragent.log" com.lansa.jsf.useragent.JSFUserAgent workspace\SendCSVFile.lih workspace\iii_employee_new_salary.xls workspace\iii_employee_response.csv
if exist useragent.err goto error
goto end
rem -- An error has occured
:error
cls
echo Check useragent.err for possible messages
echo Check useragent.log for possible messages
goto end
:end
Note how the send instruction is composed of four parts:
- The instruction to start the User Agent.
- The first parameter - SendCSVFile.lih (how to find the service)
- The second parameter - iii_Employee_New_Salary.xls (the data to be processed)
- The third parameter - iii_employee_response.csv (the name of the file that will receive the response from the service)
8. In the File menu, select the Save As option using these options:
Save in |
locate the directory where you installed the LANSA User Agent, by default ...\program files\lansa\integrator\UserAgent\ |
File Name |
iii_UPLOAD.BAT |
Save as Type |
All files |
Note: Save to …\UserAgent\ not …\UserAgent\workspace\.
9. Execute the iii_UPLOAD.BAT file. If successful, a file called iii_response.csv should be created in the directory …\UserAgent\workspace\. Windows will open this (CSV) file with Excel.
If you encounter a problem, the first thing to check is whether you can manually start the LANSA User Agent, load host SendCSVFile.lih, open source iii_Employee_New_Salary.xls, send, and receive a response. Refer to Step 5. Test iiiFN05 function for details.