@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()); } // If no environment: use directly the command Service with interceptors 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; } } }
public Object invoke(final Object proxy, final Method method, final Object[] args) throws BonitaException { try { // If already in environment: use the same environment to execute the // command directly if (Environment.getCurrent() != null) { return new APIInterceptorCommand(method, args, true).execute(Environment.getCurrent()); } // If no environment: use directly the command Service with interceptors final EnvironmentFactory envFactory = GlobalEnvironmentFactory.getEnvironmentFactory(); return envFactory.get(CommandService.class).execute(new APIInterceptorCommand(method, args, false)); } catch (final PvmException e) { final Throwable cause = e.getCause(); if (cause instanceof BonitaException) { throw (BonitaException) cause; } throw e; } catch (final BonitaException e) { throw e; } catch (final InvalidEnvironmentException e) { // Don't throw BonitaInternalException if Environment parsing failed. // This is a configuration problem, not an engine bug. throw e; } catch (final BonitaWrapperException e) { throw (RuntimeException) e.getCause(); } catch (final RuntimeException e) { throw BonitaInternalException.build(e); } catch (final Exception t) { throw new BonitaInternalException("Ouch! Unexpected error: " + t, t); } }