use of org.aspectj.lang.JoinPoint in project irida by phac-nml.
the class ValidMethodParametersAspect method getParameterAnnotations.
/**
* Gets the set of annotations applied to parameters from both an interface
* and concrete implementation of a class.
*
* @param jp
* the {@link JoinPoint} that's currently executing.
* @return the collection of annotations applied to parameters of the
* currently executing method.
*/
private List<List<Annotation>> getParameterAnnotations(JoinPoint jp) {
List<List<Annotation>> annotations = new ArrayList<>();
MethodSignature signature = (MethodSignature) jp.getSignature();
Method m = signature.getMethod();
// in the event that the class is *not* an interface, we need to get the
// corresponding method from the interface to load any parameter
// annotations from there. Note that we only load the direct super
// interface, and stop when we find the first interface that matches the
// method definition; order of interfaces is important.
Class<?>[] interfaces = m.getDeclaringClass().getInterfaces();
Method interfaceMethod = null;
for (Class<?> iface : interfaces) {
try {
interfaceMethod = iface.getMethod(m.getName(), m.getParameterTypes());
} catch (NoSuchMethodException | SecurityException e) {
}
}
if (interfaceMethod == null) {
interfaceMethod = m;
}
Annotation[][] interfaceAnnotations = interfaceMethod.getParameterAnnotations();
for (Annotation[] interfaceAnnotation : interfaceAnnotations) {
annotations.add(Lists.newArrayList(interfaceAnnotation));
}
try {
Method implementedMethod = jp.getTarget().getClass().getMethod(m.getName(), m.getParameterTypes());
// This is an array-of-arrays; the first index corresponds to the
// arguments that were passed to the method, the second index
// corresponds to each of the parameters that was applied to the
// argument.
Annotation[][] implementedAnnotations = implementedMethod.getParameterAnnotations();
for (int i = 0; i < annotations.size(); i++) {
annotations.get(i).addAll(Lists.newArrayList(implementedAnnotations[i]));
}
} catch (NoSuchMethodException | SecurityException e) {
throw new IllegalStateException("A concrete instance of a class *must* implement" + " a method declared in an interface.");
}
return annotations;
}
use of org.aspectj.lang.JoinPoint in project motan by weibocom.
the class LoggingAspect method logAfter.
@AfterReturning(value = "anyPublicOperation() && execCommandOperation()", returning = "result")
public void logAfter(JoinPoint joinPoint, boolean result) {
Object[] args = joinPoint.getArgs();
OperationRecord record = new OperationRecord();
record.setOperator(getUsername());
record.setType(joinPoint.getSignature().getName());
record.setGroupName(args[0].toString());
record.setCommand(JSON.toJSONString(args[1]));
int status = result ? 1 : 0;
record.setStatus((byte) status);
if (recordMapper == null) {
LoggerUtil.accessLog(JSON.toJSONString(record));
} else {
recordMapper.insertSelective(record);
}
}
use of org.aspectj.lang.JoinPoint in project hugo by JakeWharton.
the class Hugo method enterMethod.
private static void enterMethod(JoinPoint joinPoint) {
if (!enabled)
return;
CodeSignature codeSignature = (CodeSignature) joinPoint.getSignature();
Class<?> cls = codeSignature.getDeclaringType();
String methodName = codeSignature.getName();
String[] parameterNames = codeSignature.getParameterNames();
Object[] parameterValues = joinPoint.getArgs();
StringBuilder builder = new StringBuilder("\u21E2 ");
builder.append(methodName).append('(');
for (int i = 0; i < parameterValues.length; i++) {
if (i > 0) {
builder.append(", ");
}
builder.append(parameterNames[i]).append('=');
builder.append(Strings.toString(parameterValues[i]));
}
builder.append(')');
if (Looper.myLooper() != Looper.getMainLooper()) {
builder.append(" [Thread:\"").append(Thread.currentThread().getName()).append("\"]");
}
Log.v(asTag(cls), builder.toString());
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
final String section = builder.toString().substring(2);
Trace.beginSection(section);
}
}
use of org.aspectj.lang.JoinPoint in project wechat by dllwh.
the class LogFactory method createOperateLog.
/**
* @方法描述 : 创建操作日志
*/
public static SysLogEntity createOperateLog(JoinPoint joinPoint, long time, Throwable throwable, Object opResult, String ip, String browser) {
MethodSignature signature = (MethodSignature) joinPoint.getSignature();
Method method = signature.getMethod();
SysLogEntity sysLog = new SysLogEntity();
SystemLog systemLog = method.getAnnotation(SystemLog.class);
if (systemLog != null) {
// 注解上的描述
sysLog.setRemark(systemLog.desc());
// 注解上的操作相关表
sysLog.setTableName(StringUtils.join(systemLog.tableName(), ","));
// 注解上的操作类型
sysLog.setOpType(systemLog.opType().getValue());
}
// 请求方法名
// 获取目标类名
String targetName = joinPoint.getTarget().getClass().getName();
sysLog.setMethod(targetName + "." + signature.getName() + "()");
// 访问目标方法的参数:
Object[] args = joinPoint.getArgs();
String params = JSON.toJSONString(args[0]);
// sysLog.setParams(JsonMapper.toJsonString(joinPoint.getArgs()));
sysLog.setParams(params);
// 操作人的信息
int userId = -1;
if (ShiroHelper.isLogin()) {
userId = WebUtilHelper.getCurrentUserId();
}
sysLog.setUserCode(userId);
if (opResult != null) {
sysLog.setOpResult(JsonMapper.toJsonString(opResult));
}
if (throwable != null) {
sysLog.setLogType(-1);
sysLog.setExceptionCode(sysLog.getClass().getName());
sysLog.setExceptionDetail(throwable.getMessage());
}
sysLog.setIpAddress(ip);
sysLog.setBrowser(browser);
sysLog.setTime(time);
return sysLog;
}
use of org.aspectj.lang.JoinPoint in project spring-framework by spring-projects.
the class MethodInvocationProceedingJoinPointTests method toShortAndLongStringFormedCorrectly.
@Test
public void toShortAndLongStringFormedCorrectly() throws Exception {
final Object raw = new TestBean();
ProxyFactory pf = new ProxyFactory(raw);
pf.addAdvisor(ExposeInvocationInterceptor.ADVISOR);
pf.addAdvice((MethodBeforeAdvice) (method, args, target) -> {
// makeEncSJP, although meant for computing the enclosing join point,
// it serves our purpose here
StaticPart aspectJVersionJp = Factory.makeEncSJP(method);
JoinPoint jp = AbstractAspectJAdvice.currentJoinPoint();
assertThat(jp.getSignature().toLongString()).isEqualTo(aspectJVersionJp.getSignature().toLongString());
assertThat(jp.getSignature().toShortString()).isEqualTo(aspectJVersionJp.getSignature().toShortString());
assertThat(jp.getSignature().toString()).isEqualTo(aspectJVersionJp.getSignature().toString());
assertThat(jp.toLongString()).isEqualTo(aspectJVersionJp.toLongString());
assertThat(jp.toShortString()).isEqualTo(aspectJVersionJp.toShortString());
assertThat(jp.toString()).isEqualTo(aspectJVersionJp.toString());
});
ITestBean itb = (ITestBean) pf.getProxy();
itb.getAge();
itb.setName("foo");
itb.getDoctor();
itb.getStringArray();
itb.getSpouse();
itb.setSpouse(new TestBean());
try {
itb.unreliableFileOperation();
} catch (IOException ex) {
// we don't really care...
}
}
Aggregations