APIs, SDKs, and Services > Process Server WSHT API Overview > Using JAX-WS Based WSHT4J API
  

Using JAX-WS Based WSHT4J API

The Process Server wsht4j API is a WSHT API client based on JAX-WS (version 2.1.5). To use the client API, include the avos-wsht4j.jar along with the dependent libraries (for JAX-WS) in your classpath. The JAX-WS dependent jars are:
Jar File
Comment
activation.jar
Java Activation Framework
jaxb-api.jar
JAX Binding
jaxb-impl.jar
jaxws-api.jar
JAX-WS
jaxws-rt.jar
jsr173_api.jar
Streaming API for XML
jsr181-api.jar
Web Services meta data
mimepull.jar
resolver.jar
saaj-api.jar
SAAJ
woodstox.jar
StAX-compliant (JSR-173) Open Source XML-processor
Building WSHT4J
You can build the API using the provided ant build script. The built avos-wsht4j.jar is copied to the dist/ directory. JDK 1.5 or later is required.
WSHT4J Samples
Samples using the wsht4j API can be found under the /src-examples/ source tree.

Listing Tasks

The following sample snippet shows how to list unclaimed tasks using the wsht4j API. See com.activevos.examples.wsht.GetMyTasksDemo1 (and GetMyTasksDemo2) class for the complete examples.

import com.activevos.api.humantask.AeB4PTaskClientTaskOperations;
import com.activevos.api.humantask.TaskOperations;
import com.activevos.api.humantask.wsht.htda.TGenericHumanRoleType;
import com.activevos.api.humantask.wsht.htda.TStatus;
import com.activevos.api.humantask.wsht.htda.TTask;
import java.util.ArrayList;
import java.util.List;
import javax.xml.ws.BindingProvider;
// Define endpoint, username and password
String serviceUrl =
"http://localhost:8080/active-bpel/services/AeB4PTaskClient-taskOperations";
String username = "loanrep1";
String password = "loanrep1";
// Create service and get service port.
AeB4PTaskClientTaskOperations wshtService =
new AeB4PTaskClientTaskOperations();
TaskOperations wshtServicePort = wshtService.getAeB4PTaskClientTaskOperationsPort();
// Set request properties such as binding endpoint and BASIC credentials.
((BindingProvider)wshtServicePort).getRequestContext().
put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, serviceUrl);
((BindingProvider)wshtServicePort).getRequestContext().
put(BindingProvider.USERNAME_PROPERTY, username);
((BindingProvider)wshtServicePort).getRequestContext().
put(BindingProvider.PASSWORD_PROPERTY, password);

// Task type. In this case we are looking for the tasks (and not notifications).
// In general, the taskType is 'TASKS' for all cases unless you want notifications
// in the response. For notifications, use the value 'NOTIFICATIONS'. If you want
// tasks and notifications, use 'ALL'.
String taskType = "TASKS";

// Set role to be potential owners. That is, tasks that are available
// to potential owners.
TGenericHumanRoleType role = TGenericHumanRoleType.POTENTIAL_OWNERS;
// workQueue - not used.
String workQueue = null;

// Task status - this is one of the main filters we use to narrow down the
// resultset. Unclaimed tasks have a status of 'READY'.
// Some other common status enumerations are claimed (RESERVED),
// started (IN_PROGRESS), failed (FAILED), and completed (COMPLETED).
List<TStatus> statuses = new ArrayList<TStatus>();
statuses.add(TStatus.READY); // READY = 'unclaimed'.
// whereClause - not used.
String where = null;
// createdOn - not used.
String createdOnClause = null;

// maximum number of tasks to be returned in the resultset.
int maxtasks = 5;
// Call getMyTasks
List<TTask> tasks = wshtServicePort.getMyTasks(taskType, role, workQueue, statuses, where,
createdOnClause, maxtasks);

// Note: TTask is of complex type tTask defined in ws-humantask-api-wsdl.xsd schema.
int count = tasks.size();
System.out.println("Number of tasks: " + count);
if ( count == 0 )
{
// No tasks. Normally, this happens if:
// - The username (defined in PRINCIPAL_USERNAME) does not have access to any tasks
// - There are no unclaimed tasks (that is, tasks with status = READY).
return;
}
//
// Get 1st task in the list and print some information.
//
TTask task = tasks.get(0);

