3 Replies Latest reply on Apr 1, 2009 12:47 PM by boercher

    Error handling in CommandServiceBean.execute

      Hi,

      a little bug in my test program in which I tried remote command execution took me quite a while to analyse. The problem was that instead of an error message indicating the real error I got this one:

      ERROR [org.jboss.ejb.plugins.LogInterceptor] (WorkerThread#0[127.0.0.1:1264])
      RuntimeException in method: public abstract java.lang.Object
      org.jbpm.ejb.RemoteCommandService.execute(org.jbpm.command.Command)
      throws java.rmi.RemoteException:
      org.hibernate.exception.GenericJDBCException: Cannot open connection
      ...
      at org.jbpm.JbpmContext.close(JbpmContext.java:129)
      at org.jbpm.ejb.impl.CommandServiceBean.execute(CommandServiceBean.java:124)


      The reason for the misleading error message was a missing try-catch block in CommandServiceBean.execute (in jbpm-3.2.6.SP1):

      public Object execute(Command command) {
       JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
       try {
       log.debug("executing " + command);
       return command.execute(jbpmContext);
       }
       catch (RuntimeException e) {
       sessionContext.setRollbackOnly();
       throw e;
       }
       catch (Exception e) {
       sessionContext.setRollbackOnly();
       throw new JbpmException("failed to execute " + command, e);
       }
       finally {
       jbpmContext.close();
       }
       }
      

      The finally block performs some non-trivial cleanup-operations that easily may throw exceptions in case of a preceding error. Errors in command execution would be much easier to spot if the finally block would be coded like that:

      finally {
       try {
       jbpmContext.close();
       }
       catch (Throwable t) {
       log.error("error on context close", t);
       }
       }
      


      but development on 3.2 has been stopped, right?

      Regards,
      Volker