Issue in implementing external tasks using Javascript "Polling failed with undefined"

I am trying to follow the quick start guide to create a flow with service task (Executing automated steps (2/6) | docs.camunda.org). When I try to run the node.js script with node ./worker.js I get error “polling failed with undefined”. My process engine is running, I am able to deploy and execute processes with user task and business rule tasks.

Configuration:
Mac - OS Mojave v10.14.3
Node.js - 10.15.3
java - 11.0.1
Logs -
Catalin.out
12-Mar-2019 17:34:16.375 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [/Users/kh2406/Downloads/Camunda/camunda-bpm-ee-tomcat-7.10.3-ee/server/apache-tomcat-9.0.12/webapps/engine-rest]
12-Mar-2019 17:34:16.496 FINE [main] org.apache.jasper.servlet.TldScanner.scanResourcePaths No TLD files were found in resource path [/WEB-INF/].
12-Mar-2019 17:34:16.565 SEVERE [main] org.apache.catalina.core.StandardContext.startInternal One or more Filters failed to start. Full details will be found in the appropriate container log file
12-Mar-2019 17:34:16.567 SEVERE [main] org.apache.catalina.core.StandardContext.startInternal Context [/engine-rest] startup failed due to previous errors
12-Mar-2019 17:34:16.585 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/Users/kh2406/Downloads/Camunda/camunda-bpm-ee-tomcat-7.10.3-ee/server/apache-tomcat-9.0.12/webapps/engine-rest] has finished in [210] ms

For Further logs - GitHub - RahulVerma1990/Camunda-Logs: Logs

What container/application server is your process engine running on?

Also - can you post the code for your worker?

Tomcat 9.0.12

worker.js
const { Client, logger } = require(‘camunda-external-task-client-js’);

