List of usage examples for org.aspectj.lang ProceedingJoinPoint getTarget
Object getTarget();
From source file:org.cybercat.automation.core.SoapServicesAspect.java
License:Apache License
public Object invoke(ProceedingJoinPoint pjp) throws Throwable { if (pjp.getTarget() instanceof SoapService) { SoapService service = (SoapService) pjp.getTarget(); ISessionManager session = service.getSoapSession(); //set Session session.putCookieSnapshot();// w ww. j av a 2 s .com Object result = pjp.proceed(this.before(this.getMethod(pjp), pjp.getArgs(), pjp.getTarget())); //get Session session.makeCookieSnapshot(); return result; } else { return pjp.proceed(); } }
From source file:org.cybercat.automation.core.SoapServicesAspect.java
License:Apache License
private Method getMethod(ProceedingJoinPoint pjp) { String methodName = pjp.getSignature().getName(); Method[] methods = pjp.getTarget().getClass().getMethods(); for (int i = 0; i < methods.length; i++) { if (methods[i].getName().equals(methodName)) { return methods[i]; }//from w w w . j a v a 2 s. c o m } return null; }
From source file:org.dbg4j.core.aop.DebuggingAspect.java
License:Apache License
protected Object doDebug(final ProceedingJoinPoint pjp, final Debug debug) throws Throwable { DebuggingAdapter debuggerInstance = getDebugger(debug); return debuggerInstance.debug(new MethodInvocationPoint() { @Override/*from ww w . j a v a2 s.co m*/ public Method getMethod() { return DebuggingAspect.this.getMethod(pjp); } @Nullable @Override public Object invoke() throws Throwable { return pjp.proceed(); } @Nullable @Override public Object[] getParameters() { return pjp.getArgs(); } @Nullable @Override public Object getInstance() { return pjp.getTarget(); } @Override public Debug getDebugAnnotation() { return debug; } }); }
From source file:org.dbg4j.core.aop.DebuggingAspect.java
License:Apache License
protected Method getMethod(final ProceedingJoinPoint pjp) { MethodSignature signature = (MethodSignature) pjp.getSignature(); Method method = signature.getMethod(); //if this is interface method, but not implementation method, we're trying to get "real" one if (method.getDeclaringClass().isInterface()) { try {//from ww w .j a v a 2 s . c o m method = pjp.getTarget().getClass().getDeclaredMethod(method.getName(), method.getParameterTypes()); } catch (Exception ignored) { /*it's better to have interface method than nothing*/} } return method; }
From source file:org.easyrec.utils.spring.cache.aop.CachingAspectAdvice.java
License:Open Source License
/** * Takes a method name and its arguments and stores the result in a cache. * * @param pjp the JoinPoint containing information about the intercepted method call * @return the result of the method call * @throws Throwable// ww w . ja v a2 s . c om */ public Object cacheMethodResult(ProceedingJoinPoint pjp) throws Throwable { String targetName = pjp.getTarget().getClass().getName(); String methodName = pjp.getSignature().getName(); Object[] args = pjp.getArgs(); Object result; Log logger = LogFactory.getLog(pjp.getTarget().getClass()); if (logger.isDebugEnabled()) { logger.debug("looking for method " + methodName + " result in cache"); } String cacheKey = getCacheKey(targetName, methodName, args); Element element = cache.get(cacheKey); if (element == null) { if (logger.isDebugEnabled()) { logger.debug("Cache miss - calling intercepted method!"); } result = pjp.proceed(); if (result == null) return null; if (logger.isDebugEnabled()) { logger.debug("Caching new result!"); } try { element = new Element(cacheKey, (Serializable) result); } catch (Exception e) { logger.debug("xxResult " + result + " for key: " + cacheKey + "..." + e.getMessage()); e.printStackTrace(); } cache.put(element); } assert element != null; return element.getValue(); }
From source file:org.easyrec.utils.spring.exception.aop.ThrowableToExceptionAspectAdvice.java
License:Open Source License
public Object mapToException(ProceedingJoinPoint pjp, MapThrowableToException mtte) throws Exception { try {/*from w ww . j a v a 2 s. c o m*/ return pjp.proceed(); } catch (Throwable ta) { Log logger = LogFactory.getLog(pjp.getTarget().getClass()); Constructor<? extends Exception> cons; Exception ex = null; LoggerUtils.log(logger, mtte.logLevel(), "Aspect caught Exception", ta); try { cons = mtte.exceptionClazz().getConstructor(String.class); ex = cons.newInstance((ta.getMessage())); } catch (NoSuchMethodException nsme) { logger.error("The exception passed to the aspect does not provide a constructor(String message)!", nsme); } catch (Exception e) { logger.error("Error instantiating aspect Exception, throwing original instead", e); throw (Exception) ta; } throw ex; } }
From source file:org.easyrec.utils.spring.log.aop.IOLogAspectAdvice.java
License:Open Source License
/** * Logs a method call and prints the arguments and the return value to the log level given in the * iol parameter.//from w ww . ja va 2 s.c o m * * @param pjp the JoinPoint containing information about the intercepted method call * @param iol annotation for the IOLog aspect; contains info about the log level * @return the result of the method call * @throws Throwable */ public Object logIO(ProceedingJoinPoint pjp, IOLog iol) throws Throwable { StringBuilder sb = new StringBuilder(); String methodName = pjp.getSignature().getName(); // parameter names only work with when compiled with AspectJ compiler //String[] params = ((MethodSignature)pjp.getSignature()).getParameterNames(); Class<?>[] paramTypes = ((MethodSignature) pjp.getSignature()).getParameterTypes(); Class<?> returnType = ((MethodSignature) pjp.getSignature()).getReturnType(); Object[] args = pjp.getArgs(); Log logger = LogFactory.getLog(pjp.getTarget().getClass()); Object o = pjp.proceed(); if (!LoggerUtils.isLogLevelEnabled(logger, iol.value())) return o; sb.append(methodName).append(argsToString(paramTypes, args)).append(':').append(returnType.getName()) .append('=').append(o); LoggerUtils.log(logger, iol.value(), sb.toString()); return o; }
From source file:org.entando.entando.aps.system.services.cache.CacheInfoManager.java
License:Open Source License
@Around("@annotation(cacheableInfo)") public Object aroundCacheableMethod(ProceedingJoinPoint pjp, CacheableInfo cacheableInfo) throws Throwable { Object result = pjp.proceed(); if (cacheableInfo.expiresInMinute() < 0 && (cacheableInfo.groups() == null || cacheableInfo.groups().trim().length() == 0)) { return result; }//from w w w. j a v a 2 s .co m try { MethodSignature methodSignature = (MethodSignature) pjp.getSignature(); Method targetMethod = methodSignature.getMethod(); Class targetClass = pjp.getTarget().getClass(); Method effectiveTargetMethod = targetClass.getMethod(targetMethod.getName(), targetMethod.getParameterTypes()); Cacheable cacheable = effectiveTargetMethod.getAnnotation(Cacheable.class); if (null == cacheable) { return result; } String[] cacheNames = cacheable.value(); Object key = this.evaluateExpression(cacheable.key().toString(), targetMethod, pjp.getArgs(), effectiveTargetMethod, targetClass); for (String cacheName : cacheNames) { if (cacheableInfo.groups() != null && cacheableInfo.groups().trim().length() > 0) { Object groupsCsv = this.evaluateExpression(cacheableInfo.groups().toString(), targetMethod, pjp.getArgs(), effectiveTargetMethod, targetClass); if (null != groupsCsv && groupsCsv.toString().trim().length() > 0) { String[] groups = groupsCsv.toString().split(","); this.putInGroup(cacheName, key.toString(), groups); } } if (cacheableInfo.expiresInMinute() > 0) { this.setExpirationTime(cacheName, key.toString(), cacheableInfo.expiresInMinute()); } } } catch (Throwable t) { logger.error("Error while evaluating cacheableInfo annotation", t); throw new ApsSystemException("Error while evaluating cacheableInfo annotation", t); } return result; }
From source file:org.entando.entando.aps.system.services.cache.CacheInfoManager.java
License:Open Source License
@Around("@annotation(cacheInfoEvict)") public Object aroundCacheInfoEvictMethod(ProceedingJoinPoint pjp, CacheInfoEvict cacheInfoEvict) throws Throwable { try {/*from ww w .j a v a2s. co m*/ MethodSignature methodSignature = (MethodSignature) pjp.getSignature(); Method targetMethod = methodSignature.getMethod(); Class targetClass = pjp.getTarget().getClass(); Method effectiveTargetMethod = targetClass.getMethod(targetMethod.getName(), targetMethod.getParameterTypes()); String[] cacheNames = cacheInfoEvict.value(); Object groupsCsv = this.evaluateExpression(cacheInfoEvict.groups().toString(), targetMethod, pjp.getArgs(), effectiveTargetMethod, targetClass); if (null != groupsCsv && groupsCsv.toString().trim().length() > 0) { String[] groups = groupsCsv.toString().split(","); for (String group : groups) { for (String cacheName : cacheNames) { this.flushGroup(cacheName, group); } } } } catch (Throwable t) { logger.error("Error while flushing group", t); throw new ApsSystemException("Error while flushing group", t); } return pjp.proceed(); }
From source file:org.escidoc.core.aspects.PatternPerformanceAspect.java
License:Open Source License
@Around("call(public java.lang.String java.lang.String.replaceAll(java.lang.String, java.lang.String))" + " && !within(org.escidoc.core.aspects.PatternPerformanceAspect)" + " && !within(org.escidoc.core.util.regex..*)") public Object optimizeReplaceAllWithStrings(final ProceedingJoinPoint joinPoint) { final String target = (String) joinPoint.getTarget(); final String patternString = (String) joinPoint.getArgs()[0]; final String replacement = (String) joinPoint.getArgs()[1]; final Matcher matcher = matcherFactory.createMatcher(patternString); return matcher.reset(target).replaceAll(replacement); }