cancel
Showing results for 
Search instead for 
Did you mean: 

JavaDelegate injecting filed

nuthan
Champ in-the-making
Champ in-the-making
Hi I have a Spring bean which acts as Service delegate class. I am having trouble in injecting a filed .. Getting following error
Field definition uses unexisting field 'className' on class com.sun.proxy.$Proxy229

My delegate Class
————–

@Component("agileIntegrationDelegate")
@Transactional
public class AgileIntegrationOutBoundService implements JavaDelegate {
      
      public Expression entity;
      public Expression itemNumber;
      public Expression className;
      public Expression recipient;
      
      
      @Autowired
      @Qualifier("dataSource")
      private DataSource dataSource;
      
      
       @Override
      public void execute(DelegateExecution execution) throws Exception {
          try {
             execution.getVariables();
             String _class = (String) className.getValue(execution);
             String item = (String) itemNumber.getValue(execution);
             String to = (String) recipient.getValue(execution);
             AbstractEntity _entity = (AbstractEntity)entity.getValue(execution);
             
             /*String _class = (String) execution.getVariable("className");
             String item = (String) execution.getVariable("itemNumber");
             String to =  (String) execution.getVariable("recipient");
             AbstractEntity _entity = (AbstractEntity)execution.getVariable("entity");
             */
             switch(_class)
             {
             case "TECHNOLOGY":
                Technology tech = (Technology) _entity;
                System.out.println(tech);
                break;
             default:
                break;
             }
             System.out.println(_class + item + to);
          } catch (Exception e) {
             e.printStackTrace();
            //throw new BpmnError("BusinessExceptionOccurred");
          }
         
      }
}




My BPM xml
————

<process id="agileIntegration" name="Agile Out Bound integration" isExecutable="true">
    <startEvent id="startevent1" name="Start"></startEvent>
    <sequenceFlow id="flow1" sourceRef="startevent1" targetRef="servicetask1" />
    <serviceTask id="servicetask1" name="Java Service to send data" activiti:delegateExpression="${agileIntegrationDelegate}">
        <extensionElements>
               <activiti:field name="className">
                  <activiti:string>${className}</activiti:string>
               </activiti:field>
               <activiti:field name="itemNumber">
                  <activiti:string>${itemNumber}</activiti:string>
               </activiti:field>
               <activiti:field name="recipient">
                  <activiti:string>${recipient}</activiti:string>
               </activiti:field>
               <activiti:field name="entity">
                     <activiti:expression>${entity}</activiti:expression>
             </activiti:field>
        </extensionElements>
    </serviceTask>
    <sequenceFlow id="flow2" sourceRef="servicetask1" targetRef="endevent1"></sequenceFlow>
   
    <endEvent id="endevent1" name="End"></endEvent>
  </process>



and I am starting workflow with

String process = "agileIntegration";
         Map<String, Object> variables = new HashMap<String, Object>();
         variables.put("itemNumber", itemNumber);
         variables.put("className", className);
         variables.put("entity", entity);
         variables.put("recipient", "nuthankumar.mallavaram@globalfoundries.com");
         //variables.put("owner", SecurityUtils.getCurrentLogin());
         //variables.put("variables", new String[] {"1234"});
         runtimeService.startProcessInstanceByKey(process, variables);



If I use direct class instead of spring bean , its getting all variables with out any problem. But My requirement is to inject bean
1 ACCEPTED ANSWER

anilmann
Confirmed Champ
Confirmed Champ
This seems to be not possbile as activiti uses different class loader when it comes to Java Service Calls.
You need to create your objects in class itself.
You can try adding Application Context object as a process instance variable and retrieve beans from that application object.

Another option is using groovy script and calling your class method from that script. You class is already configured as spring bean so object will be available to activiti for execution.

Please let me know if this idea works.


Edit 1: Please ignore above ideas.

There are 2 ways to achieve this.
1. Use Delegate Expression
2. Use Expression.

View answer in original post

1 REPLY 1

anilmann
Confirmed Champ
Confirmed Champ
This seems to be not possbile as activiti uses different class loader when it comes to Java Service Calls.
You need to create your objects in class itself.
You can try adding Application Context object as a process instance variable and retrieve beans from that application object.

Another option is using groovy script and calling your class method from that script. You class is already configured as spring bean so object will be available to activiti for execution.

Please let me know if this idea works.


Edit 1: Please ignore above ideas.

There are 2 ways to achieve this.
1. Use Delegate Expression
2. Use Expression.