Search in sources :

Example 31 with AroundInvoke

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;
}
Also used : FallbackPolicy(fish.payara.microprofile.faulttolerance.interceptors.fallback.FallbackPolicy) Config(org.eclipse.microprofile.config.Config) InvocationManager(org.glassfish.api.invocation.InvocationManager) Fallback(org.eclipse.microprofile.faulttolerance.Fallback) Retry(org.eclipse.microprofile.faulttolerance.Retry) FaultToleranceService(fish.payara.microprofile.faulttolerance.FaultToleranceService) NamingException(javax.naming.NamingException) TimeoutException(org.eclipse.microprofile.faulttolerance.exceptions.TimeoutException) AroundInvoke(javax.interceptor.AroundInvoke)

Example 32 with AroundInvoke

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();
}
Also used : RolesPermitted(fish.payara.cdi.auth.roles.RolesPermitted) CallerAccessException(fish.payara.cdi.auth.roles.CallerAccessException) AroundInvoke(javax.interceptor.AroundInvoke)

Example 33 with AroundInvoke

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;
}
Also used : RequestTraceSpan(fish.payara.notification.requesttracing.RequestTraceSpan) RequestTracingService(fish.payara.nucleus.requesttracing.RequestTracingService) AroundInvoke(javax.interceptor.AroundInvoke)

Example 34 with AroundInvoke

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();
}
Also used : Method(java.lang.reflect.Method) FacesException(javax.faces.FacesException) FacesException(javax.faces.FacesException) AroundInvoke(javax.interceptor.AroundInvoke)

Example 35 with AroundInvoke

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();
}
Also used : Meter(com.codahale.metrics.Meter) Method(java.lang.reflect.Method) AroundInvoke(javax.interceptor.AroundInvoke)

Aggregations

AroundInvoke (javax.interceptor.AroundInvoke)52 Method (java.lang.reflect.Method)10 InvocationManager (org.glassfish.api.invocation.InvocationManager)6 FaultToleranceService (fish.payara.microprofile.faulttolerance.FaultToleranceService)5 FallbackPolicy (fish.payara.microprofile.faulttolerance.interceptors.fallback.FallbackPolicy)5 InvocationTargetException (java.lang.reflect.InvocationTargetException)5 TransactionalException (javax.transaction.TransactionalException)5 Config (org.eclipse.microprofile.config.Config)5 Fallback (org.eclipse.microprofile.faulttolerance.Fallback)5 PayaraCacheKeyInvocationContext (fish.payara.cdi.jsr107.implementation.PayaraCacheKeyInvocationContext)4 Meter (com.codahale.metrics.Meter)2 Timer (com.codahale.metrics.Timer)2 TransactionManagerHelper (com.sun.enterprise.transaction.TransactionManagerHelper)2 CallerAccessException (fish.payara.cdi.auth.roles.CallerAccessException)2 RolesPermitted (fish.payara.cdi.auth.roles.RolesPermitted)2 Parameter (java.lang.reflect.Parameter)2 Principal (java.security.Principal)2 ArrayList (java.util.ArrayList)2 NoSuchElementException (java.util.NoSuchElementException)2 Message (javax.jms.Message)2