Hello, I’m creating a new thread about this issue because despite mentioning the same errors, the other solutions didn’t seem to apply to my case…
From time to time, I get the errors “ENGINE-09008 Exception while instantiating class” together with “ENGINE-09017 Cannot load class” when a process instance tries to call a Java class via TaskListener.
I say ‘from time to time’, because often it works. But, for reasons I cannot explain, it suddenly stops working and I get these errors.
I’m running Camunda Community 7.11, Java 1.8, and both the Java classes and BPMN models are deployed via Process Application (using Jenkins).
The models are updated somewhat frequently, and we create new models all the time. Therefore, this Process Application is deployed very often. But, this particular class (the one Camunda is unable to find) is not updated. It’s a simple class that calls a service to send an e-mail. And, due its nature, this class is used by several different processes.
I did notice that when this problem occurs, if I re-deploy the process that happened to call this class (no actual change, just moved the end event to the right a bit), the problem seem to go away. But, as mentioned, eventually I get this error again.
I’m at a loss as to what to investigate, change, or configure.
I’ve uploaded the model and here’s the class I’ve mentioned:
package br.gov.finep.processosCredito;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import org.apache.commons.lang3.StringUtils;
import org.camunda.bpm.engine.delegate.DelegateTask;
import org.camunda.bpm.engine.delegate.Expression;
import org.camunda.bpm.engine.delegate.TaskListener;
import org.camunda.bpm.engine.task.IdentityLink;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.HttpStatusCodeException;
import org.springframework.web.client.RestTemplate;
import com.fasterxml.jackson.databind.ObjectMapper;
import br.gov.finep.processosCredito.servicos.ServicoCreditoEnum;
public class EnviarEmail implements TaskListener {
private static final Logger LOGGER = LoggerFactory.getLogger(EnviarEmail.class);
private static final String CODIGO_ERRO = "ERRO_EMAIL";
private Expression tipo;
@Override
public void notify(DelegateTask delegateTask) {
try {
Set<String> loginsUsuarios = usuarios(delegateTask);
Set<String> gruposUsuarios = gruposUsuarios(delegateTask);
Map<String, Object> body = new HashMap<>();
inserirParametro(body, "idProjeto", delegateTask.getVariable("p_idProjeto"));
inserirParametro(body, "loginsUsuarios", loginsUsuarios);
inserirParametro(body, "gruposUsuarios", gruposUsuarios);
inserirParametro(body, "tipo", tipo.getValue(delegateTask).toString());
HttpHeaders headers = new HttpHeaders();
headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
headers.setContentType(MediaType.APPLICATION_JSON_UTF8);
HttpEntity<String> entity = new HttpEntity<String>(new ObjectMapper().writeValueAsString(body), headers);
String url = ServicoCreditoEnum.ENVIAR_EMAIL.getURI();
ResponseEntity<String> resposta = new RestTemplate().exchange(url, HttpMethod.POST, entity, String.class);
if (resposta.getStatusCode() != HttpStatus.OK) {
throw new Exception(resposta.getBody());
}
} catch (HttpStatusCodeException e) {
LOGGER.error(CODIGO_ERRO + ":: " + e.getResponseBodyAsString());
} catch (Exception e) {
LOGGER.error(CODIGO_ERRO + ":: " + e.getMessage());
}
}
private static void inserirParametro(Map<String, Object> body, String nomeParametro, Object valor) {
if (!(valor instanceof Collection) && valor != null || valor instanceof Collection && !((Collection<?>) valor).isEmpty()) {
body.put(nomeParametro, valor);
}
}
private static Set<String> usuarios(DelegateTask delegateTask) {
Set<String> usuarios = new HashSet<>();
String assignee = delegateTask.getAssignee();
if (!StringUtils.isBlank(assignee)) {
usuarios.add(assignee);
}
for (IdentityLink candidate : delegateTask.getCandidates()) {
String candidateUserId = candidate.getUserId();
if (!StringUtils.isBlank(candidateUserId)) {
usuarios.add(candidateUserId);
}
}
return usuarios;
}
private static Set<String> gruposUsuarios(DelegateTask delegateTask) {
Set<String> gruposUsuarios = new HashSet<>();
for (IdentityLink candidate : delegateTask.getCandidates()) {
String candidateGroupId = candidate.getGroupId();
if (!StringUtils.isBlank(candidateGroupId)) {
gruposUsuarios.add(candidateGroupId);
}
}
return gruposUsuarios;
}
}