public static void doInvoke
(WorkflowEngine wfe, InvocationHelperLocal invHlp, Activity act,
ExtApplication appl, Map params, boolean useNew)
throws RemoteException {
ExtApplication.InvocationResult res = null;
RequestScope scope = RequestLog.enterScope
(ApplInvokerEJB.class, "doInvoke",
new Object[] { wfe,invHlp,act,appl,params,new Boolean(useNew) });
if (RequestLog.isEnabled()) {
scope.logMessage
("Invoking " + appl.toString() + "from " + act.toString()
+ " with parameters " + params.toString());
}
try {
// Invoke in separate transaction. Else all exceptions
// thrown by EJB methods invoked from the application
// cause a roll back of this transaction and no
// ToolInvocationFailedAuditEvent will be recorded and
// the invocation will be repeated (maybe endlessly)
res = invHlp.doInvoke(wfe, appl, act, params);
if (res != null) {
Object resVal = res.result();
if (useNew) {
while (true) {
try {
if (resVal instanceof ExceptionResult) {
invHlp.doAbandon
(wfe, act, (ExceptionResult)resVal);
break;
}
invHlp.doFinish (wfe, act, (Map)resVal);
break;
} catch (EJBException e) {
// Probably deadlock
logger.warn ("Error while finishing, repeating: "
+ e.getMessage());
}
}
} else {
if (resVal instanceof ExceptionResult) {
((ExtActivity)act).abandon((ExceptionResult)resVal);
} else {
if (act instanceof ActivityProxy) {
Activity aun = ((ActivityProxy)act).unwrap();
aun.setResult(new DefaultProcessData ((Map)resVal));
aun.complete ();
}
}
}
}
if (RequestLog.isEnabled()) {
scope.logMessage
("Result is: " + (res == null ? "null" : res.toString()));
}
} catch (RemoteException e) {
// Indicates that the invocation should be retried,
// simply re-throw.
logger.warn (appl + " has requested re-invocation: "
+ e.getMessage());
logger.debug ("Stack trace:", e);
throw e;
} catch (EJBException e) {
// Indicates that the invocation should be retried,
// simply re-throw.
logger.warn (appl + " has requested re-invocation: "
+ e.getMessage());
logger.debug ("Stack trace:", e);
throw (RemoteException)
(new RemoteException (e.getMessage(), e));
} catch (Throwable e) {
if ((e instanceof ToolInvocationException)
&& e.getCause() != null
&& (e.getCause() instanceof CannotExecuteException)) {
Throwable t = e.getCause();
if (t.getCause() != null) {
t = t.getCause();
}
logger.warn(appl + " reports " + t.getClass().getName()
+ " during invocation (" + act + " will be terminated): "
+ t.getMessage(), t);
} else {
logger.error
("Problem invoking " + appl
+ " (" + act + " will be terminated): "
+ e.getClass().getName() + ": " + e.getMessage(), e);
}
invHlp.handleToolInvocationFailed(wfe, act.uniqueKey());
return;
} finally {
scope.leave();
}
}