此内容没有您所选择的语言版本。

Chapter 56. Work item handler project customization


You can customize the code of a work item handler project. There are two Java methods required by a work item handler, executeWorkItem and abortWorkItem.

Expand
Table 56.1. Java method descriptions
Java MethodDescription

executeWorkItem(WorkItem workItem, WorkItemManager manager)

Executed by default when the work item handler is run.

abortWorkItem(WorkItem workItem, WorkItemManager manager)

Executed when the work item is aborted.

In both methods, the WorkItem parameter contains any of the parameters entered into the custom task through a GUI or API call, and the WorkItemManager parameter is responsible for tracking the state of the custom task.

Example code structure

public class MyWorkItemWorkItemHandler extends AbstractLogOrThrowWorkItemHandler {

  public void executeWorkItem(WorkItem workItem, WorkItemManager manager) {
    try {
      RequiredParameterValidator.validate(this.getClass(), workItem);

      // sample parameters
      String sampleParam = (String) workItem.getParameter("SampleParam");
      String sampleParamTwo = (String) workItem.getParameter("SampleParamTwo");

      // complete workitem impl...

      // return results
      String sampleResult = "sample result";
      Map<String, Object> results = new HashMap<String, Object>();
      results.put("SampleResult", sampleResult);
      manager.completeWorkItem(workItem.getId(), results);
    } catch(Throwable cause) {
      handleException(cause);
    }
	}

	@Override
	public void abortWorkItem(WorkItem workItem, WorkItemManager manager) {
    // similar
	}
}
Copy to Clipboard Toggle word wrap

Expand
Table 56.2. Parameter descriptions
ParameterDescription

RequiredParameterValidator.validate(this.getClass(), workItem);

Checks that all parameters marked “required” are present. If they are not, an IllegalArgumentException is thrown.

String sampleParam = (String) workItem.getParameter("SampleParam");

Example of getting a parameter from the WorkItem class. The name is always a string. For example, WorkItem. In the example, SampleParam is always a string but the object associated with it can be many things and require a cast in order to avoid errors.

// complete workitem impl…

Executes the custom Java code when a parameter is received.

results.put("SampleResult", sampleResult);

Passes results to the custom task. The results are placed in the data output areas of the custom task.

manager.completeWorkItem(workItem.getId(), results);

Marks the work item handler as complete. The WorkItemManager controls the state of the work item and is responsible for getting the WorkItem ID and associate the results with the correct custom task.

abortWorkItem()

Aborts the custom Java code. May be left blank if the work item is not designed to be aborted

Note

Red Hat Process Automation Manager includes a limited set of supported custom tasks. Custom tasks that are not included in Red Hat Process Automation Manager are not supported.

返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2025 Red Hat