List of usage examples for org.aspectj.lang ProceedingJoinPoint getArgs
Object[] getArgs();
From source file:quanlyhocvu.api.mongodb.DAO.AOP.StaffAOP.java
@Around("execution(* quanlyhocvu.api.mongodb.DAO.StaffDAO.*(..))") public Object LookTestAOP(ProceedingJoinPoint joinPoint) throws Throwable { boolean result = true; for (Object obj : joinPoint.getArgs()) { if (obj instanceof StaffDTO) { if (!checkStaffData((StaffDTO) obj)) { result = false;// w ww.j ava2 s.c o m break; } } } if (!result) throw new Exception("Sai thng tin nhn vin"); else return joinPoint.proceed(); }
From source file:ro.nextreports.server.aop.MethodProfilerAdvice.java
License:Apache License
/** * Intercepts methods that declare Profile annotation and prints out the time it takes to complete/ * //w ww .ja v a 2s .c om * @param joinPoint proceeding join point * @return the intercepted method returned object * @throws Throwable in case something goes wrong in the actual method call */ @Around("isProfileAnnotation(profile)") public Object profileMethod(ProceedingJoinPoint joinPoint, Profile profile) throws Throwable { String logPrefix = null; boolean debug = LOG.isDebugEnabled(); long time = System.currentTimeMillis(); // parse out the first arg String arg1 = ""; Object[] args = joinPoint.getArgs(); if ((args != null) && (args.length > 0) && (args[0] != null)) { arg1 = args[0].toString(); } if (debug) { logPrefix = joinPoint.getSignature().getDeclaringTypeName() + "." + joinPoint.getSignature().getName() + " " + arg1; LOG.debug(logPrefix + " START"); } Object returnValue = joinPoint.proceed(); time = System.currentTimeMillis() - time; if (debug) { LOG.debug(logPrefix + " EXECUTED in " + time + " ms"); } return returnValue; }
From source file:ru.caramel.juniperbot.web.common.aspect.GuildIdAspect.java
License:Open Source License
@Around("execution(public * *(.., @ru.caramel.juniperbot.web.common.aspect.GuildId (*), ..))") public Object doAwesomeStuff(ProceedingJoinPoint thisJoinPoint) throws Throwable { try {//from w ww . j a v a 2 s .c o m Object[] methodArgs = thisJoinPoint.getArgs(); int numArgs = methodArgs.length; MethodSignature methodSignature = (MethodSignature) thisJoinPoint.getSignature(); Annotation[][] annotationMatrix = methodSignature.getMethod().getParameterAnnotations(); for (int i = 0; i < numArgs; i++) { Annotation[] annotations = annotationMatrix[i]; for (Annotation annotation : annotations) { if (annotation.annotationType() == GuildId.class && methodArgs[i] instanceof Long) { GuildId guildIdAnnotation = (GuildId) annotation; long guildId = (long) methodArgs[i]; MDC.put("guildId", String.valueOf(guildId)); if (guildIdAnnotation.validate()) { DiscordGuildDetails details = tokenServices.getGuildById(guildId); if (details == null) { throw new NotFoundException(); } if (!tokenServices.hasPermission(details)) { throw new AccessDeniedException(); } } } } } return thisJoinPoint.proceed(); } finally { MDC.remove("guildId"); } }
From source file:ru.xxlabaza.aspect.MyAspect.java
License:Apache License
@Around("bean(*Controller)") public Object around(ProceedingJoinPoint joinPoint) throws Throwable { String methodName = ((MethodSignature) joinPoint.getSignature()).getMethod().getName(); String arguments = Stream.of(joinPoint.getArgs()).map(Object::toString).collect(Collectors.joining(", ")); log.info("\n\tAROUND ->\n" + "\tMethod name: {}\n" + "\tArguments: {}", methodName, arguments); return joinPoint.proceed(); }
From source file:se.inera.intyg.privatlakarportal.common.service.stub.JavaMailSenderAroundAdvice.java
License:Open Source License
/** * Intercepts and mail sending calls and stores the mime message in the MailStore. *//*w w w . j ava 2 s. co m*/ @Around("execution(* org.springframework.mail.javamail.JavaMailSender+.send(..))") public Object interceptMailSending(ProceedingJoinPoint pjp) throws Throwable { if (StringUtils.isEmpty(mailHost)) { for (Object argument : pjp.getArgs()) { if (argument instanceof MimeMessage) { mailStore.getMails().add(new OutgoingMail((MimeMessage) argument)); mailStore.waitToContinue(); } } return null; } else { return pjp.proceed(); } }
From source file:se.inera.intyg.webcert.mailstub.JavaMailSenderAroundAdvice.java
License:Open Source License
/** * Intercepts and mail sending calls and stores the mime message in the MailStore. *///w w w . j a va 2s. co m @Around("execution(* org.springframework.mail.javamail.JavaMailSender+.send(..))") public Object interceptMailSending(ProceedingJoinPoint pjp) throws Throwable { if (Strings.isNullOrEmpty(mailHost)) { for (Object argument : pjp.getArgs()) { if (argument instanceof MimeMessage) { OutgoingMail outgoingMail = new OutgoingMail((MimeMessage) argument); mailStore.getMails().add(outgoingMail); LOG.info("\n*********************************************************************************\n" + " Intercepting mail to : '{}' subject: '{}' from: '{}'.\n" + "{}\n" + "*********************************************************************************", outgoingMail.getRecipients().stream().collect(Collectors.joining(", ")), outgoingMail.getSubject(), outgoingMail.getFrom(), outgoingMail.getBody()); mailStore.waitToContinue(); } } return null; } else { return pjp.proceed(); } }
From source file:se.omik.squash.SquashAdviser.java
License:Open Source License
/** * Aspect applied to read operations./* ww w . ja va 2 s . c om*/ */ @Around(value = "execution(* *(..)) && @annotation(squashBefore)") public Object readMemcached(ProceedingJoinPoint joinPoint, SquashBefore squashBefore) throws Throwable { long start = System.currentTimeMillis(); String domain = getDomain(joinPoint); String keyToRead = squashBefore.key(); MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature(); if (keyToRead == null || keyToRead.length() == 0) { StringBuilder guessedKey = new StringBuilder(); for (int i = 0; i < joinPoint.getArgs().length; i++) { guessedKey.append(":$").append(i); } if (guessedKey.length() == 0) { guessedKey.append(":").append(methodSignature.getName()); } if (guessedKey.length() > 0) { keyToRead = methodSignature.getReturnType().getSimpleName() + guessedKey.toString(); } } String key = getKey(domain, keyToRead, joinPoint.getArgs());//get the key of the object int expiration = squashBefore.expiration(); if (expiration == -1 && squashBefore.expirationFromParameter() >= 0) { expiration = Integer .parseInt(String.valueOf(joinPoint.getArgs()[squashBefore.expirationFromParameter()])); } if (logger.isDebugEnabled()) { logger.debug("cacheRead: " + methodSignature.getMethod().getDeclaringClass().getSimpleName() + "." + methodSignature.getMethod().getName() + " [" + key + "]"); } Object object = squashProvider.get(key);//try to get the object from the cache if (object == null) {//if the object is not in the cache... object = joinPoint.proceed();//invoke the method if (logger.isDebugEnabled()) { logger.debug("object didn't exist in cache, executing method: " + methodSignature.getMethod().getDeclaringClass().getSimpleName() + "." + methodSignature.getMethod().getName() + " took " + (System.currentTimeMillis() - start) + "ms"); } if (squashBefore.cacheWhenNull() && object == null) { object = "null"; } if (object != null) { String keys = key; if (squashBefore.updateOtherEntries().length() > 0) { keys += "," + squashBefore.updateOtherEntries(); } updateKeys(object, domain, keys, expiration, squashBefore.useKeyList(), squashBefore.mainKey(), joinPoint.getArgs()); } } else if (logger.isDebugEnabled()) { logger.debug("returning cached object"); } if ("null".equals(object)) { object = null; } return object; }
From source file:se.omik.squash.SquashAdviser.java
License:Open Source License
/** * Aspect applied to delete operations.// ww w . ja v a2s. c o m */ @Around(value = "execution(* *(..)) && @annotation(deleteFromSquash)") public void deleteMemcached(ProceedingJoinPoint joinPoint, DeleteFromSquash deleteFromSquash) throws Throwable { joinPoint.proceed(); MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature(); if (logger.isDebugEnabled()) { logger.debug("cacheDelete: " + methodSignature.getMethod().getDeclaringClass().getSimpleName() + "." + methodSignature.getMethod().getName() + " [" + joinPoint.getArgs()[0] + "]"); } String domain = getDomain(joinPoint); String deleteEntries = deleteFromSquash.deleteEntries(); if (deleteEntries == null || deleteEntries.length() == 0) { deleteEntries = ((MethodSignature) joinPoint.getSignature()).getReturnType().getSimpleName() + ":$" + deleteFromSquash.keyField(); if (logger.isDebugEnabled()) { logger.debug("guessed: " + deleteEntries); } } deleteKeys(joinPoint.getArgs()[0], domain, deleteEntries, deleteFromSquash.useKeyList(), joinPoint.getArgs()); }
From source file:se.vgregion.mobile.hriv.aspect.KivwsSearchServiceCacheAspect.java
License:Open Source License
/** * Pointcut around KivwsSearchService#searchUnits(java.lang.String, int, java.util.List<java.lang.String>) method. * <p/>//from ww w .java2 s.co m * Using Ehcache to cache entries, cache settings (time to live, max elements etc.) are defiend in ehcache.xml. * * @param joinPoint Used to get method parameters value(s) * @return method return value * @throws Throwable If something goes wrong */ @Around("execution(* se.vgregion.mobile.hriv.service.KivwsSearchService.searchUnits(java.lang.String,int,java.util.List))") public Object cacheKivwsSearches(ProceedingJoinPoint joinPoint) throws Throwable { Object[] arguments = joinPoint.getArgs(); // Convert to list since lists implement the equals method so the cache.get() will work List<Object> argumentsAsList = Arrays.asList(arguments); Element element = cache.get(argumentsAsList); if (null == element) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("No cached element found."); } Object result = joinPoint.proceed(); if (null != result) { element = new Element(argumentsAsList, result); cache.put(element); } return result; } else { if (LOGGER.isDebugEnabled()) { LOGGER.debug("Cached element found."); } return element.getValue(); } }