@Override
public Object invoke(final Object proxy, final Method method,
final Object[] args) throws Throwable {
if (Environment.getCurrent() != null) {
return new RESTServerAPIInterceptorCommand(method, args, api)
.execute(Environment.getCurrent());
}
final EnvironmentFactory envFactory = GlobalEnvironmentFactory
.getEnvironmentFactory(DomainOwner.getDomain());
try {
return envFactory.get(CommandService.class).execute(
new RESTServerAPIInterceptorCommand(method, args, api));
} catch (final BonitaWrapperException e) {
throw e.getCause();
} catch (final BonitaRuntimeException e) {
if (DefaultCommandService.class.getName().equals(e.getWrappedBy()) || UnRollbackableException.class.getName().equals(e.getWrappedBy())) {
throw e.getCause();
} else {
throw e;
}
}
}