2 Replies Latest reply on Apr 28, 2010 3:49 PM by gerardons

    Process Variable cannot be casted and accessed

    gerardons

      Hi All,

       

      I'm having a problem to access a process variable in an ActionHandler. I've installed jBPM 3.2.3 (suite) and the GPD eclipse plugin, which is very nice for the deployment of the process and all its resources.

       

      The problem appears in the jbpm-console when the token moves from state named "first" to the end-state "end". The transition fires and calls de.hpi.pois.GetterAction. The ActionHandler wants to acess the process variable "appli" and then the error appears. The process variable cannot be cast (see the attached errorLog). The jbpm-console displays the error message:"Error signalling token: An exception of type "org.jbpm.graph.def.DelegationException" was thrown. The message is: de.hpi.pois.klassen.Application cannot be cast to de.hpi.pois.klassen.Application".

       

      I know that there is already a thread (http://community.jboss.org/message/377445#377445) dealing with almost the same problem, but this discussion doesn't come to an end. I hope that this discussion will get a result. Maybe you'll have an idea.

       

      It's only a guess, but maybe there are some configurations missing (maybe for the hibernate, I don't know). To deploy the process I use the deployment tab provided by the GPD eclipse plugin (see GPDt.png). I wonder how experts deploy their processes? Maybe I'm doing something wrong.

       

      I've prepared a little process for this thread which reproduces the problem. My main project is a bit bigger, but there happens the same problem.


      My processdefiniton.xml:

       

      <process-definition
        xmlns="urn:jbpm.org:jpdl-3.2"
        name="simple">
         <start-state name="start">
              <transition to="first" name="to_state">
                  <action name="actoin1" class="de.hpi.pois.action.ApplicationCreation"></action>
              </transition>
          </start-state>
         <state name="first">
            <transition name="to_end" to="end">
               <action name="action2" class="de.hpi.pois.action.GetterAction"></action>
            </transition>
         </state>
         <end-state name="end"></end-state>
      </process-definition>


      The ActionHandler ApplicationCreation:

       

      package de.hpi.pois.action;

       

      import org.jbpm.graph.def.ActionHandler;

      import org.jbpm.graph.exe.ExecutionContext;

       

      import de.hpi.pois.klassen.Application;

       

      public class ApplicationCreation implements ActionHandler

      {

          private static final long serialVersionUID = 1893405813471405736L;

       

          @Override

          public void execute(ExecutionContext arg0) throws Exception

          {

              Application appli = Application.createApplication("Gerardo,g@hpi.de");

       

              arg0.setVariable("appli", appli);

          }

       

      }


      The ActionHandler GetterAction:

       

      package de.hpi.pois.action;

       

      import org.jbpm.graph.def.ActionHandler;

      import org.jbpm.graph.exe.ExecutionContext;

       

      import de.hpi.pois.klassen.Application;

       

      public class GetterAction implements ActionHandler

      {

          private static final long serialVersionUID = -7981154292715474830L;

       

          @Override

          public void execute(ExecutionContext arg0) throws Exception

          {

              Application appli = (Application) arg0.getVariable("appli");

       

              arg0.setVariable("name", appli.getName());

              arg0.setVariable("email", appli.getEmail());

          }

       

      }


      The class Applicaion:

       

      package de.hpi.pois.klassen;

       

      import java.io.Serializable;

       

      public class Application implements Serializable
      {
          private static final long serialVersionUID = 134598365872315L;
         
          public String name;
          public String email;
         
          public Application(){}
         
          public Application(String name, String email)
          {
              setName(name);
              setEmail(email);
          }
         
          public static Application createApplication(String entry)
          {
              String[] entryElements = entry.split(",");
             
              return new Application(entryElements[0], entryElements[1]);
          }
         
          public void setName(String name) {
              this.name = name;
          }

       

          public String getName() {
              return name;

          }

       

          public void setEmail(String email) {
              this.email = email;
          }

       

          public String getEmail() {
              return email;
          }
      }

       

      Thanks fro your help. I appreciate it a lot.

       

      Greetings,

       

      Gerardo

        • 1. Re: Process Variable cannot be casted and accessed
          camunda

          Hi Gerardo.

           

          Unfortunately I don't have the time to have a deeper look at your sources. But if you get an ClassCastException on the same class (like you wrote: de.hpi.pois.klassen.Application cannot be cast to  de.hpi.pois.klassen.Application) this always means you have the same class loaded by different class loaders. And this means you have deployed the class twice somehow. So a good start would be to look how the class is packaged and in which deployment artefact this is contained...

           

          Cheers

          Bernd

          • 2. Re: Process Variable cannot be casted and accessed
            gerardons

            Hallo Bernd,

             

            thank you very much for this hint. But nevertheless I couldn't figure out why I get this error or why the classes are deployed twice.

             

            Like I said before I use the GPD plugin to develop and also deploy the processes. When I press the "Deploy Process Archive ..." Button eclipse says that the deployment succeeded. So I trust eclipse and it's GPD plugin, but obviously there appears to happen something wrong.

             

            My question is now:

             

            1) You said: "So a good start would be to look how the class is packaged". Well, the class is in the package "de.hpi.pois.klassen" and the action are in the package "de.hpi.pois.action". But I think that this is not what you mean by that phrase. I've tried to find the archive that is created by the GPD and to look how the classes are packaged there, but I couldn't find the archive. Do you know where the archives could be?

             

            2) Where I can find the deployment artifacts? (google doesn't give me a good answer)

             

            3) You said that you have to take a closer look to my source. So, do you think that the problem lies in the code?

             

            An alternative could deploy it with an ant target. Meanwhile, I tried this alternative but up to this point without any success.

             

            Thanks again for your help.

             

            Greetings,

             

            Gerardo