Skip to content

Instantly share code, notes, and snippets.

@wendelicious
Created June 5, 2013 06:09
Show Gist options
  • Save wendelicious/5711925 to your computer and use it in GitHub Desktop.
Save wendelicious/5711925 to your computer and use it in GitHub Desktop.
package com.infusionsoft.metrics.spring;
import com.infusion.crm.log.Log;
import com.infusion.util.data.filter.DataFilter;
import com.infusionsoft.util.AnnotationMethodFilter;
import org.aopalliance.intercept.MethodInvocation;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import java.lang.reflect.Method;
/**
* Created with IntelliJ IDEA.
* User: wendel.schultz
* Date: 6/4/13
* Time: 3:38 PM
*/
public class StereotypedMetricsPublishingMethodInterceptor extends MetricsPublishingMethodInterceptor{
private final DataFilter<Method> requestMappingMethodFilter;
public StereotypedMetricsPublishingMethodInterceptor(){
final AnnotationMethodFilter methodFilter = new AnnotationMethodFilter();
methodFilter.setAnnotation(RequestMapping.class);
this.requestMappingMethodFilter = methodFilter;
setPublicMethodsOnly(false);
}
@Override
public boolean shouldAdviseWithMetrics(MethodInvocation methodInvocation) {
final Method targetMethod = methodInvocation.getMethod();
if(Log.isDebugEnabled(Log.Context.Metrics)){
Log.debug(Log.Context.Metrics, "Is Controller: " + isController(targetMethod.getDeclaringClass()));
}
if(isController(targetMethod.getDeclaringClass())){
if(Log.isDebugEnabled(Log.Context.Metrics)){
Log.debug(Log.Context.Metrics, "shouldAdviseWithMetrics: Stereotyped true");
}
return requestMappingMethodFilter.filter(targetMethod);
} else {
return super.shouldAdviseWithMetrics(methodInvocation);
}
}
private boolean isController(Class<?> clazz){
return AnnotationUtils.findAnnotation(clazz, Controller.class) != null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment