javascriptcamunda

How to send an HTTP request using Javascript within a BPMN model's script task?


I wold like to send an HTTP request from within a script task in a BPMN model executed by Camunda using Javascript. Does anyone know how to do that?

I've already tested this:

var xmlhttp;
xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET", "http://test.local/append.php", true);
xmlhttp.send();

But once I get to the script task containing the above code, Tasklist prompts that XMLHttpRequest is not found.


Solution

  • Depending on your Java version you either use the Rhino (until Java 7) or Nashorn (since Java 8) Javascript engine. Both have no concept of XmlHttpRequest as you know it from Javascript engines in web browsers. So you have to use a library which allows you to send HTTP Requests. This Post links a XmlHttpRequest implementation for Rhino.