JobHandler interface force me override newConfiguration method on Escalation sample

I’m unable to run the sample with the current version.
It’s forcing me to override newConfiguration method and it crashes on test.
Is there another class I should extend now instead of implementing JobHandler?

public class EscalationJobHandler implements JobHandler {
	
	private static final Logger log = Logger.getLogger(EscalationJobHandler.class.getName());

	public static final String ESCALATION_JOB_HANDLER_TYPE = "escalationJob";

	@Override
	public String getType() {
		return ESCALATION_JOB_HANDLER_TYPE;
	}

	@Override
	public void execute(JobHandlerConfiguration configuration, ExecutionEntity execution, CommandContext commandContext, String arg3) {
		log.info("\n\nEscalation received! " + execution.getId() + "\n\n");
		log.info(execution.getActivity().getName());
	}

	@Override
	public JobHandlerConfiguration newConfiguration(String canonicalString) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void onDelete(JobHandlerConfiguration configuration, JobEntity jobEntity) {
		// TODO Auto-generated method stub
		
	}
}

I’m creating the Job using this code:

	log.info("create job for escalation for task " + delegateTask.getId());
	ExecutionEntity execution = (ExecutionEntity) delegateTask.getExecution();
	ProcessDefinitionEntity processDefinition = (ProcessDefinitionEntity) execution.getProcessDefinition();

	TimerEntity timer = new TimerEntity();
	timer.setExecution(execution);
	timer.setDuedate(delegateTask.getDueDate());
	timer.setJobHandlerType(EscalationJobHandler.ESCALATION_JOB_HANDLER_TYPE);
	timer.setProcessDefinitionKey(processDefinition.getKey());
	timer.setDeploymentId(processDefinition.getDeploymentId());
	
	Context.getCommandContext().getJobManager().schedule(timer);

Ont this is the error I got:

10:09:36.198 [main] ERROR org.camunda.bpm.engine.context - ENGINE-16004 Exception while closing command context: null
java.lang.NullPointerException: null
	at org.camunda.bpm.engine.impl.persistence.entity.JobEntity.getJobHandlerConfiguration(JobEntity.java:465) ~[camunda-engine-7.6.0.jar:7.6.0]
	at org.camunda.bpm.engine.impl.persistence.entity.JobEntity.execute(JobEntity.java:127) ~[camunda-engine-7.6.0.jar:7.6.0]
	at org.camunda.bpm.engine.impl.cmd.ExecuteJobsCmd.execute(ExecuteJobsCmd.java:99) ~[camunda-engine-7.6.0.jar:7.6.0]
	at org.camunda.bpm.engine.impl.cmd.ExecuteJobsCmd.execute(ExecuteJobsCmd.java:36) ~[camunda-engine-7.6.0.jar:7.6.0]
	at org.camunda.bpm.engine.impl.interceptor.CommandExecutorImpl.execute(CommandExecutorImpl.java:24) ~[camunda-engine-7.6.0.jar:7.6.0]
	at org.camunda.bpm.engine.impl.interceptor.CommandContextInterceptor.execute(CommandContextInterceptor.java:104) ~[camunda-engine-7.6.0.jar:7.6.0]
	at org.camunda.bpm.engine.impl.interceptor.ProcessApplicationContextInterceptor.execute(ProcessApplicationContextInterceptor.java:66) [camunda-engine-7.6.0.jar:7.6.0]
	at org.camunda.bpm.engine.impl.interceptor.LogInterceptor.execute(LogInterceptor.java:30) [camunda-engine-7.6.0.jar:7.6.0]
	at org.camunda.bpm.engine.impl.jobexecutor.ExecuteJobHelper.executeJob(ExecuteJobHelper.java:35) [camunda-engine-7.6.0.jar:7.6.0]
	at org.camunda.bpm.engine.impl.jobexecutor.ExecuteJobHelper.executeJob(ExecuteJobHelper.java:28) [camunda-engine-7.6.0.jar:7.6.0]
	at org.camunda.bpm.engine.impl.ManagementServiceImpl.executeJob(ManagementServiceImpl.java:115) [camunda-engine-7.6.0.jar:7.6.0]

Hi @lcrodriguez,

Have you added your EscalationJobHandler to the process engine configuration?

Cheers,
Roman

Well, implement JobHandlerConfiguration and return a new instance in newConfiguration. By the way, which sample are you referring to?

This is the sample on github:

Do you have a sample of how to implement it?

How about

public class EmptyConfiguration implements JobHandlerConfiguration {
  public String toCanonicalString() {
    return null;
  }
}

?

Not working. Same error.
Maybe is something wrong in my test?

/**
 * Test case starting an in-memory database-backed Process Engine.
 */
public class InMemoryH2Test {

  @ClassRule
  @Rule
  public static ProcessEngineRule rule = TestCoverageProcessEngineRuleBuilder.create().build();

  private static final String PROCESS_DEFINITION_KEY = "camunda-plugins";

  static {
    LogFactory.useSlf4jLogging(); // MyBatis
  }

  @Before
  public void setup() {
    init(rule.getProcessEngine());
    
    Group g = processEngine().getIdentityService().newGroup("analyst");
    g.setType("TYPE");
    processEngine().getIdentityService().saveGroup(g);
    
    User u = processEngine().getIdentityService().newUser("john");
    u.setEmail("aaaa@gmail.com");
    u.setFirstName("Leo");
    u.setLastName("Rodriguez");
    u.setPassword("12345678");
    processEngine().getIdentityService().saveUser(u);

    u = processEngine().getIdentityService().newUser("peter");
    u.setEmail("leonardo.rodriguez@nybblegroup.com");
    u.setFirstName("Peter");
    u.setLastName("Rodriguez");
    u.setPassword("12345678");
    processEngine().getIdentityService().saveUser(u);

    processEngine().getIdentityService().createMembership("john", "analyst");
  }

 
  
  @Test
  @Deployment(resources = "process.bpmn")
  public void testDueDate() {
	  Date dueDate = new Date();
	  VariableMap variables = Variables.createVariables().putValue("dueDate", dueDate);

	  ProcessInstance pi = processEngine().getRuntimeService().startProcessInstanceByKey(PROCESS_DEFINITION_KEY, variables);
	  assertThat(pi).task();
	  assertThat(pi).job().hasDueDate(dueDate);
	  execute(job());
  }

}

The EscalationJobHandler is scheduled fine. The problem is the execution as far I can see.

Jan 30, 2017 10:29:26 AM com.northstarlife.camunda.EscalationTaskListener createJobForEscalation
INFO: create job for escalation for task 10

You may download a failing sample here when running the unit test:

https://www.dropbox.com/s/bkn21gvkj4y9ctc/camunda-plugins.zip?dl=0

Thanks for your help.

Hi @lcrodriguez,

As I said, you have to register your EscalationJobHandler on the process engine configuration. You can do this for example in your CommunicationProcessEnginePlugin like this:

public class CommunicationProcessEnginePlugin implements ProcessEnginePlugin {

  @Override
  public void postInit(ProcessEngineConfigurationImpl processEngineConfiguration) {
    processEngineConfiguration.getJobHandlers().put(EscalationJobHandler.ESCALATION_JOB_HANDLER_TYPE, new EscalationJobHandler());
  }

}

Then the EscalationJobHandler is invoked.

Cheers,
Roman

1 Like

Life saver! :smiley:

I guess I misunderstood what you mean with that as it was setting up in the logs.
It works now! :smiley:

Thanks for your time.