Search in sources :

Example 36 with AroundInvoke

use of javax.interceptor.AroundInvoke in project microservice_framework by CJSCommonPlatform.

the class JmsLoggerMetadataInterceptor method addRequestDataToMappedDiagnosticContext.

@AroundInvoke
protected Object addRequestDataToMappedDiagnosticContext(final InvocationContext context) throws Exception {
    traceLogger.trace(logger, () -> "Adding Request data to MDC");
    final Object[] parameters = context.getParameters();
    parameterChecker.check(parameters);
    final TextMessage message = (TextMessage) parameters[0];
    final JsonObjectBuilder builder = createObjectBuilder();
    addServiceContextNameIfPresent(builder);
    addMetaDataToBuilder(message, builder);
    MDC.put(REQUEST_DATA, builder.build().toString());
    traceLogger.trace(logger, () -> "Request data added to MDC");
    final Object result = context.proceed();
    traceLogger.trace(logger, () -> "Clearing MDC");
    MDC.clear();
    return result;
}
Also used : JsonObjectBuilder(javax.json.JsonObjectBuilder) TextMessage(javax.jms.TextMessage) AroundInvoke(javax.interceptor.AroundInvoke)

Example 37 with AroundInvoke

use of javax.interceptor.AroundInvoke in project camunda-bpm-platform by camunda.

the class StartProcessInterceptor method invoke.

@AroundInvoke
public Object invoke(InvocationContext ctx) throws Exception {
    try {
        Object result = ctx.proceed();
        StartProcess startProcessAnnotation = ctx.getMethod().getAnnotation(StartProcess.class);
        String key = startProcessAnnotation.value();
        Map<String, Object> variables = extractVariables(startProcessAnnotation, ctx);
        businessProcess.startProcessByKey(key, variables);
        return result;
    } catch (InvocationTargetException e) {
        Throwable cause = e.getCause();
        if (cause != null && cause instanceof Exception) {
            throw (Exception) cause;
        } else {
            throw e;
        }
    } catch (Exception e) {
        throw new ProcessEngineException("Error while starting process using @StartProcess on method  '" + ctx.getMethod() + "': " + e.getMessage(), e);
    }
}
Also used : StartProcess(org.camunda.bpm.engine.cdi.annotation.StartProcess) InvocationTargetException(java.lang.reflect.InvocationTargetException) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException) AroundInvoke(javax.interceptor.AroundInvoke)

Example 38 with AroundInvoke

use of javax.interceptor.AroundInvoke in project ART-TIME by Artezio.

the class ShiroSecuredInterceptor method interceptShiroSecurity.

@AroundInvoke
public Object interceptShiroSecurity(InvocationContext context) throws Exception {
    Subject subject = SecurityUtils.getSubject();
    Class<?> clas = context.getTarget().getClass();
    Method method = context.getMethod();
    if (!subject.isAuthenticated() && hasAnnotation(clas, method, RequiresAuthentication.class)) {
        throw new UnauthenticatedException("Authentication required");
    }
    if (subject.getPrincipal() != null && hasAnnotation(clas, method, RequiresGuest.class)) {
        throw new UnauthenticatedException("Guest required");
    }
    if (subject.getPrincipal() == null && hasAnnotation(clas, method, RequiresUser.class)) {
        throw new UnauthenticatedException("User required");
    }
    RequiresRoles roles = getAnnotation(clas, method, RequiresRoles.class);
    if (roles != null) {
        subject.checkRoles(Arrays.asList(roles.value()));
    }
    RequiresPermissions permissions = getAnnotation(clas, method, RequiresPermissions.class);
    if (permissions != null) {
        subject.checkPermissions(permissions.value());
    }
    return context.proceed();
}
Also used : RequiresGuest(org.apache.shiro.authz.annotation.RequiresGuest) RequiresUser(org.apache.shiro.authz.annotation.RequiresUser) RequiresPermissions(org.apache.shiro.authz.annotation.RequiresPermissions) UnauthenticatedException(org.apache.shiro.authz.UnauthenticatedException) RequiresAuthentication(org.apache.shiro.authz.annotation.RequiresAuthentication) Method(java.lang.reflect.Method) RequiresRoles(org.apache.shiro.authz.annotation.RequiresRoles) Subject(org.apache.shiro.subject.Subject) AroundInvoke(javax.interceptor.AroundInvoke)

Example 39 with AroundInvoke

use of javax.interceptor.AroundInvoke in project microservice_framework by CJSCommonPlatform.

the class JsonSchemaValidationInterceptor method validate.

@AroundInvoke
protected Object validate(final InvocationContext context) throws Exception {
    final Object[] parameters = context.getParameters();
    parametersChecker.check(parameters);
    final TextMessage message = (TextMessage) parameters[0];
    if (shouldValidate(message)) {
        validate(message);
    }
    return context.proceed();
}
Also used : TextMessage(javax.jms.TextMessage) AroundInvoke(javax.interceptor.AroundInvoke)

Example 40 with AroundInvoke

use of javax.interceptor.AroundInvoke in project Payara by payara.

the class ClusterScopedInterceptor method lockAndRefresh.

@AroundInvoke
public Object lockAndRefresh(InvocationContext invocationContext) throws Exception {
    Class<?> beanClass = invocationContext.getMethod().getDeclaringClass();
    Clustered clusteredAnnotation = getAnnotation(beanManager, beanClass);
    try {
        lock(beanClass, clusteredAnnotation);
        return invocationContext.proceed();
    } finally {
        refresh(beanClass, invocationContext.getTarget());
        unlock(beanClass, clusteredAnnotation);
    }
}
Also used : Clustered(fish.payara.cluster.Clustered) 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