List of usage examples for org.aspectj.lang ProceedingJoinPoint getArgs
Object[] getArgs();
From source file:hr.fer.zemris.vhdllab.service.aspect.LogAspect.java
License:Apache License
@Around("services()") public Object logExecution(ProceedingJoinPoint pjp) throws Throwable { long start = 0; String callSignature = null;/*from w w w . j av a2 s.co m*/ String arguments = null; if (LOG.isTraceEnabled()) { Signature signature = pjp.getSignature(); callSignature = signature.getDeclaringType().getSimpleName() + "." + signature.getName(); arguments = Arrays.toString(pjp.getArgs()); LOG.trace("Entering " + callSignature + " with arguments: " + arguments); start = System.currentTimeMillis(); } Object returnValue = pjp.proceed(); if (LOG.isTraceEnabled()) { long end = System.currentTimeMillis(); StringBuilder sb = new StringBuilder(1000); sb.append(callSignature); sb.append(" finished execution in ").append(end - start); sb.append(" ms for arguments: ").append(arguments); sb.append(" and returned: ").append(returnValue); LOG.trace(sb.toString()); } return returnValue; }
From source file:io.github.autsia.crowly.controllers.aspects.CampaignAspect.java
License:Apache License
@Around("execution(* io.github.autsia.crowly.controllers.rest.CampaignsController.create(..))") public Object checkCreateCampaign(ProceedingJoinPoint joinPoint) throws Throwable { try {/*w ww . j a v a 2 s .c o m*/ Object[] args = joinPoint.getArgs(); String name = (String) args[0]; String socialEndpoints = (String) args[1]; String language = (String) args[2]; String keywords = (String) args[3]; String regionNames = (String) args[4]; String startDate = (String) args[5]; String endDate = (String) args[6]; String cronExpression = (String) args[7]; String sentiment = (String) args[8]; float threshold = (Float) args[9]; String emails = (String) args[10]; boolean isNameNotEmpty = !name.isEmpty(); boolean isSocialEndpointsCorrect = socialEndpoints.split(SEPARATOR).length != 0; boolean isLanguageCorrect = language.split(SEPARATOR).length != 0; boolean isKeywordsCorrect = keywords.split(SEPARATOR).length != 0; boolean isRegionNamesNotEmpty = !regionNames.isEmpty(); boolean isStartDatNotEmpty = !startDate.isEmpty(); boolean isEndDateNotEmpty = !endDate.isEmpty(); boolean isCronExpressionNotEmpty = !cronExpression.isEmpty(); boolean isSentimentCorrect = Sentiment.get(sentiment) != null; boolean isThresholdCorrect = threshold >= 0 && threshold <= 100; boolean isEmailsValid = true; if (emails != null) { for (String email : emails.split(SEPARATOR)) { if (!pattern.matcher(email).matches()) { isEmailsValid = false; break; } } } if (isNameNotEmpty && isSocialEndpointsCorrect && isLanguageCorrect && isKeywordsCorrect && isRegionNamesNotEmpty && isStartDatNotEmpty && isEndDateNotEmpty && isCronExpressionNotEmpty && isSentimentCorrect && isThresholdCorrect && isEmailsValid) { return joinPoint.proceed(joinPoint.getArgs()); } else { throw new IllegalArgumentException(); } } catch (Exception e) { logger.error(e.getMessage(), e); return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); } }
From source file:io.github.autsia.crowly.controllers.aspects.CheckPageSizeAspect.java
License:Apache License
@Around("execution(* io.github.autsia.crowly.controllers.rest.UsersController.pages(..)) ||" + "execution(* io.github.autsia.crowly.controllers.rest.UsersController.users(..))") public Object checkPageSize(ProceedingJoinPoint joinPoint) throws Throwable { try {//from ww w. j av a2s . c om Integer page = (Integer) joinPoint.getArgs()[0]; Integer size = (Integer) joinPoint.getArgs()[1]; if (!allowedSizes.contains(size)) { page = DEFAULT_PAGE; size = MIN_SIZE; } joinPoint.getArgs()[0] = page; joinPoint.getArgs()[1] = size; return joinPoint.proceed(joinPoint.getArgs()); } catch (Exception e) { logger.error(e); return joinPoint.proceed(); } }
From source file:io.github.resilience4j.bulkhead.configure.BulkheadAspect.java
License:Apache License
@Around(value = "matchAnnotatedClassOrMethod(bulkheadAnnotation)", argNames = "proceedingJoinPoint, bulkheadAnnotation") public Object bulkheadAroundAdvice(ProceedingJoinPoint proceedingJoinPoint, @Nullable Bulkhead bulkheadAnnotation) throws Throwable { Method method = ((MethodSignature) proceedingJoinPoint.getSignature()).getMethod(); String methodName = method.getDeclaringClass().getName() + "#" + method.getName(); if (bulkheadAnnotation == null) { bulkheadAnnotation = geBulkheadAnnotation(proceedingJoinPoint); }// w w w. ja va 2 s . c om if (bulkheadAnnotation == null) { //because annotations wasn't found return proceedingJoinPoint.proceed(); } String backend = bulkheadAnnotation.name(); io.github.resilience4j.bulkhead.Bulkhead bulkhead = getOrCreateBulkhead(methodName, backend); Class<?> returnType = method.getReturnType(); if (StringUtils.isEmpty(bulkheadAnnotation.fallbackMethod())) { return proceed(proceedingJoinPoint, methodName, bulkhead, returnType); } FallbackMethod fallbackMethod = FallbackMethod.create(bulkheadAnnotation.fallbackMethod(), method, proceedingJoinPoint.getArgs(), proceedingJoinPoint.getTarget()); return fallbackDecorators .decorate(fallbackMethod, () -> proceed(proceedingJoinPoint, methodName, bulkhead, returnType)) .apply(); }
From source file:io.github.resilience4j.circuitbreaker.configure.CircuitBreakerAspect.java
License:Apache License
@Around(value = "matchAnnotatedClassOrMethod(circuitBreakerAnnotation)", argNames = "proceedingJoinPoint, circuitBreakerAnnotation") public Object circuitBreakerAroundAdvice(ProceedingJoinPoint proceedingJoinPoint, @Nullable CircuitBreaker circuitBreakerAnnotation) throws Throwable { Method method = ((MethodSignature) proceedingJoinPoint.getSignature()).getMethod(); String methodName = method.getDeclaringClass().getName() + "#" + method.getName(); if (circuitBreakerAnnotation == null) { circuitBreakerAnnotation = getCircuitBreakerAnnotation(proceedingJoinPoint); }/*from w ww . j av a 2s .com*/ if (circuitBreakerAnnotation == null) { //because annotations wasn't found return proceedingJoinPoint.proceed(); } String backend = circuitBreakerAnnotation.name(); io.github.resilience4j.circuitbreaker.CircuitBreaker circuitBreaker = getOrCreateCircuitBreaker(methodName, backend); Class<?> returnType = method.getReturnType(); if (StringUtils.isEmpty(circuitBreakerAnnotation.fallbackMethod())) { return proceed(proceedingJoinPoint, methodName, circuitBreaker, returnType); } FallbackMethod fallbackMethod = FallbackMethod.create(circuitBreakerAnnotation.fallbackMethod(), method, proceedingJoinPoint.getArgs(), proceedingJoinPoint.getTarget()); return fallbackDecorators.decorate(fallbackMethod, () -> proceed(proceedingJoinPoint, methodName, circuitBreaker, returnType)).apply(); }
From source file:io.github.resilience4j.ratelimiter.configure.RateLimiterAspect.java
License:Apache License
@Around(value = "matchAnnotatedClassOrMethod(rateLimiterAnnotation)", argNames = "proceedingJoinPoint, rateLimiterAnnotation") public Object rateLimiterAroundAdvice(ProceedingJoinPoint proceedingJoinPoint, @Nullable RateLimiter rateLimiterAnnotation) throws Throwable { Method method = ((MethodSignature) proceedingJoinPoint.getSignature()).getMethod(); String methodName = method.getDeclaringClass().getName() + "#" + method.getName(); if (rateLimiterAnnotation == null) { rateLimiterAnnotation = getRateLimiterAnnotation(proceedingJoinPoint); }//from ww w . java 2 s .c om if (rateLimiterAnnotation == null) { //because annotations wasn't found return proceedingJoinPoint.proceed(); } String name = rateLimiterAnnotation.name(); io.github.resilience4j.ratelimiter.RateLimiter rateLimiter = getOrCreateRateLimiter(methodName, name); Class<?> returnType = method.getReturnType(); if (StringUtils.isEmpty(rateLimiterAnnotation.fallbackMethod())) { return proceed(proceedingJoinPoint, methodName, returnType, rateLimiter); } FallbackMethod fallbackMethod = FallbackMethod.create(rateLimiterAnnotation.fallbackMethod(), method, proceedingJoinPoint.getArgs(), proceedingJoinPoint.getTarget()); return fallbackDecorators .decorate(fallbackMethod, () -> proceed(proceedingJoinPoint, methodName, returnType, rateLimiter)) .apply(); }
From source file:io.github.resilience4j.retry.configure.RetryAspect.java
License:Apache License
@Around(value = "matchAnnotatedClassOrMethod(retryAnnotation)", argNames = "proceedingJoinPoint, retryAnnotation") public Object retryAroundAdvice(ProceedingJoinPoint proceedingJoinPoint, @Nullable Retry retryAnnotation) throws Throwable { Method method = ((MethodSignature) proceedingJoinPoint.getSignature()).getMethod(); String methodName = method.getDeclaringClass().getName() + "#" + method.getName(); if (retryAnnotation == null) { retryAnnotation = getRetryAnnotation(proceedingJoinPoint); }//from www . j a va2s . c o m if (retryAnnotation == null) { //because annotations wasn't found return proceedingJoinPoint.proceed(); } String backend = retryAnnotation.name(); io.github.resilience4j.retry.Retry retry = getOrCreateRetry(methodName, backend); Class<?> returnType = method.getReturnType(); if (StringUtils.isEmpty(retryAnnotation.fallbackMethod())) { return proceed(proceedingJoinPoint, methodName, retry, returnType); } FallbackMethod fallbackMethod = FallbackMethod.create(retryAnnotation.fallbackMethod(), method, proceedingJoinPoint.getArgs(), proceedingJoinPoint.getTarget()); return fallbackDecorators .decorate(fallbackMethod, () -> proceed(proceedingJoinPoint, methodName, retry, returnType)) .apply(); }
From source file:io.helixservice.feature.context.RequestContextAspect.java
License:Open Source License
/** * Wraps Vert.x handlers and copies the context on context invocation *///from w ww . ja va2 s .c o m @Around(value = "(execution(public !static * *(.., io.vertx.core.Handler, ..)))") public Object aroundHandlerMethods(ProceedingJoinPoint pjp) throws Throwable, SuspendExecution { Object[] args = pjp.getArgs(); RequestContext context = RequestContext.getContext(); if (context != null) { for (int i = 0; i < args.length; i++) { if (args[i] != null && Handler.class.isAssignableFrom(args[i].getClass())) { args[i] = new ContextCopyingHandler((Handler) args[i], context); } } } return pjp.proceed(args); }
From source file:io.opencensus.contrib.spring.aop.CensusSpringSqlAspect.java
License:Apache License
/** * trace handles invocations of java.sql.Statement.execute*. A new span will be created whose name * is (execute|executeQuery|executeQuery)-(hash of sql). * * @since 0.16.0/* www .ja v a2 s .co m*/ */ @Around("execute() || testing()") public Object trace(ProceedingJoinPoint call) throws Throwable { if (call.getArgs().length == 0 || call.getArgs()[0] == null) { return call.proceed(); } String sql = (String) call.getArgs()[0]; String spanName = makeSpanName(call, sql); return Handler.proceed(call, tracer, spanName, sql); }
From source file:io.renren.common.aspect.SysLogAspect.java
License:Apache License
private void saveSysLog(ProceedingJoinPoint joinPoint, long time) { MethodSignature signature = (MethodSignature) joinPoint.getSignature(); Method method = signature.getMethod(); SysLogEntity sysLog = new SysLogEntity(); SysLog syslog = method.getAnnotation(SysLog.class); if (syslog != null) { //??//from w w w. j a v a2 s.c om sysLog.setOperation(syslog.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 = ((SysUserEntity) SecurityUtils.getSubject().getPrincipal()).getUsername(); sysLog.setUsername(username); sysLog.setTime(time); sysLog.setCreateDate(new Date()); //? sysLogService.insert(sysLog); }