AnsweredAssumed Answered

use java dynamic proxy to implement custom taskService

Question asked by richard9527 on Oct 26, 2017

   Hello, I am new to Activiti and I am trying to use my custom taskService to handle request related to tasks.I use dynamic proxy to achieve it , handle most of request providing to delegate taskService and just handle a few by my service.

   In order to get proper taskService, I must buildEngine firstly and then get taskService.otherwise , if I get taskService from ProcessEngineConfigurationImpl, it leads to some variables not initialized.My code is shown below:



ProcessEngineConfigurationImpl processEngineConfiguration = (ProcessEngineConfigurationImpl) ProcessEngineConfiguration.createProcessEngineConfigurationFromResourceDefault();

processEngine = processEngineConfiguration.buildProcessEngine();

TaskService taskService = processEngine.getTaskService();


Class[] interfaces = new Class[]{TaskService.class};

TaskServiceProxy taskServiceProxy = new TaskServiceProxy(taskService);
TaskService proxyService = (TaskService) Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(),interfaces,taskServiceProxy);
processEngine = processEngineConfiguration.buildProcessEngine();



     The code works, however I don't if this way is proper and it will cause some problem unknown for I build the engine twice.Are there any more elegant way to achieve the same function?


     Thanks in advance

      Best regard