8 Replies Latest reply on Sep 13, 2008 1:23 AM by svadu

    Bijection and jBpm Node actions

    mtorres

      Hi,


      I'm trying to work on a jBpm process definition proof of concept that is integrated with Seam. When a node element that contains an action is invoked through el, bijection does not seem to work.


      Example



      <node name="completeProcessing">
              <action expression="#{loanProcessing.complete}">/action>       
              <transition name="end" to="endState"></transition>
      </node>
      



      loanProcessing.complete gets called but injection of process variables does not work. This scenario works on task nodes though.


      LoanProcessing class code is shown below.


      Any help is greatly appreciated.



      @Name("loanProcessing")
      public class LoanProcessingAction {
              
              private Long loanId;    
              
              @Logger
              private Log logger;
              
              
              private ProcessInstance processInstance;
                      
              private TaskInstance taskInstance;
              
              @In(required=false)
              public void setTaskInstance(TaskInstance taskInstance) {
                      this.taskInstance = taskInstance;
              }
              @In(required=false)
              public void setProcessInstance(ProcessInstance processInstance) {
                      this.processInstance = processInstance;
              }
              @In(required=false)
              public void setLoanId(Long loanId) {
                      this.loanId = loanId;
              }
                              
              @StartTask
              @EndTask(transition="approved")
              public void completeSelected(){         
                      System.out.println("test " + loanId);
              }
              
              @StartTask
              @EndTask(transition="cancel")
              public void cancelSelected(){
                      System.out.println("test " + loanId );
              }
              
              @Transition("end")
              public void complete(){         
                      logger.info("Loan {0} has been completed.", loanId);
              }
              
              @Transition("end")
              public void cancel(){
                      logger.info("Loan {0} has been cancelled.", loanId);
              }
      }
      
      


        • 1. Re: Bijection and jBpm Node actions
          mtorres

          I continued playing around with the scenario, looks like the problem is not necessarily a node action, but when actions are called when deeper jbpm nodes are traversed.



           <start-state name="start">
                  <transition to="startNode"/>
              </start-state>
              
              <node name="startNode">
                    <action expression="#{loanProcessing.startNodeAction}"></action>     
                    <transition name="next" to="secondNode"></transition>
               </node>
               
               <node name="secondNode">
                    <action expression="#{loanProcessing.secondNodeAction}"></action>     
                    <transition name="next" to="initialContact"></transition>
               </node>



          For the snippet above, bijection works when loanProcessing.startNodeAction gets called but does not happen when loanProcessing.secondNodeAction is invoked.

          • 2. Re: Bijection and jBpm Node actions
            mtorres

            Did some more digging on this, even Decision nodes has this problem. During debug, I noticed that seam(through SeamELResolver, Namespace and Context) is pulling out the component(loanProcessing) from the method context. This caused the BijectionInterceptor not to be invoked, hence the loanId was not set.


            The relevant interceptor chain is as follows:
            ...MethodContextInterceptor -- BusinessProcessInterceptor -- ConversationInterceptor -- BijectionInterceptor...


            Is there any solution/fix to this, Or any workarounds? I understand that splitting the action component to multiple classes may sort of work, but I'd prefer to keep things in the same class.


            Any insight on this is appreciated.

            • 3. Re: Bijection and jBpm Node actions
              mtorres

              I just wanted to share what I have done to work around this problem.


              I created an interceptor that sits between MethodContextInterceptor and BusinessProcessInterceptor to remove the component from the MethodContext. This interceptor is only activated on jBpmHandlers, by means of an annotation.


              The relevant codes are


              Interceptor


              @SuppressWarnings("serial")
              @Interceptor(stateless = true, within = MethodContextInterceptor.class,

              public class JbpmHandlerInterceptor extends AbstractInterceptor{
                   @AroundInvoke
                   public Object aroundInvoke(InvocationContext ctx) throws Exception {          
                        Component comp = getComponent();
                        if (comp!=null){
                             String name = comp.getName();
                             Contexts.getMethodContext().set(name,null);
                        }
                        Object ret = ctx.proceed();          
                        return ret;
                   }
              }


              Annotation


              @Target(TYPE)
              @Retention(RUNTIME)
              @Interceptors(JbpmHandlerInterceptor.class)
              public @interface JbpmHandler {
              }


              jBpm Handler class


              @Name("loanProcessing")
              @JbpmHandler
              public class LoanProcessingAction {
              ...
              }


              It worked in my test scenario so far, but since I have no deep knowledge of the framework, I cant tell if there's a scenario that this will break. Do you foresee any problems related to this approach?

              • 4. Re: Bijection and jBpm Node actions
                mtorres

                Just reformatting my previous post.



                @SuppressWarnings("serial")
                @Interceptor(stateless = true, within = MethodContextInterceptor.class,
                
                public class JbpmHandlerInterceptor extends AbstractInterceptor{
                     @AroundInvoke
                     public Object aroundInvoke(InvocationContext ctx) throws Exception {          
                          Component comp = getComponent();
                          if (comp!=null){
                               String name = comp.getName();
                               Contexts.getMethodContext().set(name,null);
                          }
                          Object ret = ctx.proceed();          
                          return ret;
                     }
                }




                @Target(TYPE)
                @Retention(RUNTIME)
                @Interceptors(JbpmHandlerInterceptor.class)
                public @interface JbpmHandler {
                }




                @Name("loanProcessing")
                @JbpmHandler
                public class LoanProcessingAction {
                ...
                }




                • 5. Re: Bijection and jBpm Node actions
                  ophidian

                  I've ran into this same issue.  While your solution does seem to fix most of the problem, bijection still fails for any components added to the business process context during the first node execution.


                  I'm new to both Seam and JBPM, but will try to play around with this a little more before conceding and splitting up my action.  Here's what appears to be the relevant bug (which you've already found) for others if they happen upon this same issue: JBSEAM-3095

                  • 6. Re: Bijection and jBpm Node actions
                    ophidian

                    Sorry, I had a misconfiguration on my part.  The above interceptor does appear to be a full solution to the issue.  From what I understand, the whole idea of having the MethodContextInterceptor to not contain the proxied object is to prevent some horribleness when the component is invoked recursively.  So using this JbpmHandler appears to be a solid choice when used carefully.  Thanks for posting your solution.

                    • 7. Re: Bijection and jBpm Node actions
                      c0upal

                      Hi.


                      Your workaround works for me.


                      I have a problem where i need a processInstance object to be injected on a method, and needs to signal to a transition. 


                      Your workaround made me successfully inject a processInstance object to my Bean.


                      see post: http://www.seamframework.org/Community/JbpmNodeNodeTypeWithActionExpressionDoesNotContinue


                      Thanks for your posting.

                      • 8. Re: Bijection and jBpm Node actions

                        Might be a good idea for a JIRA issue...