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());
}
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);
}
}
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);
}
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());
}
}
}
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();
}
}
Aggregations