use of javax.interceptor.AroundInvoke in project Payara by payara.
the class TimeoutInterceptor method intercept.
@AroundInvoke
public Object intercept(InvocationContext invocationContext) throws Exception {
Object proceededInvocationContext = null;
FaultToleranceService faultToleranceService = Globals.getDefaultBaseServiceLocator().getService(FaultToleranceService.class);
InvocationManager invocationManager = Globals.getDefaultBaseServiceLocator().getService(InvocationManager.class);
Config config = null;
try {
config = ConfigProvider.getConfig();
} catch (IllegalArgumentException ex) {
logger.log(Level.INFO, "No config could be found", ex);
}
try {
if (faultToleranceService.isFaultToleranceEnabled(faultToleranceService.getApplicationName(invocationManager, invocationContext), config)) {
logger.log(Level.FINER, "Proceeding invocation with timeout semantics");
proceededInvocationContext = timeout(invocationContext);
} else {
// If fault tolerance isn't enabled, just proceed as normal
logger.log(Level.FINE, "Fault Tolerance not enabled for {0}, proceeding normally without timeout.", faultToleranceService.getApplicationName(invocationManager, invocationContext));
proceededInvocationContext = invocationContext.proceed();
}
} catch (Exception ex) {
Retry retry = FaultToleranceCdiUtils.getAnnotation(beanManager, Retry.class, invocationContext);
if (retry != null) {
logger.log(Level.FINE, "Retry annotation found on method, propagating error upwards.");
throw ex;
} else {
Fallback fallback = FaultToleranceCdiUtils.getAnnotation(beanManager, Fallback.class, invocationContext);
if (fallback != null) {
logger.log(Level.FINE, "Fallback annotation found on method, and no Retry annotation - " + "falling back from Timeout");
FallbackPolicy fallbackPolicy = new FallbackPolicy(fallback, config, invocationContext);
proceededInvocationContext = fallbackPolicy.fallback(invocationContext);
} else {
throw ex;
}
}
}
return proceededInvocationContext;
}
use of javax.interceptor.AroundInvoke in project Payara by payara.
the class RolesCDIInterceptor method method.
/**
* Method invoked whenever a method annotated with @Roles, or a method within a class annotated with @Roles is
* called.
*
* @param invocationContext Context provided by Weld.
* @return Proceed to next interceptor in chain.
*/
@AroundInvoke
public Object method(InvocationContext invocationContext) throws Exception {
RolesPermitted roles = getRolesPermitted(invocationContext);
boolean isAccessPermitted = checkAccessPermitted(roles);
if (!isAccessPermitted) {
throw new CallerAccessException("Caller was not permitted access to a protected resource");
}
return invocationContext.proceed();
}
use of javax.interceptor.AroundInvoke in project Payara by payara.
the class RequestTracingCdiInterceptor method traceCdiCall.
@AroundInvoke
public Object traceCdiCall(InvocationContext ctx) throws Exception {
RequestTracingService requestTracing = Globals.getDefaultHabitat().getService(RequestTracingService.class);
Object proceed = null;
if (requestTracing != null && requestTracing.isRequestTracingEnabled()) {
RequestTraceSpan span = new RequestTraceSpan("executeCdiMethod");
span.addSpanTag("TargetClass", ctx.getTarget().getClass().getName());
span.addSpanTag("MethodName", ctx.getMethod().getName());
proceed = ctx.proceed();
requestTracing.traceSpan(span);
} else {
proceed = ctx.proceed();
}
return proceed;
}
use of javax.interceptor.AroundInvoke in project rubia-forums by flashboss.
the class AuthorizationListener method accessAllowed.
@AroundInvoke
public Object accessAllowed(InvocationContext ctx) throws Exception {
Method businessAction = ctx.getMethod();
Object managedBean = ctx.getTarget();
boolean isAccessAllowed = false;
// enforce authorization security
try {
// start building the SecurityContext here for the Authorization
// System
ActionContext securityContext = new ActionContext(getUser(userModule));
securityContext.setBusinessAction(businessAction);
securityContext.setManagedBean(managedBean);
// feed this context to the Authorization system which will decide
// whether
// access should be granted or not
isAccessAllowed = forumsACLProvider.hasAccess(securityContext);
if (!isAccessAllowed)
return null;
} catch (NoSuchMethodException nsme) {
throw new FacesException("Error calling action method of component with id " + nsme, nsme);
} catch (Exception e) {
throw new FacesException("Error calling action method of component with id " + e, e);
}
return ctx.proceed();
}
use of javax.interceptor.AroundInvoke in project solr-document-store by DBCDK.
the class MeteredInterceptor method timer.
@AroundInvoke
public Object timer(InvocationContext ic) throws Exception {
Method method = ic.getMethod();
Meter meter = METERS.computeIfAbsent(method, this::makeMeter);
meter.mark();
return ic.proceed();
}
Aggregations