Java service task with Activiti workflow

Activiti provides the Java service task that allows to invoke an external Java class. And here, we will see how to do it. You shoud practice the previous tutorial to be clear with the process model design before working on this.

Create an external Java class as a jar file

  1. In Eclipse, create a new Maven Project.
  2. In your project, edit the file pom.xml by adding:

        <dependency>
          <groupId>org.activiti</groupId>
          <artifactId>activiti-engine</artifactId>
          <version>5.22.0</version>
        </dependency>
  3. Create a package org.activiti.
  4. In the package org.activiti, create a class MyJavaDelegate with the following code:

    package org.activiti;
     
    import org.activiti.engine.delegate.DelegateExecution;
    import org.activiti.engine.delegate.JavaDelegate;
     
    public class MyJavaDelegate implements JavaDelegate {
     
    	public void execute(DelegateExecution execution) throws Exception {
    		String var = (String) execution.getVariable("input");
    		var = var.toUpperCase();
    		execution.setVariable("input", var);
    	}
     
    }
  5. Right click on your project and select Run As→Maven Install to build a jar file.
  6. Copy a jar file in the folder target to apache-tomcat-7.0.12\webapps\activiti-explorer\WEB-INF\lib
  7. Restart your tomcat.

Design the "Displaying Upper Case" process model

  1. In Activiti, login as admin with Processes→Model workspace→New model.
  2. Enter new model Name: Displaying Upper Case. Click Create.
  3. Firstly, enter the following process properties:
    1. Process identifier: uppercase
    2. Name: Displaying Upper Case
  4. Design a process model by drag and drop model elements, you should have something similar to this picture:


  5. On the start event, specify the following properties:
    1. Initiator: initiator
    2. Form properties:
      1. id: input, Name: Input, Type: string
  6. On the Get uppercase activity, specify the property Class: org.activiti.MyJavaDelegate
  7. On the output activity, specify the following properties:
    1. Assignments→Assignee: ${initiator}
    2. Form properties:
      1. id: input, Name: Output, Type: string
  8. Click on Save the model icon, then click on Save and close editor.
  9. In Processes→Model workspace, select your Displaying Upper Case process model, then go to Model action and select Deploy.

Executing a process model

  1. Go to Processes→Deployed process definitions, select your newly created process model, then click on Start process.
  2. Enter some text in the input, then click on Start process*.


    - Go to
    Processes→My instances to see the status of your executing process.


    As you can see, the service task
    Get uppercase has automatically executed and invoked an external java class MyJavaDelegate. Now the current task is output which needed to be handled by you. - Select Tasks→Inbox to see the output, then click on Complete task** button to end this process.


teaching_assistant/workflow/activiti_java_service_task.txt · Last modified: 2021/12/07 12:06 by Nour
Back to top
CC Attribution-Share Alike 4.0 International
chimeric.de = chi`s home Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0