List of usage examples for org.aspectj.lang ProceedingJoinPoint getArgs
Object[] getArgs();
From source file:com.create.aop.LoggingAspect.java
License:Apache License
private String getQueryWatchId(ProceedingJoinPoint joinPoint) { final String methodName = getMethodName(joinPoint.getSignature()); final String arguments = Arrays.toString(joinPoint.getArgs()); return String.format("%s%s", methodName, arguments); }
From source file:com.crossbusiness.resiliency.aspect.AbstractFallbackAspect.java
License:Open Source License
public Object rerouteToFallback(ProceedingJoinPoint pjp, Fallback fallbackConfig) throws Throwable { String[] fallbacks = fallbackConfig.value(); Class<? extends Throwable>[] fallbackableExceptions = fallbackConfig.exceptions(); List<Object> fallbackBeans = new ArrayList<Object>(fallbacks.length); for (String fallback : fallbacks) { try {// w ww.j a v a 2s . c o m fallbackBeans.add(context.getBean(fallback)); } catch (BeansException be) { log.error("configuration error: cannot find bean with name: '{}'", fallback, be); //configuration errors should be fixed immediately. throw be; } } MethodSignature targetMethodSig = (MethodSignature) pjp.getSignature(); Method targetMethod = targetMethodSig.getMethod(); Class[] paramTypes = (Class[]) targetMethod.getParameterTypes(); Object[] args = pjp.getArgs(); log.debug("fallbacks: {} method: '{}'", fallbacks, targetMethod); try { return pjp.proceed(); } catch (Throwable t) { // if the exception is not what we're looking for, rethrow it if (!isFallbackableException(t, fallbackableExceptions)) throw t; log.debug("got exception while trying the targetBean method: '{}'. will try fallbackBean...", targetMethod); Iterator<Object> iter = fallbackBeans.iterator(); while (iter.hasNext()) { Object fallbackBean = iter.next(); Method fallbackMethod; try { fallbackMethod = fallbackBean.getClass().getMethod(targetMethod.getName(), paramTypes); } catch (NoSuchMethodException | SecurityException nsme) { log.error( "configuration error: No matchig method found in fallbackBean: '{}' that matches to targetBean method: '{}'", new Object[] { fallbackBean.getClass().getName(), targetMethod, nsme }); //configuration errors should be fixed immediately. throw nsme; } try { log.debug("trying fallbackBean method: '{}'...", fallbackMethod); return fallbackMethod.invoke(fallbackBean, args); } catch (IllegalArgumentException | IllegalAccessException iae) { log.error( "configuration error: arguments missmatch: fallbackBean method: '{}' arguments missmatch to targetBean method: '{}' arguments", new Object[] { fallbackMethod, targetMethod, iae }); //configuration errors should be fixed immediately. throw iae; } catch (InvocationTargetException ite) { log.debug( "got exception while trying the fallbackBean method: '{}'. will try next fallbackBean...", fallbackMethod); //fallbackBean method thrown an exception. try next bean or throw exception if this is the last bean if (!iter.hasNext()) { //TODO : do we still need to check isFallbackableException? throw ite.getCause(); } } } //code should never reach this line. throw t; } }
From source file:com.crossbusiness.resiliency.aspect.spring.AnnotationFallbackAspect.java
License:Open Source License
public Object rerouteToFallback(ProceedingJoinPoint pjp, Fallback fallbackConfig) throws Throwable { String[] fallbacks = fallbackConfig.value(); Class<? extends Throwable>[] fallbackableExceptions = fallbackConfig.exceptions(); List<Object> fallbackBeans = new ArrayList<Object>(fallbacks.length); for (String fallback : fallbacks) { try {//from w ww .ja v a 2 s. co m fallbackBeans.add(context.getBean(fallback)); } catch (BeansException be) { log.error("configuration error: cannot find bean with name: '{}'", fallback, be); //configuration errors should be fixed immediately. throw be; } } MethodSignature targetMethodSig = (MethodSignature) pjp.getSignature(); Method targetMethod = targetMethodSig.getMethod(); Class[] paramTypes = (Class[]) targetMethod.getParameterTypes(); Object[] args = pjp.getArgs(); log.debug("fallbacks: {} method: '{}'", fallbacks, targetMethod); try { return pjp.proceed(); } catch (Throwable t) { // if the exception is not what we're looking for, rethrow it if (!isFallbackableException(t, fallbackableExceptions)) throw t; log.debug("got exception while trying the targetBean method: '{}'. will try fallbackBean...", targetMethod); Iterator<Object> iter = fallbackBeans.iterator(); while (iter.hasNext()) { Object fallbackBean = iter.next(); Method fallbackMethod; try { fallbackMethod = fallbackBean.getClass().getMethod(targetMethod.getName(), paramTypes); } catch (NoSuchMethodException | SecurityException nsme) { log.error( "configuration error: No matchig method found in fallbackBean: '{}' that matches to targetBean method: '{}'", new Object[] { fallbackBean.getClass().getName(), targetMethod, nsme }); //configuration errors should be fixed immediately. throw nsme; } try { log.debug("trying fallbackBean method: '{}'...", fallbackMethod); return fallbackMethod.invoke(fallbackBean, args); } catch (IllegalArgumentException | IllegalAccessException iae) { log.error( "configuration error: arguments missmatch: fallbackBean method: '{}' arguments missmatch to targetBean method: '{}' arguments", new Object[] { fallbackMethod, targetMethod, iae }); //configuration errors should be fixed immediately. throw iae; } catch (InvocationTargetException ite) { log.debug( "got exception while trying the fallbackBean method: '{}'. will try next fallbackBean...", fallbackMethod); //fallbackBean method thrown an exception. try next bean or throw exception if this is the last bean if (!iter.hasNext()) { //TODO : do we still need to check isFallbackableException? throw ite.getCause(); } } } //code should never reach this line. throw t; } }
From source file:com.daphne.es.extra.aop.UserCacheAspect.java
License:Apache License
@Around(value = "userServicePointcut() && cacheablePointcut()") public Object cacheableAdvice(ProceedingJoinPoint pjp) throws Throwable { String methodName = pjp.getSignature().getName(); Object arg = pjp.getArgs().length >= 1 ? pjp.getArgs()[0] : null; String key = ""; boolean isIdKey = false; if ("findOne".equals(methodName)) { key = idKey(String.valueOf(arg)); isIdKey = true;//from w w w .j a v a 2 s . co m } else if ("findByUsername".equals(methodName)) { key = usernameKey((String) arg); } else if ("findByEmail".equals(methodName)) { key = emailKey((String) arg); } else if ("findByMobilePhoneNumber".equals(methodName)) { key = mobilePhoneNumberKey((String) arg); } User user = null; if (isIdKey == true) { user = get(key); } else { Long id = get(key); if (id != null) { key = idKey(String.valueOf(id)); user = get(key); } } //cache hit if (user != null) { log.debug("cacheName:{}, hit key:{}", cacheName, key); return user; } log.debug("cacheName:{}, miss key:{}", cacheName, key); //cache miss user = (User) pjp.proceed(); //put cache put(user); return user; }
From source file:com.datastax.hectorjpa.spring.ConsistencyLevelAspect.java
License:Open Source License
/** * Validates any method that has the valid annotation on it and is wired as * a spring service//ww w . ja v a 2 s . c o m * * @param jp * @throws Throwable */ @Around("@annotation(com.datastax.hectorjpa.spring.Consistency)") public Object setConsistency(ProceedingJoinPoint pjp) throws Throwable { logger.debug("Invoking before advice for @Consistency annotation. Target object is {} on method {}", pjp.getTarget(), pjp.getSignature()); MethodSignature sig = (MethodSignature) pjp.getSignature(); Object[] args = pjp.getArgs(); Method signatureMethod = sig.getMethod(); Class<?>[] signatureTypes = signatureMethod.getParameterTypes(); // we do this because we want to get the best match from the child // classes Class<?>[] runtimeArgs = new Class<?>[signatureTypes.length]; for (int i = 0; i < signatureTypes.length; i++) { if (args[i] != null) { runtimeArgs[i] = args[i].getClass(); } else { runtimeArgs[i] = signatureTypes[i]; } } Class<?> runtimeClass = pjp.getTarget().getClass(); // check if this is annotated, if not proceed and execute it HConsistencyLevel level = consistency(runtimeClass, signatureMethod.getName(), runtimeArgs); if (level == null) { return pjp.proceed(args); } Stack<HConsistencyLevel> stack = threadStack.get(); stack.push(level); JPAConsistency.set(level); Object result = null; try { result = pjp.proceed(args); } finally { stack.pop(); if (stack.size() > 0) { JPAConsistency.set(stack.peek()); } else { JPAConsistency.remove(); } } return result; }
From source file:com.dcits.govsbu.southernbase.baseproject2.helper.aop.AuthorityHelperAOP.java
License:Apache License
@Around("actionMethod()") public Object authorityAroundService(ProceedingJoinPoint joinpoint) throws Throwable { ModelAndView result = null;/*from w w w . j a v a 2 s . c om*/ try { // ? begin // long start = System.currentTimeMillis(); // ????TOKEN Object[] args = joinpoint.getArgs(); if (args.length > 0 && authorityHelper.isAdmin((String) args[0])) { // ???? TOKEN/mainInfo // return joinpoint.proceed(); result = ((ModelAndView) joinpoint.proceed()).addObject("token", args[0]); } else { result = new ModelAndView(AdminUrl.loginPage); result.addObject("message", Messages.USER_NOT_ADMIN); } // long end = System.currentTimeMillis(); // System.out.println("end! performance took " + (end-start) + " milliseconds"); // ? end } catch (Throwable e) { // e.printStackTrace(); result = new ModelAndView(AdminUrl.loginPage); result.addObject("message", Messages.AOP_HAS_ERROR); } return result; }
From source file:com.denimgroup.threadfix.service.eventmodel.aspect.CommentSubmissionAspect.java
License:Mozilla Public License
@Around("execution(* com.denimgroup.threadfix.service.VulnerabilityCommentService.addCommentToVuln(..))") public Object emitEvent(ProceedingJoinPoint joinPoint) throws Throwable { VulnerabilityComment comment = (VulnerabilityComment) joinPoint.getArgs()[0]; Integer vulnerabilityId = (Integer) joinPoint.getArgs()[1]; Object proceed = joinPoint.proceed(); eventPublisher.publishEvent(new CommentSubmissionEvent(comment, vulnerabilityId)); return proceed; }
From source file:com.denimgroup.threadfix.service.eventmodel.aspect.DefectTrackerFormPopulationAspect.java
License:Mozilla Public License
@Around("execution(* com.denimgroup.threadfix.service.DefectTrackerService.getProjectMetadata(..))") public Object emitEvent(ProceedingJoinPoint joinPoint) throws Throwable { LOG.debug("Emitting getProjectMetadata event."); ProjectMetadataSource metadataSource = (ProjectMetadataSource) joinPoint.getArgs()[0]; AbstractDefectTracker tracker = null; if (metadataSource instanceof AbstractDefectTracker) { tracker = (AbstractDefectTracker) metadataSource; LOG.debug("Got AbstractDefectTracker from metadataSource"); } else {/*from w w w . ja v a2s.c om*/ LOG.error("MetadataSource wasn't an AbstractDefectTracker. This shouldn't happen."); assert false : "Shouldn't be here, fix your code"; } Object proceed = joinPoint.proceed(); eventPublisher.publishEvent(new DefectTrackerProjectMetadataEvent(tracker, (ProjectMetadata) proceed)); return proceed; }
From source file:com.denimgroup.threadfix.service.eventmodel.aspect.SubmitDefectAspect.java
License:Mozilla Public License
@Around("execution(* com.denimgroup.threadfix.service.DefectSubmissionServiceImpl.submitDefect(..))") public Object emitEvent(ProceedingJoinPoint joinPoint) throws Throwable { LOG.debug("Emitting getProjectMetadata event."); Object[] args = joinPoint.getArgs(); assert args.length == 3 : "Length of join point arguments wasn't 3: " + Arrays.toString(args); AbstractDefectTracker tracker = getAs(args[0], AbstractDefectTracker.class); List vulns = getAs(args[1], List.class); DefectMetadata metadata = getAs(args[2], DefectMetadata.class); eventPublisher.publishEvent(new PreDefectSubmissionEvent(tracker, vulns, metadata)); return joinPoint.proceed(new Object[] { tracker, vulns, metadata }); }
From source file:com.evolveum.midpoint.util.aspect.MidpointAspect.java
License:Apache License
private Object wrapSubsystem(ProceedingJoinPoint pjp, String subsystem) throws Throwable { Object retValue = null;//from www .j a v a 2 s .c o m String prev = null; int id = 0; int d = 1; boolean exc = false; String excName = null; long elapsed; // Profiling start long startTime = System.nanoTime(); final StringBuilder infoLog = new StringBuilder("#### Entry: "); try { // Marking MDC->Subsystem with current one subsystem and mark // previous prev = swapSubsystemMark(subsystem); if (LOGGER_PROFILING.isDebugEnabled()) { id = idcounter.incrementAndGet(); infoLog.append(id); } if (LOGGER_PROFILING.isTraceEnabled()) { String depth = MDC.get("depth"); if (depth == null || depth.isEmpty()) { d = 0; } else { d = Integer.parseInt(depth); } d++; MDC.put("depth", Integer.toString(d)); for (int i = 0; i < d; i++) { infoLog.append(INDENT_STRING); } } // is profiling info is needed if (LOGGER_PROFILING.isDebugEnabled()) { infoLog.append(getClassName(pjp)); LOGGER_PROFILING.debug("{}->{}", infoLog, pjp.getSignature().getName()); // If debug enable get entry parameters and log them if (LOGGER_PROFILING.isTraceEnabled()) { final Object[] args = pjp.getArgs(); // final String[] names = ((CodeSignature) // pjp.getSignature()).getParameterNames(); // @SuppressWarnings("unchecked") // final Class<CodeSignature>[] types = ((CodeSignature) // pjp.getSignature()).getParameterTypes(); final StringBuffer sb = new StringBuffer(); sb.append("###### args: "); sb.append("("); for (int i = 0; i < args.length; i++) { sb.append(formatVal(args[i])); if (args.length != i + 1) { sb.append(", "); } } sb.append(")"); LOGGER_PROFILING.trace(sb.toString()); } } //We dont need profiling on method start in current version // if profiling info is needed - start //if(isProfilingActive){ // LOGGER.info("Profiling is active: onStart"); // AspectProfilingFilters.applyGranularityFilterOnStart(pjp, subsystem); //} // Process original call try { retValue = pjp.proceed(); } catch (Exception e) { excName = e.getClass().getName(); exc = true; throw e; } // Return original response return retValue; } finally { // Depth -1 if (LOGGER_PROFILING.isTraceEnabled()) { d--; MDC.put("depth", Integer.toString(d)); } // Restore previously marked subsystem executed before return if (LOGGER_PROFILING.isDebugEnabled()) { StringBuilder sb = new StringBuilder(); sb.append("##### Exit: "); if (LOGGER_PROFILING.isDebugEnabled()) { sb.append(id); sb.append(" "); } // sb.append("/"); if (LOGGER_PROFILING.isTraceEnabled()) { for (int i = 0; i < d + 1; i++) { sb.append(INDENT_STRING); } } sb.append(getClassName(pjp)); sb.append("->"); sb.append(pjp.getSignature().getName()); if (LOGGER_PROFILING.isDebugEnabled()) { sb.append(" etime: "); // Mark end of processing elapsed = System.nanoTime() - startTime; sb.append((long) (elapsed / 1000000)); sb.append('.'); long mikros = (long) (elapsed / 1000) % 1000; if (mikros < 100) { sb.append('0'); } if (mikros < 10) { sb.append('0'); } sb.append(mikros); sb.append(" ms"); } LOGGER_PROFILING.debug(sb.toString()); if (LOGGER_PROFILING.isTraceEnabled()) { if (exc) { LOGGER_PROFILING.trace("###### return exception: {}", excName); } else { LOGGER_PROFILING.trace("###### retval: {}", formatVal(retValue)); } } } if (isProfilingActive) { if (pjp != null) { Long processingStartTime = System.nanoTime(); ProfilingDataManager.getInstance().applyGranularityFilterOnEnd(getClassName(pjp), getMethodName(pjp), pjp.getArgs(), subsystem, startTime, processingStartTime); } } // Restore MDC swapSubsystemMark(prev); } }