Create Custom Task (Java)

Last modified 13 Nov 2021 00:39 +01:00

MidPoint Task Manager is designed for extensibility. It can manage any kind of task. Each task has two parts: The definition (TaskType object) and the code.

Custom Task Definition

Simply import the XML object definition similar to the following:


    <name>My Custom Task</name>
    <ownerRef oid="00000000-0000-0000-0000-000000000002"/>

The important part is the handler URI. The handler URI associates the task definition with the code.

Custom Task Code

The task code must be part of midPoint code. Currently perhaps the only feasible way is to recompile midPoint with your custom code in it (see Source Code Customization). The code itself is simply one class that implements the task handler:

public class MyTaskHandler implements TaskHandler {

    public static final String HANDLER_URI = "";

    private TaskManager taskManager;

    private void initialize() {
        taskManager.registerHandler(HANDLER_URI, this);

    public TaskRunResult run(Task task) {

        long progress = task.getProgress();
        OperationResult opResult = new OperationResult("com.example.mytask.handler");
        TaskRunResult runResult = new TaskRunResult();

		// TODO: custom code comes here


        // This "run" is finished.
        return runResult;

    public Long heartbeat(Task task) {
        // Heartbeat is not supported for this task
        return null;

    public void refreshStatus(Task task) {
        // Do nothing, no need to explicitly refresh task status

    public String getCategoryName(Task task) {
         return TaskCategory.CUSTOM;

    public List<String> getCategoryNames() {
        // just a single category, specified above
        return null;

The code is using Spring annotations to manage the class lifecycle. The class registers itself in the task manager in the post-construct method. The same handler instance will be invoked for all task instances. The task instance is passed as a parameter.

Was this page helpful?
Thanks for your feedback