List of usage examples for org.aspectj.lang ProceedingJoinPoint proceed
public Object proceed() throws Throwable;
From source file:com.devexperts.chameleon.aspect.TimingAspect.java
License:Open Source License
@Around("serviceMethods()") public Object profile(ProceedingJoinPoint pjp) throws Throwable { Signature signature = pjp.getSignature(); String name = signature.toShortString(); long start = System.currentTimeMillis(); Object output = pjp.proceed(); long elapsedTime = System.currentTimeMillis() - start; if (elapsedTime > timingMoreThen) logger.info("{} execution time: " + elapsedTime + " milliseconds.", name); return output; }
From source file:com.dianping.wed.cache.redis.aop.RedisAspect.java
License:Open Source License
public Object doAround(ProceedingJoinPoint pjp) throws Throwable { Object result = null;/*from w w w . j a v a 2 s . c o m*/ String op = pjp.getSignature().getName() + ":(RedisKeys)"; //Cat.logMetricForCount(CAT_NAME.concat(op)); Transaction transaction = Cat.getProducer().newTransaction(CAT_NAME, op); try { result = pjp.proceed(); transaction.setStatus(Transaction.SUCCESS); } catch (Exception e) { transaction.setStatus(e); Cat.logError(e); throw e; } finally { transaction.complete(); } return result; }
From source file:com.envision.envservice.rest.advice.ExceptionAdvice.java
License:Open Source License
@Around(value = "execution(public * com.envision.envservice.rest.*.*(..))") public Response around(ProceedingJoinPoint pjp) { HttpStatus status = HttpStatus.BAD_REQUEST; Code code = Code.BUSINESS_FAIL;/*w w w . jav a 2 s . c om*/ String response = null; try { return (Response) pjp.proceed(); } catch (ServiceException e) { BUSINESS_FAIL_LOGGER.error(e.getMessage(), e); code = e.getCode() == null ? code : e.getCode(); response = FailResult.toJson(code, e.getMessage()); } catch (Throwable e) { REST_ERROR_LOGGER.error(e.getMessage(), e); response = FailResult.toJson(Code.ERROR, e.getMessage()); } return Response.status(status.value()).entity(response).build(); }
From source file:com.envision.envservice.rest.advice.HttpAdvice.java
License:Open Source License
@Around(value = "execution(public * com.envision.envservice.rest.*.*(..))") public Response around(ProceedingJoinPoint pjp) throws Throwable { Response response = (Response) pjp.proceed(); setExtraHeaders(response);/*from w w w.jav a 2 s .c o m*/ return response; }
From source file:com.envisioncn.it.super_sonic.showcase.evaluation.advice.ExceptionAdvice.java
License:Open Source License
@Around(value = "execution(public * com.envisioncn.it.super_sonic.showcase.evaluation.ctl.*.*(..))") public Object around(ProceedingJoinPoint pjp) { try {/* w w w . ja v a2 s .c om*/ return pjp.proceed(); } catch (Throwable e) { e.printStackTrace(); return "redirect:/evaluation/error"; } }
From source file:com.eryansky.core.aop.LogAspect.java
License:Apache License
/** * @param point //from ww w. java2 s.co m */ @Around("execution(* com.eryansky.service..*Manager.*(..))") public Object logAll(ProceedingJoinPoint point) { Object result = null; // ?? String methodName = point.getSignature().getName(); String className = point.getTarget().getClass().getSimpleName(); String userName = null; Long start = 0L; Long end = 0L; String ip = null; // ? try { // start = System.currentTimeMillis(); result = point.proceed(); end = System.currentTimeMillis(); // ?? SessionInfo sessionInfo = SecurityUtils.getCurrentSessionInfo(); if (sessionInfo != null) { userName = sessionInfo.getLoginName(); ip = sessionInfo.getIp(); } else { userName = ""; ip = "127.0.0.1"; logger.warn("sessionInfo."); } } catch (Throwable e) { logger.error(e.getMessage()); // e.printStackTrace(); } String name = null; // ? if (className.indexOf("Resource") > -1) { name = "??"; } else if (className.indexOf("Role") > -1) { name = "?"; } else if (className.indexOf("User") > -1) { name = "?"; } else if (className.indexOf("Organ") > -1) { name = "?"; } else { name = className; } // ? String opertype = methodName; if (StringUtils.isNotBlank(opertype) && (opertype.indexOf("save") > -1 || opertype.indexOf("update") > -1 || opertype.indexOf("delete") > -1 || opertype.indexOf("merge") > -1)) { Long time = end - start; Log log = new Log(); log.setType(LogType.operate.getValue()); log.setLoginName(userName); log.setModule(name); log.setAction(opertype); log.setOperTime(new Date(start)); log.setActionTime(time.toString()); log.setIp(ip); defaultEntityManager.save(log); } if (logger.isDebugEnabled()) { logger.debug(":{},?{},?{},{}ms.", new Object[] { userName, className, methodName, end - start }); } return result; }
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 w ww .j a va 2s . 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); } }
From source file:com.example.guestbook.JdbcTraceAspect.java
License:Open Source License
@Around("execution (* org.springframework.jdbc.core.JdbcTemplate.*(..))") public Object traceJdbcCall(final ProceedingJoinPoint pjp) throws Throwable { String spanName = SpanNameUtil.toLowerHyphen(pjp.getSignature().getName()); Span span = this.tracer.createSpan("jdbc:/" + spanName); try {/*from w w w . j a va 2 s. co m*/ return pjp.proceed(); } finally { this.tracer.close(span); } }
From source file:com.facio.aop.EmulateFilterServletAspect.java
@Around("execution(* com.facio.service.*.*(..))") // the pointcut expression public Object anyServiceLayerMethod(ProceedingJoinPoint joinPoint) throws Throwable { Object result = null;/*from w w w . j a va2s . com*/ LOG.info("calling Aspect..."); LOG.debug( "method called=" + joinPoint.getSignature().getName() + "; args=" + joinPoint.getArgs().toString()); LOG.info(" ===== Initialize RequestContext ====="); //This should be called to cache work HystrixRequestContext initializeContext = HystrixRequestContext.initializeContext(); try { result = joinPoint.proceed(); LOG.debug("result in Aspect=" + result); } finally { LOG.info(" ===== Close RequestContext ====="); if (initializeContext != null) { initializeContext.shutdown(); } LOG.info("Aspect called."); } return result; }
From source file:com.facio.test.aspect.LogginAspect.java
@Around("loggingAnnotationPointcut()") public Object methodsAnnotatedWithLogging(final ProceedingJoinPoint joinPoint) throws Throwable { LOG.info("begin methodsAnnotatedWithLogging()"); Object result = null;//from w w w.ja v a 2 s. co m try { LOG.debug("begin interpected method=" + joinPoint.getSignature()); result = joinPoint.proceed(); } finally { LOG.debug("end interpected method=" + joinPoint.getSignature()); } return result; }