Announcement Announcement Module
Collapse
No announcement yet.
2 aspects based on annotations Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 2 aspects based on annotations

    Hi,

    In my application code there is already one aspect (mongo availabilty) based on annotation which works fine.
    Code:
    @Retention(RetentionPolicy.RUNTIME)
    @Target(ElementType.METHOD)
    @Inherited
    @Documented
    public @interface MongoAvailability {
    //    MongoAvailabilityType availabilityType() default MongoAvailabilityType.read;
    }
    
     @Around("@annotation(mongoAvailability)")
        public Object mongoAvailability(ProceedingJoinPoint joinPoint, MongoAvailability mongoAvailability) throws Throwable {
    //        MongoAvailabilityType mongoAvailabilityType = mongoAvailability.availabilityType();
            String signature = joinPoint.getSignature().toShortString();
            try {
                return joinPoint.proceed(joinPoint.getArgs());
    
    //            if (mongoAvailabilityType == MongoAvailabilityType.read /*&& tsMongoStatus.isMongoAvailable()*/) {
    //                return joinPoint.proceed(joinPoint.getArgs());
    //            }
            } catch (Network e) {
                LOGGER.warn("Setting mongo to unavailable status MongoException " + e.getMessage());
                LOGGER.error(String.format("Connection timeout to mongo occurred for %s", signature));
                tsMongoStatus.setMongoUnavailable();
            } catch (MongoException e) {
                LOGGER.warn(String.format("MongoException to %s cause %s", signature, e.getMessage()));
                tsMongoStatus.setMongoUnavailable();
            } catch (Exception e) {
                LOGGER.error(String.format("General exception in %s", signature), e.getMessage());
            }
            return null;
        }
    I added new aspect based on the same logic but methods which are annotated with my new annotation do not pass in the aspect code
    Code:
    @Retention(RetentionPolicy.RUNTIME)
    @Target(ElementType.METHOD)
    @Inherited
    @Documented
    public @interface RequestTimeout {
    
    }
    
    @Component
    @Aspect
    public class RequestTimeoutInterceptor {
    	
    	@Around("@annotation(requestTimeout)")
    	public Object requestTimeout(ProceedingJoinPoint joinPoint, RequestTimeout requestTimeout)
    			throws Throwable {
    		String signature = joinPoint.getSignature().toShortString();
    		return joinPoint.proceed(joinPoint.getArgs());
    
    	}
    
    }
    however if I change the around value to execution expression it works:
    Code:
    @Component
    @Aspect
    public class RequestTimeoutInterceptor {
    	
    	@Around("execution(* com.amobee.flowmodules.adselection.filtering.caps.*.*(..))")
    	//@Around("@annotation(requestTimeout)")
    	public Object requestTimeout(ProceedingJoinPoint joinPoint)
    			throws Throwable {
    		String signature = joinPoint.getSignature().toShortString();
    		return joinPoint.proceed(joinPoint.getArgs());
    
    	}
    
    }
    What can cause this issue? is it something in the annotation? is it something in spring aop?

    Thanks,
    Daniela
Working...
X