protected void checkTenantIsInAValidModeFor(final Object apiImpl, final Method method, final String apiInterfaceName, final long tenantId, final Session session, boolean isAlreadyInTransaction) { final boolean tenantRunning = isTenantAvailable(tenantId, session, isAlreadyInTransaction); final AvailableWhenTenantIsPaused methodAnnotation = method.getAnnotation(AvailableWhenTenantIsPaused.class); AvailableWhenTenantIsPaused annotation; if (methodAnnotation != null) { annotation = methodAnnotation; } else { final Class<?> apiClass = apiImpl.getClass(); annotation = apiClass.getAnnotation(AvailableWhenTenantIsPaused.class); } checkIsValidModeFor(tenantRunning, annotation, tenantId, apiImpl, method, apiInterfaceName); }
protected Object invokeAPIOutsideTransaction(Object[] parametersValues, Object apiImpl, Method method, String apiInterfaceName, Session session) throws Throwable { checkMethodAccessibility(apiImpl, apiInterfaceName, method, session, /* Not in transaction */false); return invokeAPI(method, apiImpl, parametersValues); }
protected void checkMethodAccessibility(final Object apiImpl, final String apiInterfaceName, final Method method, final Session session, boolean isAlreadyInTransaction) { warnIfDeprecated(method, apiInterfaceName); if (!isNodeInAValidStateFor(method)) { logNodeNotStartedMessage(apiInterfaceName, method); throw new NodeNotStartedException(); } // we don't check if tenant is in pause mode at platform level and when there is no session // when there is no session means that we are trying to log in, in this case it is the LoginApiExt that check if the user is the technical user // For tenant level method call: if (session instanceof APISession) { final long tenantId = ((APISession) session).getTenantId(); checkTenantIsInAValidModeFor(apiImpl, method, apiInterfaceName, tenantId, session, isAlreadyInTransaction); } }
@Override public Object invokeMethod(final Map<String, Serializable> options, final String apiInterfaceName, final String methodName, final List<String> classNameParameters, final Object[] parametersValues) throws ServerWrappedException { technicalTraceLog("Starting ", apiInterfaceName, methodName); final ClassLoader baseClassLoader = Thread.currentThread().getContextClassLoader(); SessionAccessor sessionAccessor = null; try { session = (Session) options.get(SESSION); sessionAccessor = beforeInvokeMethod(session, apiInterfaceName); return invokeAPI(apiInterfaceName, methodName, classNameParameters, parametersValues, session); } catch (final ServerAPIRuntimeException sapire) { throw sapire.getCause(); fillGlobalContextForException(session, bre); throw createServerWrappedException(bre); } catch (final UndeclaredThrowableException ute) { technicalDebugLog(ute); throw createServerWrappedException(ute); } catch (final Throwable cause) { technicalDebugLog(cause); final BonitaRuntimeException throwableToWrap = wrapThrowable(cause); fillGlobalContextForException(session, throwableToWrap); throw createServerWrappedException(throwableToWrap); } finally { cleanSessionIfNeeded(sessionAccessor); technicalTraceLog("End ", apiInterfaceName, methodName);
SessionAccessor beforeInvokeMethod(final Session session, final String apiInterfaceName) throws BonitaHomeNotSetException, InstantiationException, IllegalAccessException, ClassNotFoundException, BonitaHomeConfigurationException, IOException, NoSuchMethodException, InvocationTargetException, SBonitaException { SessionAccessor sessionAccessor = null; final ServiceAccessorFactory serviceAccessorFactory = getServiceAccessorFactoryInstance(); final PlatformServiceAccessor platformServiceAccessor = serviceAccessorFactory.createPlatformServiceAccessor(); ClassLoader serverClassLoader = null; if (session != null) { final SessionType sessionType = getSessionType(session); sessionAccessor = serviceAccessorFactory.createSessionAccessor(); switch (sessionType) { case PLATFORM: serverClassLoader = beforeInvokeMethodForPlatformSession(sessionAccessor, platformServiceAccessor, session); break; case API: serverClassLoader = beforeInvokeMethodForAPISession(sessionAccessor, serviceAccessorFactory, platformServiceAccessor, session); break; default: throw new InvalidSessionException("Unknown session type: " + session.getClass().getName()); } } else if (accessResolver.needSession(apiInterfaceName)) { throw new InvalidSessionException("Session is null!"); } if (serverClassLoader != null) { Thread.currentThread().setContextClassLoader(serverClassLoader); } return sessionAccessor; }
private ClassLoader beforeInvokeMethodForAPISession(final SessionAccessor sessionAccessor, final ServiceAccessorFactory serviceAccessorFactory, final PlatformServiceAccessor platformServiceAccessor, final Session session) throws SBonitaException, BonitaHomeNotSetException, IOException, BonitaHomeConfigurationException, NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException, ClassNotFoundException { checkTenantSession(platformServiceAccessor, session); final long tenantId = ((APISession) session).getTenantId(); final SessionService sessionService = platformServiceAccessor.getTenantServiceAccessor(tenantId).getSessionService(); sessionService.renewSession(session.getId()); sessionAccessor.setSessionInfo(session.getId(), tenantId); final ClassLoader serverClassLoader = getTenantClassLoader(platformServiceAccessor, session); setTechnicalLogger(serviceAccessorFactory.createTenantServiceAccessor(tenantId).getTechnicalLoggerService()); return serverClassLoader; }
@Override public Object invokeMethod(final Map<String, Serializable> options, final String apiInterfaceName, final String methodName, final List<String> classNameParameters, final Object[] parametersValues) throws ServerWrappedException { technicalTraceLog("Starting ", apiInterfaceName, methodName); final ClassLoader baseClassLoader = Thread.currentThread().getContextClassLoader(); SessionAccessor sessionAccessor = null; try { session = (Session) options.get(SESSION); sessionAccessor = beforeInvokeMethod(session, apiInterfaceName); return invokeAPI(apiInterfaceName, methodName, classNameParameters, parametersValues, session); } catch (final ServerAPIRuntimeException sapire) { throw sapire.getCause(); fillGlobalContextForException(session, bre); throw createServerWrappedException(bre); } catch (final UndeclaredThrowableException ute) { technicalDebugLog(ute); throw createServerWrappedException(ute); } catch (final Throwable cause) { technicalDebugLog(cause); final BonitaRuntimeException throwableToWrap = wrapThrowable(cause); fillGlobalContextForException(session, throwableToWrap); throw createServerWrappedException(throwableToWrap); } finally { cleanSessionIfNeeded(sessionAccessor); technicalTraceLog("End ", apiInterfaceName, methodName);
SessionAccessor beforeInvokeMethod(final Session session, final String apiInterfaceName) throws BonitaHomeNotSetException, InstantiationException, IllegalAccessException, ClassNotFoundException, BonitaHomeConfigurationException, IOException, NoSuchMethodException, InvocationTargetException, SBonitaException { SessionAccessor sessionAccessor = null; final ServiceAccessorFactory serviceAccessorFactory = getServiceAccessorFactoryInstance(); final PlatformServiceAccessor platformServiceAccessor = serviceAccessorFactory.createPlatformServiceAccessor(); ClassLoader serverClassLoader = null; if (session != null) { final SessionType sessionType = getSessionType(session); sessionAccessor = serviceAccessorFactory.createSessionAccessor(); switch (sessionType) { case PLATFORM: serverClassLoader = beforeInvokeMethodForPlatformSession(sessionAccessor, platformServiceAccessor, session); break; case API: serverClassLoader = beforeInvokeMethodForAPISession(sessionAccessor, serviceAccessorFactory, platformServiceAccessor, session); break; default: throw new InvalidSessionException("Unknown session type: " + session.getClass().getName()); } } else if (accessResolver.needSession(apiInterfaceName)) { throw new InvalidSessionException("Session is null!"); } if (serverClassLoader != null) { Thread.currentThread().setContextClassLoader(serverClassLoader); } return sessionAccessor; }
private ClassLoader beforeInvokeMethodForAPISession(final SessionAccessor sessionAccessor, final ServiceAccessorFactory serviceAccessorFactory, final PlatformServiceAccessor platformServiceAccessor, final Session session) throws SBonitaException, BonitaHomeNotSetException, IOException, BonitaHomeConfigurationException, NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException, ClassNotFoundException { checkTenantSession(platformServiceAccessor, session); final long tenantId = ((APISession) session).getTenantId(); final SessionService sessionService = platformServiceAccessor.getTenantServiceAccessor(tenantId).getSessionService(); sessionService.renewSession(session.getId()); sessionAccessor.setSessionInfo(session.getId(), tenantId); final ClassLoader serverClassLoader = getTenantClassLoader(platformServiceAccessor, session); setTechnicalLogger(serviceAccessorFactory.createTenantServiceAccessor(tenantId).getTechnicalLoggerService()); return serverClassLoader; }
protected void checkMethodAccessibility(final Object apiImpl, final String apiInterfaceName, final Method method, final Session session, boolean isAlreadyInTransaction) { warnIfDeprecated(method, apiInterfaceName); if (!isNodeInAValidStateFor(method)) { logNodeNotStartedMessage(apiInterfaceName, method); throw new NodeNotStartedException(); } // we don't check if tenant is in pause mode at platform level and when there is no session // when there is no session means that we are trying to log in, in this case it is the LoginApiExt that check if the user is the technical user // For tenant level method call: if (session instanceof APISession) { final long tenantId = ((APISession) session).getTenantId(); checkTenantIsInAValidModeFor(apiImpl, method, apiInterfaceName, tenantId, session, isAlreadyInTransaction); } }
protected Object invokeAPIOutsideTransaction(Object[] parametersValues, Object apiImpl, Method method, String apiInterfaceName, Session session) throws Throwable { checkMethodAccessibility(apiImpl, apiInterfaceName, method, session, /* Not in transaction */false); return invokeAPI(method, apiImpl, parametersValues); }
protected void checkTenantIsInAValidModeFor(final Object apiImpl, final Method method, final String apiInterfaceName, final long tenantId, final Session session, boolean isAlreadyInTransaction) { final boolean tenantRunning = isTenantAvailable(tenantId, session, isAlreadyInTransaction); final AvailableWhenTenantIsPaused methodAnnotation = method.getAnnotation(AvailableWhenTenantIsPaused.class); AvailableWhenTenantIsPaused annotation; if (methodAnnotation != null) { annotation = methodAnnotation; } else { final Class<?> apiClass = apiImpl.getClass(); annotation = apiClass.getAnnotation(AvailableWhenTenantIsPaused.class); } checkIsValidModeFor(tenantRunning, annotation, tenantId, apiImpl, method, apiInterfaceName); }
@Override public Object call() throws Exception { try { checkMethodAccessibility(apiImpl, apiInterfaceName, method, session, /* Already in a transaction */true); return invokeAPI(method, apiImpl, parametersValues); } catch (final Throwable cause) { throw new ServerAPIRuntimeException(cause); } } };
@Override public Object call() throws Exception { try { checkMethodAccessibility(apiImpl, apiInterfaceName, method, session, /* Already in a transaction */true); return invokeAPI(method, apiImpl, parametersValues); } catch (final Throwable cause) { throw new ServerAPIRuntimeException(cause); } } };