Java Code Examples for org.aspectj.lang.reflect.MethodSignature#getMethod()
The following examples show how to use
org.aspectj.lang.reflect.MethodSignature#getMethod() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AJExtender.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
/** * @param method * @return <code>true</code> if the given method has the same signature as * the currently aspectJ extension-overridden method */ static boolean isLocalProceeder(Method method) { if (!ajLocalProceedingJoinPoints.get().isEmpty()) { ProceedingContext proceedingCotext = ajLocalProceedingJoinPoints.get().peek(); MethodSignature ms = (MethodSignature) proceedingCotext.proceedingJoinPoint.getSignature(); Method jpMethod = ms.getMethod(); return jpMethod.getName().endsWith(method.getName()) && Arrays.equals(jpMethod.getParameterTypes(), method.getParameterTypes()); } else { return false; } }
Example 2
Source File: MythTransactionEngine.java From myth with Apache License 2.0 | 6 votes |
private MythTransaction buildMythTransaction(final ProceedingJoinPoint point, final int role, final int status, final String transId) { MythTransaction mythTransaction; if (StringUtils.isNoneBlank(transId)) { mythTransaction = new MythTransaction(transId); } else { mythTransaction = new MythTransaction(); } MethodSignature signature = (MethodSignature) point.getSignature(); Method method = signature.getMethod(); Class<?> clazz = point.getTarget().getClass(); mythTransaction.setStatus(status); mythTransaction.setRole(role); mythTransaction.setTargetClass(clazz.getName()); mythTransaction.setTargetMethod(method.getName()); return mythTransaction; }
Example 3
Source File: CachingAnnotationsAspect.java From jim-framework with Apache License 2.0 | 6 votes |
private Method getSpecificmethod(ProceedingJoinPoint pjp) { MethodSignature methodSignature = (MethodSignature) pjp.getSignature(); Method method = methodSignature.getMethod(); // The method may be on an interface, but we need attributes from the // target class. If the target class is null, the method will be // unchanged. Class<?> targetClass = AopProxyUtils.ultimateTargetClass(pjp.getTarget()); if (targetClass == null && pjp.getTarget() != null) { targetClass = pjp.getTarget().getClass(); } Method specificMethod = ClassUtils.getMostSpecificMethod(method, targetClass); // If we are dealing with method with generic parameters, find the // original method. specificMethod = BridgeMethodResolver.findBridgedMethod(specificMethod); return specificMethod; }
Example 4
Source File: LogAspect.java From RuoYi with Apache License 2.0 | 5 votes |
/** * 是否存在注解,如果存在就获取 */ private Log getAnnotationLog(JoinPoint joinPoint) { Signature signature = joinPoint.getSignature(); MethodSignature methodSignature = (MethodSignature) signature; Method method = methodSignature.getMethod(); if (method != null) { return method.getAnnotation(Log.class); } return null; }
Example 5
Source File: WebLogAspect.java From macrozheng-mall with MIT License | 5 votes |
@Around("webLog()") public Object doAround(ProceedingJoinPoint joinPoint) throws Throwable { //获取当前请求对象 ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); HttpServletRequest request = attributes.getRequest(); //记录请求信息(通过logstash传入elasticsearch) WebLog webLog = new WebLog(); Object result = joinPoint.proceed(); Signature signature = joinPoint.getSignature(); MethodSignature methodSignature = (MethodSignature) signature; Method method = methodSignature.getMethod(); if (method.isAnnotationPresent(ApiOperation.class)) { ApiOperation log = method.getAnnotation(ApiOperation.class); webLog.setDescription(log.value()); } long endTime = System.currentTimeMillis(); webLog.setBasePath(RequestUtil.getBasePath(request)); webLog.setIp(request.getRemoteUser()); webLog.setMethod(request.getMethod()); webLog.setParameter(getParameter(method, joinPoint.getArgs())); webLog.setResult(result); webLog.setSpendTime((int) (endTime - startTime.get())); webLog.setStartTime(startTime.get()); webLog.setUri(request.getRequestURI()); webLog.setUrl(request.getRequestURL().toString()); Map<String,Object> logMap = new HashMap<>(); logMap.put("url",webLog.getUrl()); logMap.put("method",webLog.getMethod()); logMap.put("parameter",webLog.getParameter()); logMap.put("spendTime",webLog.getSpendTime()); logMap.put("description",webLog.getDescription()); // LOGGER.info("{}", JsonUtil.objectToJson(webLog)); LOGGER.info(Markers.appendEntries(logMap),JsonUtil.objectToJson(webLog)); return result; }
Example 6
Source File: MybatisPluginBaseSpringInterceptor.java From jeesuite-libs with Apache License 2.0 | 5 votes |
@Around("pointcut()") public Object around(ProceedingJoinPoint pjp) throws Throwable { boolean doContextInit = MybatisRuntimeContext.isEmpty(); try { MethodSignature methodSignature = (MethodSignature)pjp.getSignature(); Method method = methodSignature.getMethod(); if(doContextInit){ if(method.isAnnotationPresent(Transactional.class)){ MybatisRuntimeContext.setTransactionalMode(true); } if(method.isAnnotationPresent(UseMaster.class)){ MybatisRuntimeContext.forceMaster(); } } customBeforeEvent(method, pjp.getArgs()); return pjp.proceed(); } catch (Exception e) { CacheHandler.rollbackCache(); throw e; }finally { if(doContextInit){ MybatisRuntimeContext.unset(); } } }
Example 7
Source File: RestControllerAspect.java From XUpdateService with Apache License 2.0 | 5 votes |
/** * 环绕通知 * @param joinPoint 连接点 * @return 切入点返回值 * @throws Throwable 异常信息 */ @Around("@within(org.springframework.web.bind.annotation.RestController) || @annotation(org.springframework.web.bind.annotation.RestController)") public Object apiLog(ProceedingJoinPoint joinPoint) throws Throwable { MethodSignature signature = (MethodSignature) joinPoint.getSignature(); Method method = signature.getMethod(); boolean logFlag = this.needToLog(method); if (!logFlag) { return joinPoint.proceed(); } HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); String userAgent = request.getHeader("user-agent"); String ip = IpUtils.getRealIp(request); String methodName = AspectJUtils.getMethodName(joinPoint); String params = AspectJUtils.getMethodParams(joinPoint); logger.info("\n\r" + "---------->|开始请求方法:{} \n\r" + " |请求参数:{} \n\r" + " |IP:{} \n\r" + " |userAgent:{}", methodName, params, ip, userAgent); long start = System.currentTimeMillis(); Object result = joinPoint.proceed(); long end = System.currentTimeMillis(); String deleteSensitiveContent = AspectJUtils.deleteSensitiveContent(result); logger.info("\n\r" + "<----------|结束请求方法:{}\n\r" + " |返回结果{} \n\r" + " |耗时:{}毫秒 ", methodName, deleteSensitiveContent, end - start); return result; }
Example 8
Source File: LogAspect.java From Java-API-Test-Examples with Apache License 2.0 | 5 votes |
/** * 切换方法,记录日志 * @param joinPoint * @return * @throws Throwable */ @Around("serviceLog()") public Object around(ProceedingJoinPoint joinPoint) throws Throwable { MethodSignature signature = (MethodSignature) joinPoint.getSignature(); Method method = signature.getMethod(); Class<?> targetClass = method.getDeclaringClass(); StringBuffer classAndMethod = new StringBuffer(); Log classAnnotation = targetClass.getAnnotation(Log.class); Log methodAnnotation = method.getAnnotation(Log.class); if (classAnnotation != null) { if (classAnnotation.ignore()) { return joinPoint.proceed(); } classAndMethod.append(classAnnotation.value()).append("-"); } if (methodAnnotation != null) { if (methodAnnotation.ignore()) { return joinPoint.proceed(); } classAndMethod.append(methodAnnotation.value()); } String target = targetClass.getName() + "#" + method.getName(); String params = null; params = JSONObject.toJSONStringWithDateFormat(joinPoint.getArgs(), dateFormat, SerializerFeature.WriteMapNullValue); log.info(STRING_START + "{} 开始调用--> {} 参数:{}", classAndMethod.toString(), target, params); long start = System.currentTimeMillis(); Object result = joinPoint.proceed(); long timeConsuming = System.currentTimeMillis() - start; log.info("\n{} 调用结束<-- {} 返回值:{} 耗时:{}ms" + STRING_END, classAndMethod.toString(), target, JSONObject.toJSONStringWithDateFormat(result, dateFormat, SerializerFeature.WriteMapNullValue), timeConsuming); return result; }
Example 9
Source File: WebLogAspect.java From BigDataPlatform with GNU General Public License v3.0 | 5 votes |
@Around("webLog()") public Object doAround(ProceedingJoinPoint joinPoint) throws Throwable { long startTime = System.currentTimeMillis(); //获取当前请求对象 ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); HttpServletRequest request = attributes.getRequest(); //记录请求信息(通过Logstash传入Elasticsearch) WebLog webLog = new WebLog(); Object result = joinPoint.proceed(); Signature signature = joinPoint.getSignature(); MethodSignature methodSignature = (MethodSignature) signature; Method method = methodSignature.getMethod(); if (method.isAnnotationPresent(ApiOperation.class)) { ApiOperation log = method.getAnnotation(ApiOperation.class); webLog.setDescription(log.value()); } long endTime = System.currentTimeMillis(); String urlStr = request.getRequestURL().toString(); webLog.setBasePath(StrUtil.removeSuffix(urlStr, URLUtil.url(urlStr).getPath())); webLog.setIp(request.getRemoteUser()); webLog.setMethod(request.getMethod()); webLog.setParameter(getParameter(method, joinPoint.getArgs())); webLog.setResult(result); webLog.setSpendTime((int) (endTime - startTime)); webLog.setStartTime(startTime); webLog.setUri(request.getRequestURI()); webLog.setUrl(request.getRequestURL().toString()); Map<String, Object> logMap = new HashMap<>(); logMap.put("url", webLog.getUrl()); logMap.put("method", webLog.getMethod()); logMap.put("parameter", webLog.getParameter()); logMap.put("spendTime", webLog.getSpendTime()); logMap.put("description", webLog.getDescription()); // LOGGER.info("{}", JSONUtil.parse(webLog)); LOGGER.info(Markers.appendEntries(logMap), JSONUtil.parse(webLog).toString()); return result; }
Example 10
Source File: TeaSpoonProcessor.java From teaspoon with Apache License 2.0 | 5 votes |
@Around("methodWithOnUiAnnotation()") public void methodWithOnUiAnnotation(final ProceedingJoinPoint joinPoint) { Runnable runnableJoinPoint = new Runnable() { @Override public void run() { try { joinPoint.proceed(); } catch (Throwable throwable) { throw new IllegalStateException(throwable); } } }; MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature(); Method method = methodSignature.getMethod(); int methodHashCode = method.hashCode(); int delay; if (processedMap.containsKey(methodHashCode)) { delay = processedMap.get(methodHashCode); } else { delay = processMethodAndGetDelay(method); processedMap.put(methodHashCode, delay); } TeaSpoon.getInstance().onUi(runnableJoinPoint, delay); }
Example 11
Source File: TimerAspect.java From jigsaw-payment with Apache License 2.0 | 5 votes |
private Timer getTimerAnnotation(ProceedingJoinPoint joinPoint) throws NoSuchMethodException { MethodSignature signature = (MethodSignature) joinPoint.getSignature(); Method method = signature.getMethod(); Timer timer = method.getAnnotation(Timer.class); if (timer == null && method.getDeclaringClass().isInterface()) { final String methodName = signature.getName(); final Class<?> implementationClass = joinPoint.getTarget() .getClass(); final Method implementationMethod = implementationClass .getDeclaredMethod(methodName, method.getParameterTypes()); timer = implementationMethod.getAnnotation(Timer.class); } return timer; }
Example 12
Source File: DataSourceAspect.java From SuperBoot with MIT License | 5 votes |
@Around("execution(public * org.superboot.dao.jpa..*.*(..))") public Object around(ProceedingJoinPoint pjp) throws Throwable { MethodSignature methodSignature = (MethodSignature) pjp.getSignature(); Method targetMethod = methodSignature.getMethod(); //根据注解判断数据源 if (targetMethod.isAnnotationPresent(TargetDataSource.class)) { String targetDataSource = targetMethod.getAnnotation(TargetDataSource.class).dataSource(); DynamicDataSourceHolder.setDataSource(targetDataSource); } else { //保存使用写数据源 if (pjp.getSignature().getName().startsWith("save")) { DynamicDataSourceHolder.setDataSource(DataSourceConfig.WRITE_DATASOURCE_KEY); } //删除使用写数据源 else if (pjp.getSignature().getName().startsWith("delete")) { DynamicDataSourceHolder.setDataSource(DataSourceConfig.WRITE_DATASOURCE_KEY); } //查询使用读数据源 else if (pjp.getSignature().getName().startsWith("find")) { DynamicDataSourceHolder.setDataSource(DataSourceConfig.READ_DATASOURCE_KEY); } //保存使用写数据源 else if (pjp.getSignature().getName().startsWith("get")) { DynamicDataSourceHolder.setDataSource(DataSourceConfig.READ_DATASOURCE_KEY); } else { //默认使用写数据源 DynamicDataSourceHolder.setDataSource(DataSourceConfig.WRITE_DATASOURCE_KEY); } } logger.info("操作使用数据源:" + DynamicDataSourceHolder.getDataSource()); //执行方法 Object result = pjp.proceed(); DynamicDataSourceHolder.clearDataSource(); return result; }
Example 13
Source File: SwitcherProxyImpl.java From onetwo with Apache License 2.0 | 5 votes |
@Override public void processSwitchInfo(JoinPoint pjp){ final MethodSignature ms = (MethodSignature) pjp.getSignature(); SwitcherInfo info = null; info = contextHolder.getContextAttribute(SwitcherInfo.CURRENT_SWITCHER_INFO); if(info!=null) return ; try { info = this.switcherCaches.get(ms.getMethod(), new Callable<SwitcherInfo>() { @Override public SwitcherInfo call() throws Exception { SwitcherInfo switcherInfo = null; Switcher dsw = AnnotationUtils.findAnnotationWithStopClass(ms.getDeclaringType(), ms.getMethod(), Switcher.class, Object.class); if(dsw==null){ Transactional tnl = AnnotationUtils.findAnnotationWithStopClass(ms.getDeclaringType(), ms.getMethod(), Transactional.class, Object.class); if(tnl!=null){ switcherInfo = new SwitcherInfo(tnl.value(), Type.TransactionManager); }else{ switcherInfo = SwitcherInfo.DEFAULT_INFO; } }else{ switcherInfo = new SwitcherInfo(dsw.value()); } return switcherInfo; } }); } catch (ExecutionException e) { throw new BaseException("get switcher error: " + ms.getMethod()); } contextHolder.setContextAttribute(SwitcherInfo.CURRENT_SWITCHER_INFO, info); }
Example 14
Source File: LogAspect.java From FEBS-Security with Apache License 2.0 | 5 votes |
@Async public void saveLog(ProceedingJoinPoint joinPoint, long time, String ip) throws IOException { Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal(); String principalJson = objectMapper.writeValueAsString(principal); JsonNode node = objectMapper.readTree(principalJson); String usrename = node.get("username").asText(); MethodSignature signature = (MethodSignature) joinPoint.getSignature(); Method method = signature.getMethod(); SysLog log = new SysLog(); Log logAnnotation = method.getAnnotation(Log.class); if (logAnnotation != null) { // 注解上的描述 log.setOperation(logAnnotation.value()); } // 请求的类名 String className = joinPoint.getTarget().getClass().getName(); // 请求的方法名 String methodName = signature.getName(); log.setMethod(className + "." + methodName + "()"); // 请求的方法参数值 Object[] args = joinPoint.getArgs(); // 请求的方法参数名称 LocalVariableTableParameterNameDiscoverer u = new LocalVariableTableParameterNameDiscoverer(); String[] paramNames = u.getParameterNames(method); if (args != null && paramNames != null) { StringBuilder params = new StringBuilder(); params = handleParams(params, args, Arrays.asList(paramNames)); log.setParams(params.toString()); } // 设置IP地址 log.setIp(ip); log.setUsername(usrename); log.setTime(time); log.setCreateTime(new Date()); log.setLocation(AddressUtils.getCityInfo(log.getIp())); // 保存系统日志 this.logService.save(log); }
Example 15
Source File: CacheAspect.java From ace-cache with Apache License 2.0 | 5 votes |
@Around("aspect()&&@annotation(anno)") public Object interceptor(ProceedingJoinPoint invocation, Cache anno) throws Throwable { MethodSignature signature = (MethodSignature) invocation.getSignature(); Method method = signature.getMethod(); Object result = null; Class<?>[] parameterTypes = method.getParameterTypes(); Object[] arguments = invocation.getArgs(); String key = ""; String value = ""; try { key = getKey(anno, parameterTypes, arguments); value = cacheAPI.get(key); Type returnType = method.getGenericReturnType(); result = getResult(anno, result, value, returnType); } catch (Exception e) { log.error("获取缓存失败:" + key, e); } finally { if (result == null) { result = invocation.proceed(); if (StringUtils.isNotBlank(key)) { cacheAPI.set(key, result, anno.expire()); } } } return result; }
Example 16
Source File: RbacAnnotationConfig.java From springboot-plus with BSD 3-Clause "New" or "Revised" License | 5 votes |
@org.aspectj.lang.annotation.Around("within(@org.springframework.stereotype.Controller *) && @annotation(function)") public Object functionAccessCheck(final ProceedingJoinPoint pjp, Function function) throws Throwable { // debug String funCode = null; CoreUser user = null; Method m = null; try { if (function != null) { funCode = function.value(); user = platformService.getCurrentUser(); Long orgId = platformService.getCurrentOrgId(); boolean access = platformService.canAcessFunction(user.getId(), orgId, funCode); if (!access) { log.warn(jsonMapper.writeValueAsString(user) + "试图访问未授权功能 " + funCode); throw new PlatformException("试图访问未授权功能"); } FunctionLocal.set(funCode); } Object o = pjp.proceed(); if (function != null) { MethodSignature ms = (MethodSignature)pjp.getSignature(); m = ms.getMethod(); createAudit(funCode,function.name(), user, true, "",m); } return o; } catch (Throwable e) { if (function != null) { createAudit(funCode, function.name(),user, false, e.getMessage(),m); } throw e; } }
Example 17
Source File: WebLogAspect.java From HIS with Apache License 2.0 | 5 votes |
@Around("webLog()") public Object doAround(ProceedingJoinPoint joinPoint) throws Throwable { //获取当前请求对象 ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); HttpServletRequest request = attributes.getRequest(); //记录请求信息(通过logstash传入elasticsearch) WebLog webLog = new WebLog(); Object result = joinPoint.proceed(); Signature signature = joinPoint.getSignature(); MethodSignature methodSignature = (MethodSignature) signature; Method method = methodSignature.getMethod(); if (method.isAnnotationPresent(ApiOperation.class)) { ApiOperation log = method.getAnnotation(ApiOperation.class); webLog.setDescription(log.value()); } long endTime = System.currentTimeMillis(); String urlStr = request.getRequestURL().toString(); webLog.setBasePath(StrUtil.removeSuffix(urlStr, URLUtil.url(urlStr).getPath())); webLog.setIp(request.getRemoteUser()); webLog.setMethod(request.getMethod()); webLog.setParameter(getParameter(method, joinPoint.getArgs())); webLog.setResult(result); webLog.setSpendTime((int) (endTime - startTime.get())); webLog.setStartTime(startTime.get()); webLog.setUri(request.getRequestURI()); webLog.setUrl(request.getRequestURL().toString()); Map<String,Object> logMap = new HashMap<>(); logMap.put("url",webLog.getUrl()); logMap.put("method",webLog.getMethod()); logMap.put("parameter",webLog.getParameter()); logMap.put("spendTime",webLog.getSpendTime()); logMap.put("description",webLog.getDescription()); // LOGGER.info("{}", JSONUtil.parse(webLog)); LOGGER.info(Markers.appendEntries(logMap), JSONUtil.parse(webLog).toString()); return result; }
Example 18
Source File: AspectUtils.java From network-spring-boot-starter with Apache License 2.0 | 4 votes |
public static Method getMethod(ProceedingJoinPoint proceedingJoinPoint) { MethodSignature signature = (MethodSignature) proceedingJoinPoint.getSignature(); return signature.getMethod(); }
Example 19
Source File: DisconfAspectJ.java From disconf with Apache License 2.0 | 4 votes |
/** * 获取配置文件数据, 只有开启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; }
Example 20
Source File: MqProducerStoreAspect.java From paascloud-master with Apache License 2.0 | 4 votes |
private static MqProducerStore getAnnotation(JoinPoint joinPoint) { MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature(); Method method = methodSignature.getMethod(); return method.getAnnotation(MqProducerStore.class); }