use of javax.interceptor.Interceptor in project core by weld.
the class ProbeExtension method isMonitored.
private <T> boolean isMonitored(Annotated annotated, BeanAttributes<T> beanAttributes, WeldManager weldManager) {
if (annotated.isAnnotationPresent(Interceptor.class) || annotated.isAnnotationPresent(Decorator.class)) {
// Omit interceptors and decorators
return false;
}
final Type type;
if (annotated instanceof AnnotatedMember) {
// AnnotatedField or AnnotatedMethod
type = ((AnnotatedMember<?>) annotated).getDeclaringType().getBaseType();
} else {
type = annotated.getBaseType();
}
UnproxyableResolutionException unproxyableException = Proxies.getUnproxyableTypeException(type, weldManager.getServices());
if (unproxyableException != null) {
// A bean with an interceptor must be a proxyable
ProbeLogger.LOG.invocationMonitorNotAssociatedNonProxyableType(type);
ProbeLogger.LOG.catchingTrace(unproxyableException);
return false;
}
if (type instanceof Class) {
final Class<?> clazz = (Class<?>) type;
if (invocationMonitorExcludePattern != null && invocationMonitorExcludePattern.matcher(clazz.getName()).matches()) {
ProbeLogger.LOG.invocationMonitorNotAssociatedExcluded(clazz.getName());
return false;
}
}
return true;
}
use of javax.interceptor.Interceptor in project Payara by payara.
the class RolesPermittedInterceptor method getRolesPermitted.
private RolesPermitted getRolesPermitted(InvocationContext invocationContext) {
Optional<RolesPermitted> optionalRolesPermitted;
// Try the Weld bindings first. This gives us the *exact* binding which caused this interceptor being called
@SuppressWarnings("unchecked") Set<Annotation> bindings = (Set<Annotation>) invocationContext.getContextData().get("org.jboss.weld.interceptor.bindings");
if (bindings != null) {
optionalRolesPermitted = bindings.stream().filter(annotation -> annotation.annotationType().equals(RolesPermitted.class)).findAny().map(RolesPermitted.class::cast);
if (optionalRolesPermitted.isPresent()) {
return optionalRolesPermitted.get();
}
}
final BeanManager beanManager = lazyProperties.getBeanManager();
// Failing the Weld binding, check the method first
optionalRolesPermitted = getAnnotationFromMethod(beanManager, invocationContext.getMethod(), RolesPermitted.class);
if (optionalRolesPermitted.isPresent()) {
return optionalRolesPermitted.get();
}
// If nothing found on the method, check the the bean class
optionalRolesPermitted = getAnnotation(beanManager, interceptedBean.getBeanClass(), RolesPermitted.class);
if (optionalRolesPermitted.isPresent()) {
return optionalRolesPermitted.get();
}
// find it signals a critical error.
throw new IllegalStateException("@RolesPermitted not found on " + interceptedBean.getBeanClass());
}
Aggregations