use of org.aspectj.lang.reflect.MethodSignature in project head by mifos.
the class AspectJRESTApprovalInterceptor method profile.
@Around("restMethods() && requestMapping() && excludeAPI() && exludeRestfulServices()")
public Object profile(ProceedingJoinPoint pjp) throws Throwable {
Signature signature = pjp.getStaticPart().getSignature();
LOG.debug(this.getClass().getSimpleName() + " staring");
// FIXME : somehow autowiring is not working
if (approvalService == null) {
approvalService = ApplicationContextProvider.getBean(ApprovalService.class);
}
if (configurationServiceFacade == null) {
configurationServiceFacade = ApplicationContextProvider.getBean(ConfigurationServiceFacade.class);
}
if (parameterNameDiscoverer == null) {
parameterNameDiscoverer = ApplicationContextProvider.getBean(ParameterNameDiscoverer.class);
}
if (!RESTConfigKey.isApprovalRequired(configurationServiceFacade)) {
LOG.debug(pjp.getSignature() + " skip approval");
return pjp.proceed();
}
if (signature instanceof MethodSignature) {
MethodSignature ms = (MethodSignature) signature;
Method m = ms.getMethod();
RequestMapping mapping = m.getAnnotation(RequestMapping.class);
if (isReadOnly(mapping)) {
LOG.debug(m.getName() + " is read only, hence returning control");
return pjp.proceed();
}
Class<?> methodClassType = m.getDeclaringClass();
if (!methodClassType.getSimpleName().endsWith("RESTController")) {
LOG.debug(m.getName() + " is not from REST controller, hence returning control");
return pjp.proceed();
}
Object[] argValues = pjp.getArgs();
Class<?>[] argTypes = m.getParameterTypes();
String methodName = m.getName();
String[] names = parameterNameDiscoverer.getParameterNames(m);
MethodArgHolder args = new MethodArgHolder(argTypes, argValues, names);
ApprovalMethod method = new ApprovalMethod(methodName, methodClassType, args);
approvalService.create(method);
}
return pjp.proceed();
}
use of org.aspectj.lang.reflect.MethodSignature in project AndroidDevMetrics by frogermcs.
the class ActivityLifecycleAnalyzer method logAndExecute.
@Around("onCreateMethod() || onStartMethod() || onResumeMethod()")
public Object logAndExecute(ProceedingJoinPoint joinPoint) throws Throwable {
if (!enabled)
return joinPoint.proceed();
MethodSignature signature = (MethodSignature) joinPoint.getSignature();
String methodName = signature.getMethod().getName();
final Object result;
if (METHOD_ON_RESUME.equals(methodName)) {
ActivityLifecycleMetrics.getInstance().logPreOnResume((Activity) joinPoint.getTarget());
result = executeWithTracingIfEnabled(joinPoint, methodName);
ActivityLifecycleMetrics.getInstance().logPostOnResume((Activity) joinPoint.getTarget());
} else if (METHOD_ON_START.equals(methodName)) {
ActivityLifecycleMetrics.getInstance().logPreOnStart((Activity) joinPoint.getTarget());
result = executeWithTracingIfEnabled(joinPoint, methodName);
ActivityLifecycleMetrics.getInstance().logPostOnStart((Activity) joinPoint.getTarget());
} else if (METHOD_ON_CREATE.equals(methodName)) {
ActivityLifecycleMetrics.getInstance().logPreOnCreate((Activity) joinPoint.getTarget());
result = executeWithTracingIfEnabled(joinPoint, methodName);
ActivityLifecycleMetrics.getInstance().logPostOnCreate((Activity) joinPoint.getTarget());
} else {
result = null;
}
return result;
}
use of org.aspectj.lang.reflect.MethodSignature in project dq-easy-cloud by dq-open-cloud.
the class DqLogBO method buildDqLogData.
/**
* <p>
* 构建日志数据
* </p>
*
* @param pjp
* @return
* @author daiqi
* 创建时间 2018年2月9日 上午11:14:51
*/
public DqLogBO buildDqLogData(ProceedingJoinPoint pjp) {
Signature signature = pjp.getSignature();
MethodSignature methodSignature = (MethodSignature) signature;
Method targetMethod = methodSignature.getMethod();
Class<?> targetClass = pjp.getTarget().getClass();
this.buildTargetClassName(targetClass.getName()).buildTargetMethodName(targetMethod.getName());
this.buildTargetParameterTypes(targetMethod.getParameterTypes()).buildTargetParameterValues(pjp.getArgs());
this.buildTargetReturnType(targetMethod.getReturnType()).buildLogger(targetClass);
this.buildRequestPath().buildDqLog(targetClass, targetMethod);
return this;
}
use of org.aspectj.lang.reflect.MethodSignature in project entando-core by entando.
the class CacheInfoManager method aroundCacheInfoEvictMethod.
@Around("@annotation(cacheInfoEvict)")
public Object aroundCacheInfoEvictMethod(ProceedingJoinPoint pjp, CacheInfoEvict cacheInfoEvict) throws Throwable {
try {
MethodSignature methodSignature = (MethodSignature) pjp.getSignature();
Method targetMethod = methodSignature.getMethod();
Class targetClass = pjp.getTarget().getClass();
Method effectiveTargetMethod = targetClass.getMethod(targetMethod.getName(), targetMethod.getParameterTypes());
String[] cacheNames = cacheInfoEvict.value();
Object groupsCsv = this.evaluateExpression(cacheInfoEvict.groups().toString(), targetMethod, pjp.getArgs(), effectiveTargetMethod, targetClass);
if (null != groupsCsv && groupsCsv.toString().trim().length() > 0) {
String[] groups = groupsCsv.toString().split(",");
for (String group : groups) {
for (String cacheName : cacheNames) {
this.flushGroup(cacheName, group);
}
}
}
} catch (Throwable t) {
logger.error("Error while flushing group", t);
throw new ApsSystemException("Error while flushing group", t);
}
return pjp.proceed();
}
use of org.aspectj.lang.reflect.MethodSignature in project bamboobsc by billchen198318.
the class HessianServiceProxyAspect method proxyProcess.
private Object proxyProcess(ProceedingJoinPoint pjp) throws AuthorityException, ServiceException, Throwable {
MethodSignature signature = (MethodSignature) pjp.getSignature();
Annotation[] annotations = pjp.getTarget().getClass().getAnnotations();
String serviceId = AspectConstants.getServiceId(annotations);
/**
* 不需要被遠端代理的 service-bean
*/
if (!GreenStepHessianUtils.isProxyServiceId(serviceId)) {
//logger.info( "reject proxy service: " + serviceId );
return pjp.proceed();
}
String userId = StringUtils.defaultString((String) SecurityUtils.getSubject().getPrincipal());
if (GreenStepHessianUtils.getConfigHessianHeaderCheckValueModeEnable()) {
/**
* 沒使用者資訊不能處理遠端代理的 service-bean
*/
if (StringUtils.isBlank(userId)) {
logger.warn("no userId");
pjp.proceed();
}
/**
* 此使用者不能存取遠端代理的 service-bean
*/
if (GreenStepHessianUtils.isProxyBlockedAccountId(userId)) {
logger.warn("reject proxy service: " + serviceId + " , blocked userId: " + userId);
return pjp.proceed();
}
}
String serviceInterfacesName = "";
Class<?>[] serviceInterfaces = pjp.getTarget().getClass().getInterfaces();
for (Class<?> clazz : serviceInterfaces) {
if (clazz.getName().indexOf(".service.") > -1) {
serviceInterfacesName = clazz.getName();
}
}
if (StringUtils.isBlank(serviceInterfacesName)) {
logger.error("error no service interface: " + serviceId);
throw new Exception("error no service interface: " + serviceId);
}
String url = GreenStepHessianUtils.getServiceUrl(serviceId);
String theSystemPath = ApplicationSiteUtils.getHost(Constants.getSystem()) + "/" + ApplicationSiteUtils.getContextPath(Constants.getSystem());
/**
* 不要自己呼叫遠端代理的自己, 會造成 HessianServiceProxyAspect 一直重複觸發 (客戶端與server-remote同一台的情況下)
* 如客戶端是 http://127.0.0.1:8080/
* 但是客戶端有開啟 hessian.enable=Y 呼叫遠端代理, 然後遠端url設定為 hessian.serverUrl=http://127.0.0.1:8080/
*
*/
if (url.indexOf(theSystemPath) > -1) {
logger.error("cannot open same-server. now system contextPath = " + theSystemPath + " , but proxy url = " + url);
throw new Exception("cannot open same-server. now system contextPath = " + theSystemPath + " , but proxy url = " + url);
}
logger.info("proxy url = " + url);
HessianProxyFactory factory = null;
Object proxyServiceObject = null;
if (GreenStepHessianUtils.getConfigHessianHeaderCheckValueModeEnable()) {
// 一般要checkValue模式
factory = new GreenStepHessianProxyFactory();
((GreenStepHessianProxyFactory) factory).setHeaderCheckValue(GreenStepHessianUtils.getEncAuthValue(userId));
proxyServiceObject = ((GreenStepHessianProxyFactory) factory).createForHeaderMode(Class.forName(serviceInterfacesName), url);
} else {
// 不使用checkValue模式
factory = new HessianProxyFactory();
proxyServiceObject = factory.create(Class.forName(serviceInterfacesName), url);
}
Method[] proxyObjectMethods = proxyServiceObject.getClass().getMethods();
Method proxyObjectMethod = null;
if (null == proxyObjectMethods) {
logger.error("error no find proxy method: " + serviceId);
throw new Exception("error no find proxy method: " + serviceId);
}
for (Method m : proxyObjectMethods) {
if (m.getName().equals(signature.getMethod().getName()) && Arrays.equals(m.getParameterTypes(), signature.getMethod().getParameterTypes())) {
proxyObjectMethod = m;
}
}
if (null == proxyObjectMethod) {
logger.error("error no execute proxy method: " + serviceId);
throw new Exception("error no execute proxy method: " + serviceId);
}
Object resultObj = null;
try {
resultObj = proxyObjectMethod.invoke(proxyServiceObject, pjp.getArgs());
this.setReCalculateSizePageOfForPageFindGridResult(resultObj, pjp.getArgs());
} catch (InvocationTargetException e) {
if (e.getMessage() != null) {
throw new ServiceException(e.getMessage().toString());
}
if (e.getTargetException().getMessage() != null) {
throw new ServiceException(e.getTargetException().getMessage().toString());
}
throw e;
} catch (Exception e) {
logger.error(e.getMessage().toString());
throw e;
}
logger.info("proxy success: " + serviceId + " method: " + proxyObjectMethod.getName());
return resultObj;
}
Aggregations