Advanced Customization > Info*Engine User’s Guide > Server Access Kit > About the Server Access Kit > Executing Tasks
  
Executing Tasks
To create an instance of a task object, use the constructor that takes a URL as a parameter. For example:
import com.infoengine.SAK.Task;
  :
  :
Task task = new Task ("/com/acme/infoapp/QueryBOM.xml");
The parameter of this Task constructor is the URL of an Info*Engine task. A variety of URL formats can be specified. For example URLs, see Info*Engine JSP Pages.
After constructing a task instance, the application can add parameters to the task by calling the addParam method. This method accepts the name of the parameter to be added and its value. For example:
import com.infoengine.SAK.Task;
  :
  :
Task task = new Task ("/com/acme/infoapp/QueryBOM.xml");
task.addParam ("class", "wt.part.WTPart");
task.addParam ("where", "name='Engine'");
task.addParam ("group_out", groupOutName);
The same parameter name can be specified in more than one call to addParam in order to add multivalued parameters. Parameter values can be of any object type. Parameters are referenced within a task by using normal Info*Engine substitution against the @FORM context group. Thus, each call to the method addParam adds an attribute with the specified name and value to the @FORM context group of the task to be executed.
In addition to adding parameters to a task, an application can also establish execution options against the task before invoking it. For example, an application can set the username under which the task should execute. This username can then be used by Info*Engine as a credentials mapping key to select the credentials (for example, username and password) that are provided to each adapter with which the task communicates. The task’s username can be set as follows:
task.setUsername ("guest");
This sets the auth-user attribute in the @SERVER context group of the task. Other attributes can be added to the @SERVER context group also. This context group usually contains information about the runtime environment in which a task is executing. For example, when a task is executed using the Info*Engine servlet, the @SERVER context group is populated with attributes derived from information provided by the web server including all HTTP protocol headers. Applications that create and execute task instances can use the setServerAttribute method to populate the @SERVER group with runtime environment information. For example:
task.setServerAttribute ("accept-language", "en-US");
By default, Info*Engine executes tasks within the Java Virtual Machine (JVM) of the calling application. Sometimes it is more appropriate to execute tasks in a non-local JVM that is hosting an Info*Engine task processor. This is particularly true when the source code of the task can be accessed only by that non-local task processor. For example, if the task source contains sensitive information, such as privileged passwords, access to it may be restricted. When a task must be executed by a non-local task processor, an application can call the addProcessor method to specify the names of the Info*Engine task processors in which the task can be executed. For example:
task.addProcessor ("com.mycompany.engineering.windchill");
After adding all necessary parameters and service options, the task is executed by calling its invoke method as follows:
task.invoke ();