use of org.aspectj.lang.reflect.MethodSignature in project syncope by apache.
the class LogicInvocationHandler method around.
@Around("execution(* org.apache.syncope.core.logic.AbstractLogic+.*(..))")
public Object around(final ProceedingJoinPoint joinPoint) throws Throwable {
Class<?> clazz = joinPoint.getTarget().getClass();
Object[] input = joinPoint.getArgs();
String category = clazz.getSimpleName();
MethodSignature ms = (MethodSignature) joinPoint.getSignature();
Method method = ms.getMethod();
String event = joinPoint.getSignature().getName();
boolean notificationsAvailable = notificationManager.notificationsAvailable(AuditElements.EventCategoryType.LOGIC, category, null, event);
boolean auditRequested = auditManager.auditRequested(AuditElements.EventCategoryType.LOGIC, category, null, event);
AuditElements.Result condition = null;
Object output = null;
Object before = null;
try {
LOG.debug("Before {}.{}({})", clazz.getSimpleName(), event, input == null || input.length == 0 ? StringUtils.EMPTY : Arrays.asList(input));
if (notificationsAvailable || auditRequested) {
try {
before = ((AbstractLogic) joinPoint.getTarget()).resolveBeanReference(method, input);
} catch (UnresolvedReferenceException ignore) {
LOG.debug("Unresolved bean reference ...");
}
}
output = joinPoint.proceed();
condition = AuditElements.Result.SUCCESS;
LOG.debug("After returning {}.{}: {}", clazz.getSimpleName(), event, output);
return output;
} catch (Throwable t) {
output = t;
condition = AuditElements.Result.FAILURE;
LOG.debug("After throwing {}.{}", clazz.getSimpleName(), event);
throw t;
} finally {
if (notificationsAvailable || auditRequested) {
Map<String, Object> jobMap = new HashMap<>();
jobMap.put(AfterHandlingEvent.JOBMAP_KEY, new AfterHandlingEvent(AuditElements.EventCategoryType.LOGIC, category, null, event, condition, before, output, input));
AfterHandlingJob.schedule(scheduler, jobMap);
}
}
}
use of org.aspectj.lang.reflect.MethodSignature in project vip by guangdada.
the class MultiSourceExAop method around.
@Around("cut()")
public Object around(ProceedingJoinPoint point) throws Throwable {
Signature signature = point.getSignature();
MethodSignature methodSignature = null;
if (!(signature instanceof MethodSignature)) {
throw new IllegalArgumentException("该注解只能用于方法");
}
methodSignature = (MethodSignature) signature;
Object target = point.getTarget();
Method currentMethod = target.getClass().getMethod(methodSignature.getName(), methodSignature.getParameterTypes());
DataSource datasource = currentMethod.getAnnotation(DataSource.class);
if (datasource != null) {
DataSourceContextHolder.setDataSourceType(datasource.name());
log.debug("设置数据源为:" + datasource.name());
} else {
DataSourceContextHolder.setDataSourceType(DSEnum.DATA_SOURCE_GUNS);
log.debug("设置数据源为:dataSourceCurrent");
}
try {
return point.proceed();
} finally {
log.debug("清空数据源信息!");
DataSourceContextHolder.clearDataSourceType();
}
}
use of org.aspectj.lang.reflect.MethodSignature in project moon by gentoo111.
the class LogAdvice method logSave.
@Around(value = "@annotation(com.moon.admin.common.utils.LogAnnotation)")
public Object logSave(ProceedingJoinPoint joinPoint) throws Throwable {
SysLogs sysLogs = new SysLogs();
MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature();
String module = null;
LogAnnotation logAnnotation = methodSignature.getMethod().getDeclaredAnnotation(LogAnnotation.class);
module = logAnnotation.module();
if (StringUtils.isEmpty(module)) {
ApiOperation apiOperation = methodSignature.getMethod().getDeclaredAnnotation(ApiOperation.class);
if (apiOperation != null) {
module = apiOperation.value();
}
}
if (StringUtils.isEmpty(module)) {
throw new RuntimeException("没有指定日志module");
}
sysLogs.setModule(module);
try {
Object object = joinPoint.proceed();
sysLogs.setFlag(true);
sysLogService.save(sysLogs);
return object;
} catch (Exception e) {
sysLogs.setFlag(false);
sysLogs.setRemark(e.getMessage());
sysLogService.save(sysLogs);
throw e;
}
}
use of org.aspectj.lang.reflect.MethodSignature in project alien4cloud by alien4cloud.
the class ToscaContextualAspect method ensureContext.
@Around("@annotation(alien4cloud.tosca.context.ToscaContextual)")
public Object ensureContext(ProceedingJoinPoint joinPoint) throws Throwable {
MethodSignature ms = (MethodSignature) joinPoint.getSignature();
Method m = ms.getMethod();
boolean requireNew = m.getAnnotation(ToscaContextual.class).requiresNew();
return execInToscaContext(new Supplier<Object>() {
@Override
@SneakyThrows
public Object get() {
return joinPoint.proceed();
}
}, requireNew, joinPoint.getArgs());
// boolean initContext = false;
// ToscaContext.Context existingContext = ToscaContext.get();
// if (requireNew || existingContext == null) {
// initContext = true;
// }
// try {
// // try to find dependencies from parameters
// if (initContext) {
// Set<CSARDependency> dependencies = findDependencies(joinPoint.getArgs());
// log.debug("Initializing Tosca Context with dependencies {}", dependencies);
// ToscaContext.init(dependencies);
// }
// return joinPoint.proceed();
// } finally {
// if (initContext) {
// log.debug("Destroying Tosca Context");
// ToscaContext.destroy();
// }
// if (existingContext != null) {
// log.debug("Set back the existing context");
// ToscaContext.set(existingContext);
// }
// }
}
use of org.aspectj.lang.reflect.MethodSignature in project entando-core by entando.
the class CacheInfoManager method aroundCacheableMethod.
@Around("@annotation(cacheableInfo)")
public Object aroundCacheableMethod(ProceedingJoinPoint pjp, CacheableInfo cacheableInfo) throws Throwable {
Object result = pjp.proceed();
if (cacheableInfo.expiresInMinute() < 0 && (cacheableInfo.groups() == null || cacheableInfo.groups().trim().length() == 0)) {
return result;
}
try {
MethodSignature methodSignature = (MethodSignature) pjp.getSignature();
Method targetMethod = methodSignature.getMethod();
Class targetClass = pjp.getTarget().getClass();
Method effectiveTargetMethod = targetClass.getMethod(targetMethod.getName(), targetMethod.getParameterTypes());
Cacheable cacheable = effectiveTargetMethod.getAnnotation(Cacheable.class);
if (null == cacheable) {
CachePut cachePut = effectiveTargetMethod.getAnnotation(CachePut.class);
if (null == cachePut) {
return result;
}
String[] cacheNames = cachePut.value();
Object key = this.evaluateExpression(cachePut.key().toString(), targetMethod, pjp.getArgs(), effectiveTargetMethod, targetClass);
for (String cacheName : cacheNames) {
if (cacheableInfo.groups() != null && cacheableInfo.groups().trim().length() > 0) {
Object groupsCsv = this.evaluateExpression(cacheableInfo.groups().toString(), targetMethod, pjp.getArgs(), effectiveTargetMethod, targetClass);
if (null != groupsCsv && groupsCsv.toString().trim().length() > 0) {
String[] groups = groupsCsv.toString().split(",");
this.putInGroup(cacheName, key.toString(), groups);
}
}
if (cacheableInfo.expiresInMinute() > 0) {
this.setExpirationTime(cacheName, key.toString(), cacheableInfo.expiresInMinute());
}
}
} else {
String[] cacheNames = cacheable.value();
Object key = this.evaluateExpression(cacheable.key().toString(), targetMethod, pjp.getArgs(), effectiveTargetMethod, targetClass);
for (String cacheName : cacheNames) {
if (cacheableInfo.groups() != null && cacheableInfo.groups().trim().length() > 0) {
Object groupsCsv = this.evaluateExpression(cacheableInfo.groups().toString(), targetMethod, pjp.getArgs(), effectiveTargetMethod, targetClass);
if (null != groupsCsv && groupsCsv.toString().trim().length() > 0) {
String[] groups = groupsCsv.toString().split(",");
this.putInGroup(cacheName, key.toString(), groups);
}
}
if (cacheableInfo.expiresInMinute() > 0) {
this.setExpirationTime(cacheName, key.toString(), cacheableInfo.expiresInMinute());
}
}
}
} catch (Throwable t) {
logger.error("Error while evaluating cacheableInfo annotation", t);
throw new ApsSystemException("Error while evaluating cacheableInfo annotation", t);
}
return result;
}
Aggregations