[jboss-user] [JBoss jBPM] - Error handling in CommandServiceBean.execute

boercher do-not-reply at jboss.com
Tue Mar 31 18:57:38 EDT 2009


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:

anonymous wrote :   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

View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4222462#4222462

Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4222462



More information about the jboss-user mailing list