// The taskId is unique and normally takes for form "urn:b4p:NNN" where NNN is some number
// (usually representing the process id that implements the task on the ActiveVOS server).
// The taskId is required for all task related operations.
String taskId = task.getId();
System.out.println("TaskID: " + taskId);

// print some additional information:
System.out.println("Name: " + task.getName());// task QName
System.out.println("PresentationName: " + task.getPresentationName());
System.out.println("PresentationSubject: " + task.getPresentationSubject());

// Expected value is READY (unclaimed).
System.out.println("Status: " + task.getStatus().toString());

Claiming a Task

The following sample snippet shows how to claim task using the wsht4j API. Look at the com.activevos.examples.wsht.BasicOperations class for the complete example showing how to claim, start, set the output, and complete a task .

// Service port
TaskOperations wshtServicePort = null;

//
// Code to create wshtServicePort similar to previous example
//
// Id of task we want to claim
String taskId = "urn:b4p:5";
try
{
// claim
wshtServicePort.claim(taskId);
}
catch(IllegalArgumentFault illegalArgumentFault)
{
//Fault due to invalid task id.
System.out.println("IllegalArgumentFault: " + illegalArgumentFault.getFaultInfo());
}
catch(IllegalStateFault illegalStateFault)
{
// Illegal state. For example, tried to claim a task that was not in a
// a READY state (unclaimed).
IllegalState illegalState = illegalStateFault.getFaultInfo();
// Sample:
// illegalState.getStatus(): 'RESERVED' (already claimed)
// illegalState.getMessage(): 'Task must be in the READY state to be claimed.'
System.out.println("IllegalStateFault: "
+ "\n taskStatus=" + illegalState.getStatus()
+ "\n " + illegalState.getMessage());
}

Additional Examples

Operation
Example Class
getMyTasks (various examples)
com.activevos.examples.wsht.GetMyTasksDemo1 com.activevos.examples.wsht.GetMyTasksDemo2
Quick overview of claim, start, setOuput and complete.
com.activevos.examples.wsht.BasicOperationsDemo
getTaskInfo
com.activevos.examples.wsht.operations.GetTaskInfoAndDescriptionDemo
getTaskDescription
com.activevos.examples.wsht.operations.GetTaskInfoAndDescriptionDemo
claim
com.activevos.examples.wsht.operations.ClaimStartStopReleaseDemo
start
com.activevos.examples.wsht.operations.ClaimStartStopReleaseDemo
stop
com.activevos.examples.wsht.operations.ClaimStartStopReleaseDemo
release
com.activevos.examples.wsht.operations.ClaimStartStopReleaseDemo
setPriority
com.activevos.examples.wsht.operations.SetPriorityDemo
getInput
com.activevos.examples.wsht.operations.GetInputDemo
getOutput
com.activevos.examples.wsht.operations.GetSetOutputDemo
setOutput
com.activevos.examples.wsht.operations.GetSetOutputDemo
deleteOutput
com.activevos.examples.wsht.operations.GetSetOutputDemo
addComments
com.activevos.examples.wsht.operations.CommentsDemo
getComments
com.activevos.examples.wsht.operations.CommentsDemo
addAttachment
com.activevos.examples.wsht.operations.AttachmentsDemo
deleteAttachments
com.activevos.examples.wsht.operations.AttachmentsDemo
getAttachmentInfos
com.activevos.examples.wsht.operations.AttachmentsDemo
getAttachments
com.activevos.examples.wsht.operations.AttachmentsDemo
delegate (assign)
com.activevos.examples.wsht.operations.DelegateDemo
forward
com.activevos.examples.wsht.operations.ForwardDemo
suspend
com.activevos.examples.wsht.operations.SuspendResumeDemo
resume
com.activevos.examples.wsht.operations.SuspendResumeDemo
complete
com.activevos.examples.wsht.BasicOperationsDemo
deleteFault
setFault
activate
fail
getRenderingTypes
com.activevos.examples.wsht.operations.RenderingsDemo
getRendering
com.activevos.examples.wsht.operations.RenderingsDemo
nominate
remove
setGenericHumanRole
skip