3 Replies Latest reply on Jun 16, 2008 12:22 PM by octomac

    How to start a JBPM Work Flow remotely???

    cr3

      Hi there,

      Does anybody know how to start a JBPM Work Flow remotely?

      What I want to do is Instance a new Process from a remote server (a Nagios server when an alarm appears).

      The code that I think that could do this is:

      JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
      
      ProcessInstance processInstance = jbpmContext.newProcessInstance("Gestion de Problemas");
      
      processInstance.signal("Enviar");


      but I cannnot figure it out how to initialize the variable "jbpmConfiguration".

      When I was in a Node of the JBpm I used:

      JbpmContext jbpmContext =context.getJbpmContext();


      where context is an object of the class ExecutionContext, but as you can see I don't have this class because I want to start the process remotely ;).
      I tried as well to use this:
      JbpmConfiguration jbpmConfiguration = JbpmConfiguration.parseXmlString(xml);


      Where the String xml is:

      String xml="<jbpm-configuration>"+
      "<jbpm-context>"+
      "<service name=\"persistence\" factory=\"org.jbpm.persistence.db.DbPersistenceServiceFactory\" />"+
      "<service name=\"tx\" factory=\"org.jbpm.tx.TxServiceFactory\" />"+
      "<service name=\"message\" factory=\"org.jbpm.msg.db.DbMessageServiceFactory\" />"+
      "<service name=\"scheduler\" factory=\"org.jbpm.scheduler.db.DbSchedulerServiceFactory\" />"+
      "<service name=\"logging\" factory=\"org.jbpm.logging.db.DbLoggingServiceFactory\" />"+
      "<service name=\"authentication\" factory=\"org.jbpm.security.authentication.DefaultAuthenticationServiceFactory\" />"+
      "</jbpm-context>"+

      "<string name=\"resource.hibernate.cfg.xml\" value=\"hibernate.cfg.xml\" />"+


      "<string name=\"resource.business.calendar\" value=\"org/jbpm/calendar/jbpm.business.calendar.properties\" />"+
      "<string name=\"resource.default.modules\" value=\"org/jbpm/graph/def/jbpm.default.modules.properties\" />"+
      "<string name=\"resource.converter\" value=\"org/jbpm/db/hibernate/jbpm.converter.properties\" />"+
      "<string name=\"resource.action.types\" value=\"org/jbpm/graph/action/action.types.xml\" />"+
      "<string name=\"resource.node.types\" value=\"org/jbpm/graph/node/node.types.xml\" />"+
      "<string name=\"resource.parsers\" value=\"org/jbpm/jpdl/par/jbpm.parsers.xml\" />"+
      "<string name=\"resource.varmapping\" value=\"org/jbpm/context/exe/jbpm.varmapping.xml\" />"+
      "<string name=\"resource.mail.templates\" value=\"jbpm.mail.templates.xml\" />"+

      "<int name=\"jbpm.byte.block.size\" value=\"1024\" singleton=\"true\" />"+
      "<bean name=\"jbpm.task.instance.factory\" class=\"org.jbpm.taskmgmt.impl.DefaultTaskInstanceFactoryImpl\" singleton=\"true\" />"+
      "<bean name=\"jbpm.variable.resolver\" class=\"org.jbpm.jpdl.el.impl.JbpmVariableResolver\" singleton=\"true\" />"+
      "<string name=\"jbpm.mail.smtp.host\" value=\"localhost\" />"+
      "<bean name=\"jbpm.mail.address.resolver\" class=\"org.jbpm.identity.mail.IdentityAddressResolver\" singleton=\"true\" />"+
      "<string name=\"jbpm.mail.from.address\" value=\"jbpm@noreply\" />"+

      "<bean name=\"jbpm.job.executor\" class=\"org.jbpm.job.executor.JobExecutor\">"+
      "<field name=\"jbpmConfiguration\"><ref bean=\"jbpmConfiguration\" /></field>"+
      "<field name=\"name\"><string value=\"JbpmJobExector\" /></field>"+
      "<field name=\"nbrOfThreads\"><int value=\"1\" /></field>"+
      "<field name=\"idleInterval\"><int value=\"5000\" /></field>"+
      "<field name=\"maxIdleInterval\"><int value=\"3600000\" /></field> <!-- 1 hour -->"+
      "<field name=\"historyMaxSize\"><int value=\"20\" /></field>"+
      "<field name=\"maxLockTime\"><int value=\"600000\" /></field> <!-- 10 minutes -->"+
      "<field name=\"lockMonitorInterval\"><int value=\"60000\" /></field> <!-- 1 minute -->"+
      "<field name=\"lockBufferTime\"><int value=\"5000\" /></field> <!-- 5 seconds -->"+
      "</bean>"+

      "</jbpm-configuration>";


      But as you guess it, it doesn't work as well.

      Thanks in advance for your cooperation (If I got one hehe...)

      Christian

        • 1. Re: How to start a JBPM Work Flow remotely???
          octomac

          I'm not sure if this will help, as I'm fairly new to JBPM myself, but whenever I need to instantiate a JbpmContext object, I use the following line of code:

          jbpmConfiguration = JbpmConfiguration.getInstance();
          


          This calls a static method in the JbpmConfiguration class used to instantiate a JbpmConfiguration variable. You can try placing that line immediately prior to the "JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();" line in your code.

          I hope that helps!

          • 2. Re: How to start a JBPM Work Flow remotely???
            cr3

            Thanks Octomac for your reply!!!

            But I got a bad new (for me). I got this error:

            09:29:22,625 [main] WARN JDBCExceptionReporter : SQL Error: -22, SQLState: S0002
            09:29:22,625 [main] ERROR JDBCExceptionReporter : Table not found in statement [select top ? processdef0_.ID_ as ID1_4_, processdef0_.NAME_ as NAME3_4_, processdef0_.DESCRIPTION_ as DESCRIPT4_4_, processdef0_.VERSION_ as VERSION5_4_, processdef0_.ISTERMINATIONIMPLICIT_ as ISTERMIN6_4_, processdef0_.STARTSTATE_ as STARTSTATE7_4_ from JBPM_PROCESSDEFINITION processdef0_ where processdef0_.NAME_=? order by processdef0_.VERSION_ desc]
            org.hibernate.exception.SQLGrammarException: could not execute query
            at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
            at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
            at org.hibernate.loader.Loader.doList(Loader.java:2214)
            at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2095)
            at org.hibernate.loader.Loader.list(Loader.java:2090)
            at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:388)
            at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:338)
            at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:172)
            at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1121)
            at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
            at org.hibernate.impl.AbstractQueryImpl.uniqueResult(AbstractQueryImpl.java:804)
            at org.jbpm.db.GraphSession.findLatestProcessDefinition(GraphSession.java:153)
            at org.jbpm.JbpmContext.newProcessInstance(JbpmContext.java:408)
            at org.jbpm.stateTest.FlowInstance.main(FlowInstance.java:63)
            Caused by: java.sql.SQLException: Table not found in statement [select top ? processdef0_.ID_ as ID1_4_, processdef0_.NAME_ as NAME3_4_, processdef0_.DESCRIPTION_ as DESCRIPT4_4_, processdef0_.VERSION_ as VERSION5_4_, processdef0_.ISTERMINATIONIMPLICIT_ as ISTERMIN6_4_, processdef0_.STARTSTATE_ as STARTSTATE7_4_ from JBPM_PROCESSDEFINITION processdef0_ where processdef0_.NAME_=? order by processdef0_.VERSION_ desc]
            at org.hsqldb.jdbc.Util.throwError(Unknown Source)
            at org.hsqldb.jdbc.jdbcPreparedStatement.(Unknown Source)
            at org.hsqldb.jdbc.jdbcConnection.prepareStatement(Unknown Source)
            at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:497)
            at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:415)
            at org.hibernate.jdbc.AbstractBatcher.prepareQueryStatement(AbstractBatcher.java:139)
            at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1538)
            at org.hibernate.loader.Loader.doQuery(Loader.java:661)
            at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
            at org.hibernate.loader.Loader.doList(Loader.java:2211)
            ... 11 more
            09:29:22,828 [main] ERROR GraphSession : org.hibernate.exception.SQLGrammarException: could not execute query
            Exception in thread "main" org.jbpm.JbpmException: couldn't find process definition 'Gestion de Problemas'
            at org.jbpm.db.GraphSession.findLatestProcessDefinition(GraphSession.java:170)
            at org.jbpm.JbpmContext.newProcessInstance(JbpmContext.java:408)
            at org.jbpm.stateTest.FlowInstance.main(FlowInstance.java:63)
            Caused by: org.hibernate.exception.SQLGrammarException: could not execute query
            at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
            at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
            at org.hibernate.loader.Loader.doList(Loader.java:2214)
            at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2095)
            at org.hibernate.loader.Loader.list(Loader.java:2090)
            at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:388)
            at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:338)
            at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:172)
            at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1121)
            at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
            at org.hibernate.impl.AbstractQueryImpl.uniqueResult(AbstractQueryImpl.java:804)
            at org.jbpm.db.GraphSession.findLatestProcessDefinition(GraphSession.java:153)
            ... 2 more
            Caused by: java.sql.SQLException: Table not found in statement [select top ? processdef0_.ID_ as ID1_4_, processdef0_.NAME_ as NAME3_4_, processdef0_.DESCRIPTION_ as DESCRIPT4_4_, processdef0_.VERSION_ as VERSION5_4_, processdef0_.ISTERMINATIONIMPLICIT_ as ISTERMIN6_4_, processdef0_.STARTSTATE_ as STARTSTATE7_4_ from JBPM_PROCESSDEFINITION processdef0_ where processdef0_.NAME_=? order by processdef0_.VERSION_ desc]
            at org.hsqldb.jdbc.Util.throwError(Unknown Source)
            at org.hsqldb.jdbc.jdbcPreparedStatement.(Unknown Source)
            at org.hsqldb.jdbc.jdbcConnection.prepareStatement(Unknown Source)
            at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:497)
            at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:415)
            at org.hibernate.jdbc.AbstractBatcher.prepareQueryStatement(AbstractBatcher.java:139)
            at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1538)
            at org.hibernate.loader.Loader.doQuery(Loader.java:661)
            at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
            at org.hibernate.loader.Loader.doList(Loader.java:2211)
            ... 11 more

            If any one knows how to clean it, please post some adds }:^)

            Thanks in advance...

            Christian

            • 3. Re: How to start a JBPM Work Flow remotely???
              octomac

              It looks like your program is trying to find an existing process definition by the name of 'Gestion de Problemas', but there isn't a process by that name in your database. Have you deployed that process yet? That's about the only thing that comes to mind off the top of my head.