Search in sources :

Example 51 with AroundInvoke

use of javax.interceptor.AroundInvoke in project iobserve-analysis by research-iobserve.

the class TraceObjectInterceptor method interceptMethodCall.

/**
 * Around advice configuration.
 *
 * @param context
 *            the invocation context of a bean call.
 * @return the return value of the next method in the chain
 * @throws Throwable
 */
@AroundInvoke
public Object interceptMethodCall(final InvocationContext context) throws Throwable {
    // (IllegalThrowsCheck)
    if (this.monitoringCtrl.isMonitoringEnabled()) {
        final String signature = context.getMethod().toString();
        if (this.monitoringCtrl.isProbeActivated(signature)) {
            // common fields
            TraceMetadata trace = TraceObjectInterceptor.TRACEREGISTRY.getTrace();
            final boolean newTrace = trace == null;
            if (newTrace) {
                trace = TraceObjectInterceptor.TRACEREGISTRY.registerTrace();
                this.monitoringCtrl.newMonitoringRecord(trace);
            }
            final long traceId = trace.getTraceId();
            final String clazz = context.getTarget().getClass().getCanonicalName();
            final int objectId = System.identityHashCode(context);
            // measure before execution
            this.monitoringCtrl.newMonitoringRecord(new BeforeOperationObjectEvent(this.timeSource.getTime(), traceId, trace.getNextOrderId(), signature, clazz, objectId));
            // execution of the called method
            try {
                final Object retval = context.proceed();
                // measure after successful execution
                this.monitoringCtrl.newMonitoringRecord(new AfterOperationObjectEvent(this.timeSource.getTime(), traceId, trace.getNextOrderId(), signature, clazz, objectId));
                return retval;
            } catch (final Throwable th) {
                // NOPMD NOCS (catch throw might
                // ok here)
                // measure after failed execution
                this.monitoringCtrl.newMonitoringRecord(new AfterOperationFailedObjectEvent(this.timeSource.getTime(), traceId, trace.getNextOrderId(), signature, clazz, th.toString(), objectId));
                throw th;
            } finally {
                if (newTrace) {
                    // close the trace
                    TraceObjectInterceptor.TRACEREGISTRY.unregisterTrace();
                }
            }
        } else {
            return context.proceed();
        }
    } else {
        return context.proceed();
    }
}
Also used : AfterOperationObjectEvent(kieker.common.record.flow.trace.operation.object.AfterOperationObjectEvent) AfterOperationFailedObjectEvent(kieker.common.record.flow.trace.operation.object.AfterOperationFailedObjectEvent) BeforeOperationObjectEvent(kieker.common.record.flow.trace.operation.object.BeforeOperationObjectEvent) TraceMetadata(kieker.common.record.flow.trace.TraceMetadata) AroundInvoke(javax.interceptor.AroundInvoke)

Example 52 with AroundInvoke

use of javax.interceptor.AroundInvoke in project UVMS-ActivityModule-APP by UnionVMS.

the class UserRoleInterceptor method interceptRequest.

@AroundInvoke
public Object interceptRequest(final InvocationContext ic) throws Exception {
    IUserRoleInterceptor iUserRoleInterceptor = ic.getMethod().getAnnotation(IUserRoleInterceptor.class);
    // Get User role defined in the Rest service
    ActivityFeaturesEnum[] features = iUserRoleInterceptor.requiredUserRole();
    // Request parameters
    Object[] parameters = ic.getParameters();
    HttpServletRequest req = getHttpServletRequest(parameters);
    boolean isUserAuthorized = false;
    for (ActivityFeaturesEnum activityFeaturesEnum : features) {
        isUserAuthorized = req.isUserInRole(activityFeaturesEnum.value());
    }
    if (!isUserAuthorized) {
        throw new ServiceException(ErrorCodes.NOT_AUTHORIZED);
    }
    return ic.proceed();
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ActivityFeaturesEnum(eu.europa.ec.fisheries.uvms.activity.model.schemas.ActivityFeaturesEnum) ServiceException(eu.europa.ec.fisheries.uvms.commons.service.exception.ServiceException) 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