Search in sources :

Example 1 with Before

use of org.aspectj.lang.annotation.Before in project frodo by android10.

the class LogSubscriber method beforeOnNextExecution.

@Before("classAnnotatedWithRxLogSubscriber(joinPoint) && onNextMethodExecution()")
public void beforeOnNextExecution(JoinPoint joinPoint) {
    countAndMeasureTime();
    final FrodoJoinPoint frodoJoinPoint = new FrodoJoinPoint(joinPoint);
    final Object value = frodoJoinPoint.getMethodParamValuesList().isEmpty() ? null : frodoJoinPoint.getMethodParamValuesList().get(0);
    messageManager.printSubscriberOnNext(joinPoint.getTarget().getClass().getSimpleName(), value, Thread.currentThread().getName());
}
Also used : FrodoJoinPoint(com.fernandocejas.frodo.joinpoint.FrodoJoinPoint) Before(org.aspectj.lang.annotation.Before)

Example 2 with Before

use of org.aspectj.lang.annotation.Before in project ORCID-Source by ORCID.

the class OrcidApiAuthorizationSecurityAspect method checkPermissionsWithLongId.

@Before("@annotation(accessControl) && args(orcid, id)")
public void checkPermissionsWithLongId(AccessControl accessControl, String orcid, Long id) {
    Authentication auth = getAuthentication();
    boolean allowAnonymousCall = allowAnonymousAccess(auth, accessControl);
    if (!allowAnonymousCall) {
        permissionChecker.checkPermissions(auth, accessControl.requiredScope(), orcid);
    }
}
Also used : OrcidOAuth2Authentication(org.orcid.core.oauth.OrcidOAuth2Authentication) Authentication(org.springframework.security.core.Authentication) Before(org.aspectj.lang.annotation.Before)

Example 3 with Before

use of org.aspectj.lang.annotation.Before in project ats-framework by Axway.

the class UiEngineAspect method logAction.

@Before("(execution(* com.axway.ats.uiengine.elements.html.realbrowser..*.*(..)) " + "|| execution(* com.axway.ats.uiengine.elements.html.hiddenbrowser..*.*(..)) " + "|| execution(* com.axway.ats.uiengine.elements.mobile..*.*(..)) " + "|| execution(* com.axway.ats.uiengine.elements.swing..*.*(..)) " + ") && @annotation(com.axway.ats.common.PublicAtsApi)")
public void logAction(JoinPoint point) throws Throwable {
    // initialize logger
    Logger log = null;
    if (point.getThis() != null) {
        // not a static method
        log = Logger.getLogger(point.getThis().getClass());
    } else {
        // in case of MobileButton.click() this method will return MobileElement.class, but not MobileButton.class
        // that is why it is better to use point.getThis().getClass(), but if the method is static point.getThis() is null
        log = Logger.getLogger(point.getSignature().getDeclaringType());
    }
    String methodName = point.getSignature().getName();
    String propertiesString = " ";
    if (point.getThis() != null) {
        // not a static method
        UiElementProperties properties = ((UiElement) point.getThis()).getElementProperties();
        if (properties != null) {
            if (properties.containsInternalProperty(UiElementProperties.MAP_ID_INTERNAL_PARAM)) {
                propertiesString = properties.getInternalProperty(UiElementProperties.MAP_ID_INTERNAL_PARAM);
            } else {
                // get the properties in the form '{key1=value1, key2=value2}'
                propertiesString = properties.toString();
                // remove the leading and trailing brackets
                propertiesString = propertiesString.substring(1);
                propertiesString = propertiesString.substring(0, propertiesString.length() - 1);
            }
        }
    }
    StringBuilder message = new StringBuilder();
    Object[] args = point.getArgs();
    if (args.length > 0) {
        message.append(methodName + "( ");
        for (Object o : args) {
            if (o instanceof String) {
                message.append("\"" + o + "\" ,");
            } else if (o != null && o.getClass().isArray()) {
                if (o instanceof Object[]) {
                    message.append(Arrays.asList((Object[]) o) + " ,");
                } else {
                    message.append("[");
                    int length = Array.getLength(o);
                    for (int i = 0; i < length; i++) {
                        message.append(Array.get(o, i) + " ,");
                    }
                    message.delete(message.length() - 2, message.length());
                    message.append("]  ");
                }
            } else {
                message.append(o + " ,");
            }
        }
        message.deleteCharAt(message.length() - 1);
        message.append(") ");
        if (point.getThis() != null) {
            if (propertiesString.trim().isEmpty()) {
                message.insert(0, "[  ].");
            } else {
                message.insert(0, "[ \"" + propertiesString + "\" ].");
            }
        }
    } else if (point.getThis() == null) {
        // a static method
        message.insert(message.length(), "()");
    } else if (propertiesString.trim().isEmpty()) {
        message.insert(0, "[  ]." + methodName);
    } else {
        message.insert(0, "[ \"" + propertiesString + "\" ]." + methodName);
        message.insert(message.length(), "()");
    }
    log.info(message);
}
Also used : UiElement(com.axway.ats.uiengine.elements.UiElement) UiElementProperties(com.axway.ats.uiengine.elements.UiElementProperties) Logger(org.apache.log4j.Logger) Before(org.aspectj.lang.annotation.Before)

