AnsweredAssumed Answered

activity - get service registry in java class

Question asked by dmralfing on Mar 20, 2014
Latest reply on Mar 26, 2014 by dmralfing
Somebody could tell me what I´m doing wrong to get the service registry in the java class, or
well any way to get it? - I have tryed using the solution I read in the forum topic :
https://forums.alfresco.com/forum/developer-discussions/workflow/proper-way-implement-custom-tasklistener-activiti-02082012-1433
..but I´m afraid I´m doing something wrong due to I´m a beginer in activity, so I would apreciate if somebody help me..
This is the Java code:

<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="Examples">
  <process id="MyTest" name="MyTest">
   <startEvent id="theStart" name="Start">
   </startEvent>
    <serviceTask id="javaService" name="Java service invocation" activiti:class="org.activiti.examples.bpmn.test.manager2.SetterTest">
      <extensionElements>
        <activiti:field name="text">
          <activiti:string>Success</activiti:string>
        </activiti:field>
        <activiti:taskListener event="create" class="org.activiti.examples.bpmn.test.manager2.SetterTest">
        </activiti:taskListener>
      </extensionElements>
    </serviceTask>
   <userTask id="usertask1" name="User Task" activiti:candidateGroups="user"></userTask>
   
   <endEvent id="theEnd" name="End"></endEvent>
    <sequenceFlow id="flow1" name="" sourceRef="theStart" targetRef="javaService"></sequenceFlow>
    <sequenceFlow id="flow2" name="" sourceRef="javaService" targetRef="usertask1"></sequenceFlow>   
    <sequenceFlow id="flow4" name="" sourceRef="usertask1" targetRef="theEnd"></sequenceFlow>
  </process>
</definitions>


..and this is my class that unaffortunately doesn´t get the serviceRegistry..

package org.activiti.examples.bpmn.test.manager2;
import …
……….
public class SetterTest implements JavaDelegate {

   private static final String VARIABLE_NAME = "testVariable";
   private Expression text;
   ServiceRegistry serviceRegistry=null;
   //public ServiceRegistry getServiceRegistry() {return serviceRegistry;}
   protected ServiceRegistry getServiceRegistry() {

        ProcessEngineConfigurationImpl config = Context.getProcessEngineConfiguration();
        if (config != null) {
            ServiceRegistry registry = (ServiceRegistry) config.getBeans().get(ActivitiConstants.SERVICE_REGISTRY_BEAN_KEY);
            if (registry == null) {
                throw new RuntimeException(
                            "Service-registry not present in ProcessEngineConfiguration beans, expected ServiceRegistry with key" +
                            ActivitiConstants.SERVICE_REGISTRY_BEAN_KEY);
            }
            else
               System.out.println("————— config =null");
            return registry;
        }

        throw new IllegalStateException("No ProcessEngineCOnfiguration found in active context");

    }   
   public void setServiceRegistry(ServiceRegistry serviceRegistry) {this.serviceRegistry = serviceRegistry;}
   public void execute(DelegateExecution execution)
   {
         if (serviceRegistry==null)
            System.out.println("serviceRegistry is null!!");
   }
}

Thank you so much!

Outcomes