In a sample project we tried to use an external service task handled by the JavaScript task client, using v7.10 and camunda-external-task-client-js v1.1.1. The client was supposed to subscribe a topic and poll Camunda.
Our task client tried to pass a process variable containing a json string of roundabout 17KB - a list of news items.
We were unable to let the js taskclient send JSON data like below:
const {Client, logger, Variables} = require("camunda-external-task-client-js"),
request = require('request'),
path = require('path'),
camCommon = require(path.resolve(__dirname, "./common.js"));
// rest url is for spring-boot, differs from war
const config = {baseUrl: "http://localhost:8095/rest",
use: logger, asyncResponseTimeout: 5000};
const client = new Client(config);
client.subscribe("news", async function ({task, taskService}) {
const options = {
url: 'https://example.com/api/news',
method: 'GET'
};
request(options, function (err, res, body) {
const processVariables = new Variables();
processVariables.set("news", JSON.parse(body);
taskService.complete(task, processVariables);
});
});
due to this error:
019-01-27 11:52:49.722 WARN 22306 --- [nio-8095-exec-9] ExceptionHandler : org.camunda.bpm.engine.rest.exception.RestException: Unsupported value type 'json'
at org.camunda.bpm.engine.rest.dto.VariableValueDto.toTypedValue(VariableValueDto.java:94)
at org.camunda.bpm.engine.rest.dto.VariableValueDto.toMap(VariableValueDto.java:153)
The js taskclient readme points to About JSON & Date Variables which leads you to believe that the client can pass JSON. However it canât, because JSON is not a known type in ValueTypeResolverImpl
:
public ValueTypeResolverImpl() {
addType(BOOLEAN);
addType(BYTES);
addType(DATE);
addType(DOUBLE);
addType(INTEGER);
addType(LONG);
addType(NULL);
addType(SHORT);
addType(STRING);
addType(OBJECT);
addType(NUMBER);
addType(FILE);
}
Is that an error in the documentation or did we miss something? I know that the browser can define variables of type json and submit them to the engine, shouldnât external task clients or clients posting data to post-message be able to do likewise?
In an attempt to work around this, we changed our code so that the variable was not a JavaScript object, but a plain json String.
That failed, too, apparently because Camunda tries to persist the entire JSON in a database table which doesnât have enough space for the data.
Caused by: org.h2.jdbc.JdbcBatchUpdateException: Value too long for column "TEXT_ VARCHAR(4000)"
So the limit for string variables is VARCHAR(4000).
I have seen Can't set a large size file as a process variable!, but a 17kB JSON does not seem to be an excessive amount of data for backend operations.
One possible workaround is to define a Java bean which matches the JSON and pass a variable of type âobjectâ with a value that is a JSON String from the taskclient (also see related issue)
But Is there any advice for pure JSON lovers?