// configuration for the Client:
// - ‘baseUrl’: url to the Process Engine
// - ‘logger’: utility to automatically log important events
// - ‘asyncResponseTimeout’: long polling timeout (then a new request will be issued)
const config = { baseUrl: ‘http://localhost:8080/engine-rest’, use: logger, asyncResponseTimeout: 50000 };

// create a Client instance with custom configuration
const client = new Client(config);

// susbscribe to the topic: ‘charge-card’
client.subscribe(‘charge-card’, async function({ task, taskService }) {
// Put your business logic here

// Get a process variable
const amount = task.variables.get(‘amount’);
const item = task.variables.get(‘item’);

console.log(Charging credit card with an amount of ${amount}€ for the item '${item}'...);

// Complete the task
await taskService.complete(task);
});

I was able to get this working by replacing some single quotes with double quotes

const { Client, logger } = require("camunda-external-task-client-js");

// configuration for the Client:
// - ‘baseUrl’: url to the Process Engine
// - ‘logger’: utility to automatically log important events
// - ‘asyncResponseTimeout’: long polling timeout (then a new request will be issued)
const config = { baseUrl: "http://localhost:8080/engine-rest", use: logger, asyncResponseTimeout: 50000 };

// create a Client instance with custom configuration
const client = new Client(config);

// susbscribe to the topic: ‘charge-card’
client.subscribe("charge-card", async function({ task, taskService }) {
// Put your business logic here

// Get a process variable
const amount = task.variables.get("amount");
const item = task.variables.get("item");

console.log("Charging credit card with an amount of ${amount}€ for the item '${item}'...");

// Complete the task
await taskService.complete(task);
});

I am still seeing “polling failed with undefined” with this updated worker.js

and there’s one more problem:
When I am trying to deploy any workflow from modeler it gives me error
“Error: invalid json response body at http://localhost:8080/engine-rest/deployment/create reason: Unexpected end of JSON input”

but i am able to deploy the same workflow from cockpit.

I have also uploaded the latest logs at https://github.com/RahulVerma1990/Camunda-Logs

According to your logs you’re already running something on your local 8080 port, which would explain the issues you’re having.

So you either need to change the post your camunda distro is using or close down the other system using that port

Hi Niall,
Checked my processes and it looks like Camunda is running on port 8080.

kh2406-temp:charge-card-worker kh2406$ lsof -i :8080 | grep LISTEN
java 96328 kh2406 65u IPv6 0x561079e119df9563 0t0 TCP *:http-alt (LISTEN)
kh2406-temp:charge-card-worker kh2406$ ps -ef 96328
UID PID PPID C STIME TTY TIME CMD
545091890 96328 1 0 11:29AM ?? 0:37.21 /Library/Java/JavaVirtualMachines/jdk-11.0.1.jdk/Contents/Home/bin/java -Djava.util.logging.config.file=/Users/kh2406/Downloads/Camunda/camunda-bpm-ee-tomcat-7.10.3-ee/server/apache-tomcat-9.0.12/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djdk.tls.ephemeralDHKeySize=2048 -Djava.protocol.handler.pkgs=org.apache.catalina.webresources -Dorg.apache.catalina.security.SecurityListener.UMASK=0027 -Xmx512m -XX:MaxPermSize=256m -XX:PermSize=256m -Dignore.endorsed.dirs= -classpath /Users/kh2406/Downloads/Camunda/camunda-bpm-ee-tomcat-7.10.3-ee/server/apache-tomcat-9.0.12/bin/bootstrap.jar:/Users/kh2406/Downloads/Camunda/camunda-bpm-ee-tomcat-7.10.3-ee/server/apache-tomcat-9.0.12/bin/tomcat-juli.jar -Dcatalina.base=/Users/kh2406/Downloads/Camunda/camunda-bpm-ee-tomcat-7.10.3-ee/server/apache-tomcat-9.0.12 -Dcatalina.home=/Users/kh2406/Downloads/Camunda/camunda-bpm-ee-tomcat-7.10.3-ee/server/apache-tomcat-9.0.12 -Djava.io.tmpdir=/Users/kh2406/Downloads/Camunda/camunda-bpm-ee-tomcat-7.10.3-ee/server/apache-tomcat-9.0.12/temp org.apache.catalina.startup.Bootstrap start

I tried killing and restarting the engine. Still not working.

According to the logs you posted when tomcat is starting it’s throwing a whole bunch of errors including:

Caused by: java.net.BindException: Address already in use
	at java.base/sun.nio.ch.Net.bind0(Native Method)
	at java.base/sun.nio.ch.Net.bind(Net.java:461)
	at java.base/sun.nio.ch.Net.bind(Net.java:453)
	at java.base/sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:227)
	at java.base/sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:80)
	at org.apache.tomcat.util.net.NioEndpoint.initServerSocket(NioEndpoint.java:236)
	at org.apache.tomcat.util.net.NioEndpoint.bind(NioEndpoint.java:210)
	at org.apache.tomcat.util.net.AbstractEndpoint.init(AbstractEndpoint.java:1044)
	at org.apache.coyote.AbstractProtocol.init(AbstractProtocol.java:540)
	at org.apache.coyote.http11.AbstractHttp11Protocol.init(AbstractHttp11Protocol.java:74)
	at org.apache.catalina.connector.Connector.initInternal(Connector.java:932)
... 13 more

Which indicates that you might have something else - not the engine - on that port. the worker does not run on port 8080 it simply polls that port.

even when I free up the port it is still giving me error.

kh2406-temp:charge-card-worker kh2406$ lsof -i:8080

kh2406-temp:charge-card-worker kh2406$ npm init -y

Wrote to /Users/kh2406/charge-card-worker/package.json:

{

“name”: “charge-card-worker”,

“version”: “1.0.0”,

“main”: “index.js”,

“scripts”: {

“test”: “echo "Error: no test specified" && exit 1”

},

“keywords”: ,

“author”: “”,

“license”: “ISC”,

“dependencies”: {

“camunda-external-task-client-js”: “^1.1.1”

},

“devDependencies”: {},

“description”: “”

}

kh2406-temp:charge-card-worker kh2406$ npm install -s camunda-external-task-client-js

  • camunda-external-task-client-js@1.1.1

