use of org.aspectj.lang.reflect.MethodSignature in project skeleton-commons by skeleton-software-community.
the class AccessControlAspect method getTokenExtractionMode.
private TokenExtractionMode getTokenExtractionMode(ProceedingJoinPoint joinPoint) {
TokenExtractionMode tokenExtractionMode = TokenExtractionMode.HEADER;
Method proxiedMethod = ((MethodSignature) joinPoint.getSignature()).getMethod();
AccessControl accessControl = proxiedMethod.getAnnotation(AccessControl.class);
if (accessControl != null) {
tokenExtractionMode = accessControl.tokenExtractionMode();
}
return tokenExtractionMode;
}
use of org.aspectj.lang.reflect.MethodSignature in project hugo by JakeWharton.
the class Hugo method exitMethod.
private static void exitMethod(JoinPoint joinPoint, Object result, long lengthMillis) {
if (!enabled)
return;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
Trace.endSection();
}
Signature signature = joinPoint.getSignature();
Class<?> cls = signature.getDeclaringType();
String methodName = signature.getName();
boolean hasReturnType = signature instanceof MethodSignature && ((MethodSignature) signature).getReturnType() != void.class;
StringBuilder builder = new StringBuilder("\u21E0 ").append(methodName).append(" [").append(lengthMillis).append("ms]");
if (hasReturnType) {
builder.append(" = ");
builder.append(Strings.toString(result));
}
Log.v(asTag(cls), builder.toString());
}
use of org.aspectj.lang.reflect.MethodSignature in project disconf by knightliao.
the class DisconfAspectJ method decideAccess.
/**
* 获取配置文件数据, 只有开启disconf远程才会进行切面
*
* @throws Throwable
*/
@Around("anyPublicMethod() && @annotation(disconfFileItem)")
public Object decideAccess(ProceedingJoinPoint pjp, DisconfFileItem disconfFileItem) throws Throwable {
if (DisClientConfig.getInstance().ENABLE_DISCONF) {
MethodSignature ms = (MethodSignature) pjp.getSignature();
Method method = ms.getMethod();
//
// 文件名
//
Class<?> cls = method.getDeclaringClass();
DisconfFile disconfFile = cls.getAnnotation(DisconfFile.class);
//
// Field名
//
Field field = MethodUtils.getFieldFromMethod(method, cls.getDeclaredFields(), DisConfigTypeEnum.FILE);
if (field != null) {
//
// 请求仓库配置数据
//
DisconfStoreProcessor disconfStoreProcessor = DisconfStoreProcessorFactory.getDisconfStoreFileProcessor();
Object ret = disconfStoreProcessor.getConfig(disconfFile.filename(), disconfFileItem.name());
if (ret != null) {
LOGGER.debug("using disconf store value: " + disconfFile.filename() + " (" + disconfFileItem.name() + " , " + ret + ")");
return ret;
}
}
}
Object rtnOb;
try {
// 返回原值
rtnOb = pjp.proceed();
} catch (Throwable t) {
LOGGER.info(t.getMessage());
throw t;
}
return rtnOb;
}
use of org.aspectj.lang.reflect.MethodSignature in project spring-framework by spring-projects.
the class MethodInvocationProceedingJoinPointTests method testCanGetMethodSignatureFromJoinPoint.
@Test
public void testCanGetMethodSignatureFromJoinPoint() {
final Object raw = new TestBean();
// Will be set by advice during a method call
final int newAge = 23;
ProxyFactory pf = new ProxyFactory(raw);
pf.setExposeProxy(true);
pf.addAdvisor(ExposeInvocationInterceptor.ADVISOR);
AtomicInteger depth = new AtomicInteger();
pf.addAdvice((MethodBeforeAdvice) (method, args, target) -> {
JoinPoint jp = AbstractAspectJAdvice.currentJoinPoint();
assertThat(jp.toString().contains(method.getName())).as("Method named in toString").isTrue();
// Ensure that these don't cause problems
jp.toShortString();
jp.toLongString();
assertThat(AbstractAspectJAdvice.currentJoinPoint().getTarget()).isSameAs(target);
assertThat(AopUtils.isAopProxy(AbstractAspectJAdvice.currentJoinPoint().getTarget())).isFalse();
ITestBean thisProxy = (ITestBean) AbstractAspectJAdvice.currentJoinPoint().getThis();
assertThat(AopUtils.isAopProxy(AbstractAspectJAdvice.currentJoinPoint().getThis())).isTrue();
assertThat(thisProxy).isNotSameAs(target);
// Check getting again doesn't cause a problem
assertThat(AbstractAspectJAdvice.currentJoinPoint().getThis()).isSameAs(thisProxy);
// Be sure to increment depth to avoid infinite recursion
if (depth.getAndIncrement() == 0) {
// Check that toString doesn't cause a problem
thisProxy.toString();
// Change age, so this will be returned by invocation
thisProxy.setAge(newAge);
assertThat(thisProxy.getAge()).isEqualTo(newAge);
}
assertThat(thisProxy).isSameAs(AopContext.currentProxy());
assertThat(raw).isSameAs(target);
assertThat(AbstractAspectJAdvice.currentJoinPoint().getSignature().getName()).isSameAs(method.getName());
assertThat(AbstractAspectJAdvice.currentJoinPoint().getSignature().getModifiers()).isEqualTo(method.getModifiers());
MethodSignature msig = (MethodSignature) AbstractAspectJAdvice.currentJoinPoint().getSignature();
assertThat(AbstractAspectJAdvice.currentJoinPoint().getSignature()).as("Return same MethodSignature repeatedly").isSameAs(msig);
assertThat(AbstractAspectJAdvice.currentJoinPoint()).as("Return same JoinPoint repeatedly").isSameAs(AbstractAspectJAdvice.currentJoinPoint());
assertThat(msig.getDeclaringType()).isEqualTo(method.getDeclaringClass());
assertThat(Arrays.equals(method.getParameterTypes(), msig.getParameterTypes())).isTrue();
assertThat(msig.getReturnType()).isEqualTo(method.getReturnType());
assertThat(Arrays.equals(method.getExceptionTypes(), msig.getExceptionTypes())).isTrue();
msig.toLongString();
msig.toShortString();
});
ITestBean itb = (ITestBean) pf.getProxy();
// Any call will do
assertThat(itb.getAge()).as("Advice reentrantly set age").isEqualTo(newAge);
}
use of org.aspectj.lang.reflect.MethodSignature in project java-chassis by ServiceComb.
the class ZipkinSpanAspect method advise.
@Around("execution(@org.apache.servicecomb.tracing.Span * *(..)) && @annotation(spanAnnotation)")
public Object advise(ProceedingJoinPoint joinPoint, Span spanAnnotation) throws Throwable {
String spanName = spanAnnotation.spanName();
String callPath = spanAnnotation.callPath();
Method method = ((MethodSignature) joinPoint.getSignature()).getMethod();
LOG.debug("Generating zipkin span for method {}", method.toString());
if ("".equals(spanName)) {
spanName = method.getName();
}
if ("".equals(callPath)) {
callPath = method.toString();
}
return adviser.invoke(spanName, callPath, joinPoint::proceed);
}
Aggregations