Java Code Examples for org.aspectj.lang.ProceedingJoinPoint#getArgs()
The following examples show how to use
org.aspectj.lang.ProceedingJoinPoint#getArgs() .
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: IdempotentAround.java From hyena with Apache License 2.0 | 6 votes |
@Around("@annotation(Idempotent)") public Object around(ProceedingJoinPoint point) throws Throwable { Method method = ((MethodSignature) point.getSignature()).getMethod(); Idempotent shelter = method.getAnnotation(Idempotent.class); String name = shelter.name(); Object[] args = point.getArgs(); HttpServletRequest request = (HttpServletRequest) args[0]; PointOpParam param = (PointOpParam) args[1]; BaseResponse res; // String seq = request.getParameter(HyenaConstants.REQ_IDEMPOTENT_SEQ_KEY); String seq = param.getSeq(); request.setAttribute(HyenaConstants.REQ_IDEMPOTENT_SEQ_KEY, seq); res = this.preProceed(name, param, method); if (res != null) { return res; } res = (BaseResponse) point.proceed(point.getArgs()); this.postProceed(name, param, res); return res; }
Example 2
Source File: OkHttp3Probe.java From pre-dem-android with MIT License | 6 votes |
@Around("call(* okhttp3.OkHttpClient+.newCall(..))") public Object onOkHttpNew(ProceedingJoinPoint joinPoint) throws Throwable { if (!Configuration.httpMonitorEnable || joinPoint.getArgs().length != 1) { return joinPoint.proceed(); } Object[] args = joinPoint.getArgs(); Request request = (Request) args[0]; //url URL url = request.url().url(); if (GlobalConfig.isExcludeHost(url.getHost())) { return joinPoint.proceed(); } RespBean bean = new RespBean(); bean.setUrl(url.toString()); bean.setStartTimestamp(System.currentTimeMillis()); startTimeStamp.add(bean); return joinPoint.proceed(); }
Example 3
Source File: AntiBotAspect.java From CardFantasy with BSD 2-Clause "Simplified" License | 6 votes |
@Around("cfvbaibai.cardfantasy.web.aspects.AntiBotAspect.outputWebResponse()") public void setEncoding(ProceedingJoinPoint pjp) throws Throwable { try { logger.info("AntiBot advice activated on: " + pjp.getSignature().toShortString()); Object[] args = pjp.getArgs(); HttpServletRequest request = (HttpServletRequest)args[0]; if (request.getHeader("AntiBot") == null) { logger.info("Botting request from " + request.getRemoteAddr() + " found. Banned!"); HttpServletResponse response = (HttpServletResponse)args[1]; response.setStatus(403); } } catch (Exception e) { e.printStackTrace(); } finally { pjp.proceed(); } }
Example 4
Source File: AnnotationGroupIdGenerator.java From data-prep with Apache License 2.0 | 6 votes |
/** * @see GroupIdGenerator#getGroupId(ProceedingJoinPoint) */ @Override public String getGroupId(ProceedingJoinPoint pjp) { // look for the @AsyncGroupId annotated parameter int idParameterIndex = AnnotationUtils.getAnnotatedParameterIndex(pjp, AsyncGroupId.class); // to get the @AsyncGroupId parameter value final String asyncGroupId; if (idParameterIndex >= 0) { MethodSignature ms = (MethodSignature) pjp.getSignature(); final Class groupIdParameterType = ms.getParameterTypes()[idParameterIndex]; if (AsyncGroupKey.class.isAssignableFrom(groupIdParameterType)) { final AsyncGroupKey paramValue = (AsyncGroupKey) pjp.getArgs()[idParameterIndex]; asyncGroupId = paramValue.getAsyncGroupKey(); } else { asyncGroupId = String.valueOf(pjp.getArgs()[idParameterIndex]); } } else { asyncGroupId = null; } return asyncGroupId; }
Example 5
Source File: SyncDatabaseExt.java From youkefu with Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") @Around("syncDeleteEsData()") public Object syncDeleteEsData(ProceedingJoinPoint pjp) throws Throwable{ Object[] args = pjp.getArgs() ; if(args.length == 1){ Object data = args[0] ; if(data instanceof List){ List<Object> dataList = (List<Object>)data ; for(Object dbData : dataList){ UKTools.multiupdate(new MultiUpdateEvent<Object>(dbData , dbDataRes, UKDataContext.MultiUpdateType.DELETE.toString())); } }else{ if(data instanceof ESBean){ UKTools.multiupdate(new MultiUpdateEvent<Object>(data, dbDataRes, UKDataContext.MultiUpdateType.DELETE.toString())); }else{ UKTools.multiupdate(new MultiUpdateEvent<Object>(data, dbDataRes, UKDataContext.MultiUpdateType.DELETE.toString())); } } } return pjp.proceed(); }
Example 6
Source File: BindingResultAspect.java From macrozheng-mall with MIT License | 5 votes |
@Around("BindingResult()") public Object doAround(ProceedingJoinPoint joinPoint) throws Throwable { Object[] args = joinPoint.getArgs(); for (Object arg : args) { if (arg instanceof BindingResult) { BindingResult result = (BindingResult) arg; if (result.hasErrors()) { return new CommonResult().validateFailed(result); } } } return joinPoint.proceed(); }
Example 7
Source File: AroundMethodUtil.java From ProjectTree with Apache License 2.0 | 5 votes |
/** * 获取MethodId方法签名 */ public static String getMethodId(ProceedingJoinPoint pjp) { String className = pjp.getSignature().getDeclaringTypeName(); String methodName = pjp.getSignature().getName(); StringBuilder methodId = new StringBuilder(); methodId.append(className); methodId.append("x"); methodId.append(methodName); for (Object object : pjp.getArgs()) { methodId.append("x"); methodId.append(Optional.ofNullable(object).map(s -> s.getClass().getName()).orElse("null")); } return methodId.toString(); }
Example 8
Source File: SysLogAspect.java From springboot-admin with Apache License 2.0 | 5 votes |
private void saveSysLog(ProceedingJoinPoint joinPoint, long time) { MethodSignature signature = (MethodSignature) joinPoint.getSignature(); Method method = signature.getMethod(); SysLog sysLog = new SysLog(); com.vigekoo.common.annotation.SysLog log = method.getAnnotation(com.vigekoo.common.annotation.SysLog.class); if(log != null){ //注解上的描述 sysLog.setOperation(log.value()); } //请求的方法名 String className = joinPoint.getTarget().getClass().getName(); String methodName = signature.getName(); sysLog.setMethod(className + "." + methodName + "()"); //请求的参数 Object[] args = joinPoint.getArgs(); try{ String params = new Gson().toJson(args[0]); sysLog.setParams(params); }catch (Exception e){ } //获取request HttpServletRequest request = HttpContextUtils.getHttpServletRequest(); //设置IP地址 sysLog.setIp(IPUtils.getIpAddr(request)); //用户名 String username = ((SysUser) SecurityUtils.getSubject().getPrincipal()).getUsername(); sysLog.setUsername(username); sysLog.setTime(time); sysLog.setCreateTime(new Date()); //保存系统日志 sysLogService.save(sysLog); }
Example 9
Source File: OauthTokenAspect.java From microservices-platform with Apache License 2.0 | 5 votes |
@Around("execution(* org.springframework.security.oauth2.provider.endpoint.TokenEndpoint.postAccessToken(..))") public Object handleControllerMethod(ProceedingJoinPoint joinPoint) throws Throwable { try { Object[] args = joinPoint.getArgs(); Principal principal = (Principal) args[0]; if (!(principal instanceof Authentication)) { throw new InsufficientAuthenticationException( "There is no client authentication. Try adding an appropriate authentication filter."); } String clientId = getClientId(principal); Map<String, String> parameters = (Map<String, String>) args[1]; String grantType = parameters.get(OAuth2Utils.GRANT_TYPE); //保存租户id TenantContextHolder.setTenant(clientId); Object proceed = joinPoint.proceed(); if (SecurityConstants.AUTHORIZATION_CODE.equals(grantType)) { /* 如果使用 @EnableOAuth2Sso 注解不能修改返回格式,否则授权码模式可以统一改 因为本项目的 sso-demo/ss-sso 里面使用了 @EnableOAuth2Sso 注解,所以这里就不修改授权码模式的token返回值了 */ return proceed; } else { ResponseEntity<OAuth2AccessToken> responseEntity = (ResponseEntity<OAuth2AccessToken>) proceed; OAuth2AccessToken body = responseEntity.getBody(); return ResponseEntity .status(HttpStatus.OK) .body(Result.succeed(body)); } } catch (Exception e) { log.error("授权错误", e); return ResponseEntity .status(HttpStatus.BAD_REQUEST) .body(Result.failed(e.getMessage())); } finally { TenantContextHolder.clear(); } }
Example 10
Source File: LogAspect.java From openregistry with Apache License 2.0 | 5 votes |
@Around("(execution (public * org.openregistry.core..*.*(..))) && !(execution( * org.openregistry.core..*.set*(..)))") public Object traceMethod(final ProceedingJoinPoint proceedingJoinPoint) throws Throwable { Object returnVal = null; final Logger log = getLog(proceedingJoinPoint); final String methodName = proceedingJoinPoint.getSignature().getName(); try { if (log.isTraceEnabled()) { final Object[] args = proceedingJoinPoint.getArgs(); if (args == null || args.length == 0) { log.trace(this.messageSourceAccessor.getMessage(TRACE_METHOD_BEGIN, new Object[] {methodName, ""}, Locale.getDefault())); } else { final StringBuilder stringBuilder = new StringBuilder(); for (final Object o : args) { stringBuilder.append(o != null ? o.toString() : null).append(", "); } final String argString = stringBuilder.substring(0, stringBuilder.length()-3); log.trace(this.messageSourceAccessor.getMessage(TRACE_METHOD_BEGIN, new Object[] {methodName, argString}, Locale.getDefault())); } } returnVal = proceedingJoinPoint.proceed(); return returnVal; } finally { if (log.isTraceEnabled()) { log.trace(this.messageSourceAccessor.getMessage(TRACE_METHOD_END, new Object[] {methodName, (returnVal != null ? returnVal.toString() : "null")}, Locale.getDefault())); } } }
Example 11
Source File: ActivityInjection.java From FragmentRigger with MIT License | 5 votes |
@Around("onCreate()") public Object onCreateProcess(ProceedingJoinPoint joinPoint) throws Throwable { Object result = joinPoint.proceed(); Object puppet = joinPoint.getTarget(); //Only inject the class that marked by Puppet annotation. Object[] args = joinPoint.getArgs(); Method onCreate = getRiggerMethod("onCreate", Object.class, Bundle.class); onCreate.invoke(getRiggerInstance(), puppet, args[0]); return result; }
Example 12
Source File: BootApplicationInterceptor.java From spring-init with Apache License 2.0 | 5 votes |
@Around("execution(* org.springframework.boot.StartupInfoLogger.getValue(..))") public Object getValue(ProceedingJoinPoint joinPoint) throws Throwable { Object result = proceed(joinPoint); Object defaultValue = null; if (joinPoint.getArgs().length>2) { defaultValue = joinPoint.getArgs()[2]; } return result != null ? result : defaultValue; }
Example 13
Source File: RedisCachePlugin.java From pybbs with GNU Affero General Public License v3.0 | 5 votes |
@Around("co.yiiu.pybbs.hook.UserServiceHook.selectByToken()") public Object userSelectByToken(ProceedingJoinPoint proceedingJoinPoint) throws Throwable { String token = (String) proceedingJoinPoint.getArgs()[0]; String userJson = redisService.getString(String.format(RedisKeys.REDIS_USER_TOKEN_KEY, token)); if (userJson != null) { // 带泛型转换, 这里如果不带泛型转换,会报错 return JsonUtil.jsonToObject(userJson, User.class); } else { Object returnValue = proceedingJoinPoint.proceed(proceedingJoinPoint.getArgs()); redisService.setString(String.format(RedisKeys.REDIS_USER_TOKEN_KEY, token), JsonUtil.objectToJson(returnValue)); return returnValue; } }
Example 14
Source File: MockInterceptor.java From fluent-validator with Apache License 2.0 | 5 votes |
@Around("execution(* com.baidu.unbiz.fluentvalidator.service.impl.CarServiceImpl.*(..))") public Object validate4AjaxQuery(ProceedingJoinPoint pjp) throws Throwable { MethodInvocationProceedingJoinPoint methodJoinPoint = (MethodInvocationProceedingJoinPoint) pjp; MethodSignature methodSignature = (MethodSignature) methodJoinPoint.getSignature(); System.out.println("here we enter aspectJ interceptor"); Object[] args = pjp.getArgs(); System.out.println(Arrays.asList(args)); System.out.println(methodSignature); return pjp.proceed(); }
Example 15
Source File: FileListCacheAspect.java From zfile with MIT License | 5 votes |
/** * 缓存切面, 如果此驱动器开启了缓存, 则从缓存中取数据, 没有开启, 则直接调用方法. */ @Around(value = "execution(public * im.zhaojun.zfile.service.base.AbstractBaseFileService.fileList(..))") public Object around(ProceedingJoinPoint point) throws Throwable { List<FileItemDTO> result; // 获取请求路径 Object[] args = point.getArgs(); String path = String.valueOf(args[0]); // 获取当前驱动器 AbstractBaseFileService fileService = ((AbstractBaseFileService) point.getTarget()); Integer driveId = fileService.driveId; // 判断驱动器是否开启了缓存 DriveConfig driveConfig = driveConfigService.findById(driveId); boolean enableCache = driveConfig.getEnableCache(); if (enableCache) { List<FileItemDTO> cacheFileList = zFileCache.get(driveId, path); if (cacheFileList == null) { result = (List<FileItemDTO>) point.proceed(); zFileCache.put(driveId, path, result); } else { result = cacheFileList; } } else { result = (List<FileItemDTO>) point.proceed(); } return result; }
Example 16
Source File: ProcessGroupAuditor.java From nifi with Apache License 2.0 | 5 votes |
@Around("within(org.apache.nifi.web.dao.ProcessGroupDAO+) && " + "execution(org.apache.nifi.groups.ProcessGroup updateProcessGroupFlow(..))") public ProcessGroup updateProcessGroupFlowAdvice(final ProceedingJoinPoint proceedingJoinPoint) throws Throwable { final Object[] args = proceedingJoinPoint.getArgs(); final String groupId = (String) args[0]; final ProcessGroupDAO processGroupDAO = getProcessGroupDAO(); final ProcessGroup processGroup = processGroupDAO.getProcessGroup(groupId); final VersionControlInformation vci = processGroup.getVersionControlInformation(); final ProcessGroup updatedProcessGroup = (ProcessGroup) proceedingJoinPoint.proceed(); final VersionControlInformation updatedVci = updatedProcessGroup.getVersionControlInformation(); final Operation operation; if (vci == null) { operation = Operation.StartVersionControl; } else { if (updatedVci == null) { operation = Operation.StopVersionControl; } else if (vci.getVersion() == updatedVci.getVersion()) { operation = Operation.RevertLocalChanges; } else { operation = Operation.ChangeVersion; } } saveUpdateAction(groupId, operation); return updatedProcessGroup; }
Example 17
Source File: HtmlSanitizer.java From Spring5Tutorial with GNU Lesser General Public License v3.0 | 4 votes |
@Around("execution(* cc.openhome.controller.MemberController.newMessage(..))") public Object around(ProceedingJoinPoint proceedingJoinPoint) throws Throwable { Object[] args = proceedingJoinPoint.getArgs(); args[0] = policy.sanitize(args[0].toString()); return proceedingJoinPoint.proceed(args); }
Example 18
Source File: AutoLogAspect.java From teaching with Apache License 2.0 | 4 votes |
private void saveSysLog(ProceedingJoinPoint joinPoint, long time) { MethodSignature signature = (MethodSignature) joinPoint.getSignature(); Method method = signature.getMethod(); SysLog sysLog = new SysLog(); AutoLog syslog = method.getAnnotation(AutoLog.class); if(syslog != null){ //注解上的描述,操作日志内容 sysLog.setLogContent(syslog.value()); sysLog.setLogType(syslog.logType()); } //请求的方法名 String className = joinPoint.getTarget().getClass().getName(); String methodName = signature.getName(); sysLog.setMethod(className + "." + methodName + "()"); //设置操作类型 if (sysLog.getLogType() == CommonConstant.LOG_TYPE_2) { sysLog.setOperateType(getOperateType(methodName, syslog.operateType())); } //请求的参数 Object[] args = joinPoint.getArgs(); try{ String params = JSONObject.toJSONString(args); sysLog.setRequestParam(params); }catch (Exception e){ } //获取request HttpServletRequest request = SpringContextUtils.getHttpServletRequest(); //设置IP地址 sysLog.setIp(IPUtils.getIpAddr(request)); //获取登录用户信息 LoginUser sysUser = (LoginUser)SecurityUtils.getSubject().getPrincipal(); if(sysUser!=null){ sysLog.setUserid(sysUser.getUsername()); sysLog.setUsername(sysUser.getRealname()); } //耗时 sysLog.setCostTime(time); sysLog.setCreateTime(new Date()); //保存系统日志 sysLogService.save(sysLog); }
Example 19
Source File: LogOperationAspect.java From GreenSummer with GNU Lesser General Public License v2.1 | 4 votes |
@Around("(" + "@annotation(org.springframework.web.bind.annotation.RequestMapping)" + "|| @annotation(org.springframework.web.bind.annotation.GetMapping)" + "|| @annotation(org.springframework.web.bind.annotation.PostMapping)" + "|| @annotation(org.springframework.web.bind.annotation.PutMapping)" + "|| @annotation(org.springframework.web.bind.annotation.DeleteMapping)" + "|| @annotation(org.springframework.web.bind.annotation.PatchMapping)" + "|| @annotation(org.greeneyed.summer.monitoring.LogOperation)" + ")" + "&& !@annotation(org.greeneyed.summer.monitoring.DontLogOperation)") //@formatter:on public Object logMethodCall( ProceedingJoinPoint joinPoint) throws Throwable { MethodSignature methodSignature = (MethodSignature) joinPoint.getStaticPart().getSignature(); Method method = methodSignature.getMethod(); final String packageName = method.getDeclaringClass().getPackage().getName(); Throwable errorProduced = null; Object result = null; if (packages == null || packages.stream().anyMatch(packageName::startsWith)) { Object[] args = joinPoint.getArgs(); String userID = null; if (args.length > 0 && args[0] != null) { if (args[0] instanceof IdentifiedUser) { userID = ((IdentifiedUser) args[0]).getName(); } else if (args[0] instanceof Supplier) { userID = ((Supplier<?>) args[0]).get().toString(); } else if (args[0] instanceof Principal) { userID = ((Principal) args[0]).getName(); } } try { if (userID != null) { MDC.put(PRINCIPAL_LABEL, userID); } result = joinPoint.proceed(); } catch (Throwable t) { errorProduced = t; throw t; } finally { if (logOperations) { final String operationName = extractOperationName(method); if (operationName != null) { try { MDC.put(OPERATION_LABEL, operationName); StringBuilder theSB = extractArguments(method, args); if (errorProduced != null) { log.error("Performed: {}{}|{}", operationName, theSB.toString(), errorProduced.getClass().getSimpleName()); } else if (result != null && result instanceof ResponseEntity) { log.info("Performed: {}{}|{}", operationName, theSB.toString(), ((ResponseEntity<?>) result).getStatusCodeValue()); } else { log.info("Performed: {}{}", operationName, theSB.toString()); } } finally { MDC.remove(OPERATION_LABEL); } } } MDC.remove(PRINCIPAL_LABEL); } } else { result = joinPoint.proceed(); } return result; }
Example 20
Source File: SysLogAspect.java From xmanager with Apache License 2.0 | 4 votes |
@Around("cutController()") public Object recordSysLog(ProceedingJoinPoint point) throws Throwable { String strMethodName = point.getSignature().getName(); String strClassName = point.getTarget().getClass().getName(); Object[] params = point.getArgs(); StringBuffer bfParams = new StringBuffer(); Enumeration<String> paraNames = null; HttpServletRequest request = null; if (params != null && params.length > 0) { request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); paraNames = request.getParameterNames(); String key; String value; while (paraNames.hasMoreElements()) { key = paraNames.nextElement(); value = request.getParameter(key); bfParams.append(key).append("=").append(value).append("&"); } if (StringUtils.isBlank(bfParams)) { bfParams.append(request.getQueryString()); } } String strMessage = String .format("[类名]:%s,[方法]:%s,[参数]:%s", strClassName, strMethodName, bfParams.toString()); LOGGER.info(strMessage); if (isWriteLog(strMethodName)) { try { Subject currentUser = SecurityUtils.getSubject(); PrincipalCollection collection = currentUser.getPrincipals(); if (null != collection) { String loginName = collection.getPrimaryPrincipal().toString(); SysLog sysLog = new SysLog(); sysLog.setLoginName(loginName); sysLog.setRoleName(loginName); sysLog.setOptContent(strMessage); sysLog.setCreateTime(new Date()); if (request != null) { sysLog.setClientIp(request.getRemoteAddr()); } LOGGER.info(sysLog.toString()); sysLogService.insert(sysLog); } } catch (Exception e) { LOGGER.error(e.getMessage(), e); } } return point.proceed(); }