updated 1 package and audited 61 packages in 1.918s

found 0 vulnerabilities

kh2406-temp:charge-card-worker kh2406$ node ./worker.js

polling

✓ subscribed to topic charge-card

polling

:heavy_multiplication_x: polling failed with undefined

polling

:heavy_multiplication_x: polling failed with undefined

polling

:heavy_multiplication_x: polling failed with undefined

polling

:heavy_multiplication_x: polling failed with undefined

^C

Blockquote

**its when I start the camunda server, the port is occupied.

kh2406-temp:charge-card-worker kh2406$ lsof -i:8080
kh2406-temp:charge-card-worker kh2406$ sh /Users/kh2406/Downloads/Camunda/camunda-bpm-ee-tomcat-7.10.3-ee/start-camunda.sh
starting camunda BPM platform on Tomcat Application Server
Using CATALINA_BASE: /Users/kh2406/Downloads/Camunda/camunda-bpm-ee-tomcat-7.10.3-ee/server/apache-tomcat-9.0.12
Using CATALINA_HOME: /Users/kh2406/Downloads/Camunda/camunda-bpm-ee-tomcat-7.10.3-ee/server/apache-tomcat-9.0.12
Using CATALINA_TMPDIR: /Users/kh2406/Downloads/Camunda/camunda-bpm-ee-tomcat-7.10.3-ee/server/apache-tomcat-9.0.12/temp
Using JRE_HOME: /Library/Java/JavaVirtualMachines/jdk-11.0.1.jdk/Contents/Home
Using CLASSPATH: /Users/kh2406/Downloads/Camunda/camunda-bpm-ee-tomcat-7.10.3-ee/server/apache-tomcat-9.0.12/bin/bootstrap.jar:/Users/kh2406/Downloads/Camunda/camunda-bpm-ee-tomcat-7.10.3-ee/server/apache-tomcat-9.0.12/bin/tomcat-juli.jar
Tomcat started.
kh2406-temp:charge-card-worker kh2406$ lsof -i:8080
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
java 995 kh2406 65u IPv6 0x561079e100940223 0t0 TCP *:http-alt (LISTEN)
kh2406-temp:charge-card-worker kh2406$ -e We are sorry… We tried all we could do but we couldn’t locate your default browser…
If you want to see our default website please open your browser and insert this URL:
ilsof -i:8080
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
java 995 kh2406 65u IPv6 0x561079e100940223 0t0 TCP *:http-alt (LISTEN)

So, i was able to start and run your worker without any problems locally myself… so lets go through each component to find the issue.

First if Camunda is running correctly you should be able to go to this link
http://localhost:8080/ and see the tomcat homepage
then you should be able to go to this link
http://localhost:8080/camunda
and you should see tasklist and then log in.

Can you confirm that this is working first?

Yup…both are working
I was even able to execute a process with user tasks and business rule tasks

Alrighty,
So now i want to check that the REST API is working correctly.
Can you run the following in Postman or in your browser and get a result?
http://localhost:8080/engine-rest/external-task

no… HTTP Status 404 – Not Found

AH-HA!
We’ve found the problem :slight_smile: - your REST API is missing.
Have you changed anything about the regular distro?
Did you install camunda manually to tomcat?

I extracted the zip file and started camunda in terminal by running command
kh2406-temp:~ kh2406$ sh /Users/kh2406/Downloads/Camunda/camunda-bpm-ee-tomcat-7.10.3-ee/start-camunda.sh

I am using an enterprise trial version

Hi Niall,

The Problem is occurring only in enterprise version. I tried with the community version and I was able to execute the steps.

In enterprise the tomcat server starts, cockpit and tasklist apps are working fine, but the engine rest is not starting. So there is a problem in enterprise installation.

It’s a really strange problem that i’ve never come across before.
There wouldn’t be too much of a difference between the CE and EE REST API so it’s even stranger that the CE version works.

The version I was using was 7.10.3-ee Apache Tomcat. And its only the engine-rest, that’s hitting issue while starting other apps are very well running.