Getting error while doing base64 encoding/decoding using camunda modeler

537 views Asked by At

I am getting the following error while converting string to base64 encoding/decoding using Camunda.

Error:

Cannot instantiate process definition dciworkflow:1:f44c5806-2f38-11eb-9feb-0242ac15000e: Unable to evaluate script while executing activity 'Activity_nodetoken' in the process definition with id 'dciworkflow:1:f44c5806-2f38-11eb-9feb-0242ac15000e':<eval>:1:0 Expected an operand but found import\nimport java.util.Base64;\n^ in <eval> at line number 1 at column number 0

I am explaining my code below.

import java.util.Base64;
var header = new java.util.HashMap();
print(":::From node manager::");
var username = S(S(response).prop('data')).prop('username').value();
var password = S(S(response).prop('data')).prop('password').value();
print('user data', username, password);
byte[] actualByte= Base64.getDecoder().decode(password);
var enPass = new String(actualByte);
print('password', enPass);
var sample = username + ':' + enPass;
var base64 = Base64.getEncoder().encodeToString(sample.getBytes()); 
print('base64', base64);
header.put("Content-Type","application/json");
header.put("accept","application/json");
header.put("Authorization","Basic "+base64);
header;

Here I am using java class to base64 encode/decode my credentials from string. This code I am using inside camunda modeler. Here I need to convert string to base64 encode and decode. Please help me to resolve this issue.

1

There are 1 answers

0
tmdoit On

change first line

import java.util.Base64;

to

var Base64 = Java.type("java.util.Base64");