IncidentHandler - Using Spring Boot

Hey there,

I’m currently trying to use the IncidentHandler to add custom actions if an incident occures.
I tried to simply override the FailedJobIncidentHandler:

import org.camunda.bpm.engine.impl.incident.IncidentContext;
import org.camunda.bpm.engine.impl.incident.IncidentHandler;
import org.camunda.bpm.engine.impl.persistence.entity.IncidentEntity;
import org.camunda.bpm.engine.runtime.Incident;

public class FailedJobIncidentHandler extends Object implements IncidentHandler {
@Override
public String getIncidentHandlerType() {
return null;
}

@Override
public Incident handleIncident(IncidentContext context, String message) {
System.out.println(“INCIDENT TEST”);
IncidentEntity incidentEntity = (IncidentEntity) handleIncident(context, message);

return incidentEntity;

}

@Override
public void resolveIncident(IncidentContext context) {

}

@Override
public void deleteIncident(IncidentContext context) {

}
}`

Is this possible at all? Or am i searching in the wrong place?
Cause my console doesn’t want to outprint my logging…

1 Like

Hi @Brosowski,

you are on the right track, but you should return an incident type that should be handled here, like Incident.FAILED_JOB_HANDLER_TYPE.

How did you register the handler in the process engine and which kind of engine and platform do you use (embedded or shared, spring-boot or application server or JUnit test)?

Cheers, Ingo

1 Like

Hi @Ingo_Richtsmeier,

thank you for the fast answer!!
I tried to register it with a IncidentHandlerPlugin but i don’t know if i need to do more than that…
How can i activate them?

import de.ipd.handler.FailedJobIncidentHandler;
import org.camunda.bpm.engine.impl.cfg.AbstractProcessEnginePlugin;
import org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl;
import org.camunda.bpm.engine.impl.incident.IncidentHandler;

import java.util.ArrayList;

public class IncidentHandlerProcessEnginePlugin extends AbstractProcessEnginePlugin {
@Override
public void preInit(ProcessEngineConfigurationImpl processEngineConfiguration) {
ArrayList customIncidentHandlers = new ArrayList();
customIncidentHandlers.add(new FailedJobIncidentHandler());
processEngineConfiguration.setCustomIncidentHandlers(customIncidentHandlers);
}
}

I’m using embedded and springboot.

Hi @Brosowski,

I think you’re missing the magic spring boot annotation in your class: https://docs.camunda.org/manual/7.13/user-guide/spring-boot-integration/configuration/#adding-additional-configurations

Hope this helps, Ingo

2 Likes

Hi @Ingo_Richtsmeier,

thank you very much it finally works!!
That was the missing part :slight_smile:

Best regards, Benjamin Brosowski