Search code examples
javacamundacamunda-modeler

How to write a dummy java API to returning a string and call it from a Camunda service task


I want to write a dummy java api and call it from the Camunda workflow

@WebServlet("/Avg")

public class Avg extends HttpServlet{

private static final long serialVersionUID =1L;

@Override
protected void doGet(HttpServletRequest req,HttpServletResponse resp) throws ServletException,IOException{
    ProcessEngine engine =BpmPlatform.getDefaultProcessEngine();

    List<LockedExternalTask> tasks =engine.getExternalTaskService().fetchAndLock(1,"some-random-id")
    .topic("payeeavg", 2000).execute();
    Random rnd = new Random();
    int number = rnd.nextInt(999999);
    String.format("%06d", number+50000);
    LockedExternalTask lockedExternalTask =(LockedExternalTask) tasks;
    engine.getExternalTaskService().complete(lockedExternalTask.getId(), "some-random-id");
}

}

I have tried writing this but don't know how to connect it to camunda.

execution.getBpmnModelElementInstance();
    String vcUniqueTransID ="1234";
    String payeeavg = "123";
    String Comment = "Fraud";
    Boolean Approve = true;
    String Approvee ="No";

I want to write a dummy API which will give a output of string value and it should be called in the service task to get the payeeavg variable.

I have seen the camunda external task doc but i cant understand how to write it and connect it

if anyone can help or share a example how to do it.


Solution

  • You mean you want to call a REST service you exposed from within a service task?

    Here is an example how to do this: https://github.com/camunda-consulting/code/tree/master/snippets/rest-service-task-spring