Search in sources :

Example 1 with SahiProxyProperties

use of org.sakuli.datamodel.properties.SahiProxyProperties in project sakuli by ConSol.

the class ModifySahiTimerAspect method modifySahiTimer.

void modifySahiTimer(JoinPoint joinPoint, boolean beforeMethod) {
    BaseActionLoader loader = BeanLoader.loadBaseActionLoader();
    SahiProxyProperties sahiProxyProperties = loader.getSahiProxyProperties();
    if (sahiProxyProperties != null && sahiProxyProperties.isRequestDelayActive()) {
        RhinoScriptRunner rhinoScriptRunner = loader.getRhinoScriptRunner();
        if (rhinoScriptRunner != null && rhinoScriptRunner.getSession() != null) {
            getLogger(joinPoint).debug("MODIFY SAHI-TIMER for {}", getClassAndMethodAsString(joinPoint));
            Session session = rhinoScriptRunner.getSession();
            if (beforeMethod) {
                Integer delay = determineDelay(joinPoint, loader);
                session.setVariable(SahiProxyProperties.SAHI_REQUEST_DELAY_TIME_VAR, delay.toString());
                //short sleep to ensure that browser context can read out the value
                try {
                    logger.info("wait {}ms for sahi refresh", sahiProxyProperties.getRequestDelayRefreshMs());
                    Thread.sleep(sahiProxyProperties.getRequestDelayRefreshMs());
                } catch (InterruptedException e) {
                    BeanLoader.loadBaseActionLoader().getExceptionHandler().handleException(e, true);
                }
                logger.info("sahi-proxy-timer modified to {} ms", delay.toString());
            } else {
                logger.info("reset sahi-proxy-timer");
                session.setVariable(SahiProxyProperties.SAHI_REQUEST_DELAY_TIME_VAR, null);
            }
        }
    }
}
Also used : RhinoScriptRunner(net.sf.sahi.rhino.RhinoScriptRunner) BaseActionLoader(org.sakuli.loader.BaseActionLoader) SahiProxyProperties(org.sakuli.datamodel.properties.SahiProxyProperties) Session(net.sf.sahi.session.Session)

Aggregations

RhinoScriptRunner (net.sf.sahi.rhino.RhinoScriptRunner)1 Session (net.sf.sahi.session.Session)1 SahiProxyProperties (org.sakuli.datamodel.properties.SahiProxyProperties)1 BaseActionLoader (org.sakuli.loader.BaseActionLoader)1