Example 4 with Before

use of org.aspectj.lang.annotation.Before in project sakuli by ConSol.

the class RhinoAspect method doHandleRhinoException.

/**
     * Aspect to fetch all Logs from the Sahi-Proxy by the method {@link net.sf.sahi.ant.Report} and do an trusty
     * exception handling on top of that.
     *
     * @param joinPoint injected joinPoint of the execution
     */
@Before("execution(* net.sf.sahi.report.Report.addResult(..))")
public void doHandleRhinoException(JoinPoint joinPoint) {
    // Read out all args
    Object[] args = joinPoint.getArgs();
    ResultType resultType;
    if (args[1] instanceof ResultType) {
        resultType = (ResultType) args[1];
    } else {
        resultType = ResultType.getType((String) args[1]);
    }
    LogResult logResult = new LogResult((String) args[0], resultType, (String) args[2], (String) args[3]);
    if (logResult.getFailureMsg() == null || !logResult.getFailureMsg().contains(ALREADY_PROCESSED)) {
        //log and handle exception from sahi actions
        if (ResultType.ERROR.equals(resultType) || ResultType.FAILURE.equals(resultType)) {
            BaseActionLoader environmentLoader = BeanLoader.loadBaseActionLoader();
            environmentLoader.getExceptionHandler().handleException(logResult);
        } else /**
             * all Actions in Package {@link org.sakuli.actions} should be already logged by
             * {@link #doAddActionLog(org.aspectj.lang.JoinPoint, org.sakuli.actions.logging.LogToResult)}.
             */
        if (logResult.getDebugInfo() == null || !logResult.getDebugInfo().startsWith("org.sakuli.actions.")) {
            logger.info(logResult.getMessage());
        }
    }
}
Also used : LogResult(org.sakuli.datamodel.actions.LogResult) ResultType(net.sf.sahi.report.ResultType) Before(org.aspectj.lang.annotation.Before)

Example 5 with Before

use of org.aspectj.lang.annotation.Before in project spring-framework by spring-projects.

the class PerThisAspect method recordModificationIfSetterArgumentDiffersFromOldValue.

@Before(value = "execution(void set*(*)) && this(modifiable) && args(newValue)", argNames = "modifiable,newValue")
public void recordModificationIfSetterArgumentDiffersFromOldValue(JoinPoint jp, MutableModifable mixin, Object newValue) {
    if (mixin.isModified()) {
        //System.out.println("changed");
        return;
    }
    // Find the current raw value, by invoking the corresponding setter
    Method correspondingGetter = getGetterFromSetter(((MethodSignature) jp.getSignature()).getMethod());
    boolean modified = true;
    if (correspondingGetter != null) {
        try {
            Object oldValue = correspondingGetter.invoke(jp.getTarget());
            //System.out.println("Old value=" + oldValue + "; new=" + newValue);
            modified = !ObjectUtils.nullSafeEquals(oldValue, newValue);
        } catch (Exception ex) {
            ex.printStackTrace();
        // Don't sweat on exceptions; assume value was modified
        }
    } else {
    //System.out.println("cannot get getter for " + jp);
    }
    if (modified) {
        mixin.markDirty();
    }
}
Also used : Method(java.lang.reflect.Method) AopConfigException(org.springframework.aop.framework.AopConfigException) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) FileNotFoundException(java.io.FileNotFoundException) RemoteException(java.rmi.RemoteException) Before(org.aspectj.lang.annotation.Before)

Aggregations

Before (org.aspectj.lang.annotation.Before)7 OrcidOAuth2Authentication (org.orcid.core.oauth.OrcidOAuth2Authentication)3 Authentication (org.springframework.security.core.Authentication)3 UiElement (com.axway.ats.uiengine.elements.UiElement)1 UiElementProperties (com.axway.ats.uiengine.elements.UiElementProperties)1 FrodoJoinPoint (com.fernandocejas.frodo.joinpoint.FrodoJoinPoint)1 FileNotFoundException (java.io.FileNotFoundException)1 Method (java.lang.reflect.Method)1 UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)1 RemoteException (java.rmi.RemoteException)1 ResultType (net.sf.sahi.report.ResultType)1 Logger (org.apache.log4j.Logger)1 LogResult (org.sakuli.datamodel.actions.LogResult)1 AopConfigException (org.springframework.aop.framework.AopConfigException)1