use of javax.interceptor.AroundInvoke in project Payara by payara.
the class TransactionalInterceptorRequired method transactional.
@AroundInvoke
public Object transactional(InvocationContext ctx) throws Exception {
_logger.log(FINE, CDI_JTA_REQUIRED);
if (isLifeCycleMethod(ctx)) {
return proceed(ctx);
}
setTransactionalTransactionOperationsManger(false);
try {
boolean isTransactionStarted = false;
if (getTransactionManager().getTransaction() == null) {
_logger.log(FINE, CDI_JTA_MBREQUIRED);
try {
getTransactionManager().begin();
TransactionManager transactionManager = getTransactionManager();
if (transactionManager instanceof TransactionManagerHelper) {
((TransactionManagerHelper) transactionManager).preInvokeTx(true);
}
} catch (Exception exception) {
_logger.log(FINE, CDI_JTA_MBREQUIREDBT, exception);
throw new TransactionalException("Managed bean with Transactional annotation and TxType of REQUIRED " + "encountered exception during begin " + exception, exception);
}
isTransactionStarted = true;
}
Object proceed = null;
try {
proceed = proceed(ctx);
} finally {
if (isTransactionStarted) {
try {
TransactionManager transactionManager = getTransactionManager();
if (transactionManager instanceof TransactionManagerHelper) {
((TransactionManagerHelper) transactionManager).postInvokeTx(false, true);
}
// Exception handling for proceed method call above can set TM/TRX as setRollbackOnly
if (getTransactionManager().getTransaction().getStatus() == STATUS_MARKED_ROLLBACK) {
getTransactionManager().rollback();
} else {
getTransactionManager().commit();
}
} catch (Exception exception) {
_logger.log(FINE, CDI_JTA_MBREQUIREDCT, exception);
throw new TransactionalException("Managed bean with Transactional annotation and TxType of REQUIRED " + "encountered exception during commit " + exception, exception);
}
}
}
return proceed;
} finally {
resetTransactionOperationsManager();
}
}
use of javax.interceptor.AroundInvoke in project Payara by payara.
the class TransactionalInterceptorMandatory method transactional.
@AroundInvoke
public Object transactional(InvocationContext ctx) throws Exception {
_logger.log(FINE, CDI_JTA_MANDATORY);
if (isLifeCycleMethod(ctx)) {
return proceed(ctx);
}
setTransactionalTransactionOperationsManger(false);
try {
if (getTransactionManager().getTransaction() == null) {
throw new TransactionalException("TransactionRequiredException thrown from TxType.MANDATORY transactional interceptor.", new TransactionRequiredException("Managed bean with Transactional annotation and TxType of " + "MANDATORY called outside of a transaction context"));
}
return proceed(ctx);
} finally {
resetTransactionOperationsManager();
}
}
use of javax.interceptor.AroundInvoke in project Payara by payara.
the class TransactionalInterceptorNotSupported method transactional.
@AroundInvoke
public Object transactional(InvocationContext ctx) throws Exception {
_logger.log(FINE, CDI_JTA_NOTSUPPORTED);
if (isLifeCycleMethod(ctx)) {
return proceed(ctx);
}
setTransactionalTransactionOperationsManger(true);
try {
Transaction transaction = null;
if (getTransactionManager().getTransaction() != null) {
_logger.log(FINE, CDI_JTA_MBNOTSUPPORTED);
try {
transaction = getTransactionManager().suspend();
} catch (Exception exception) {
_logger.log(FINE, CDI_JTA_MBNOTSUPPORTEDTX, exception);
throw new TransactionalException("Managed bean with Transactional annotation and TxType of NOT_SUPPORTED " + "called inside a transaction context. Suspending transaction failed due to " + exception, exception);
}
}
Object proceed = null;
try {
proceed = proceed(ctx);
} finally {
if (transaction != null) {
try {
getTransactionManager().resume(transaction);
} catch (Exception exception) {
throw new TransactionalException("Managed bean with Transactional annotation and TxType of NOT_SUPPORTED " + "encountered exception during resume " + exception, exception);
}
}
}
return proceed;
} finally {
resetTransactionOperationsManager();
}
}
use of javax.interceptor.AroundInvoke in project Payara by payara.
the class CacheResultInterceptor method cacheResult.
@AroundInvoke
@SuppressWarnings("unchecked")
public Object cacheResult(InvocationContext ctx) throws Throwable {
if (!isEnabled()) {
return ctx.proceed();
}
// get my annotation
CacheResult annotation = ctx.getMethod().getAnnotation(CacheResult.class);
PayaraCacheKeyInvocationContext<CacheResult> pctx = new PayaraCacheKeyInvocationContext<>(ctx, annotation);
CacheResolverFactory resolverF = pctx.getFactory();
CacheResolver cacheResolver = resolverF.getCacheResolver(pctx);
Cache cache = cacheResolver.resolveCache(pctx);
boolean cacheExceptions = (annotation.exceptionCacheName() != null && annotation.exceptionCacheName().length() > 0);
CacheKeyGenerator generator = pctx.getGenerator();
GeneratedCacheKey key = generator.generateCacheKey(pctx);
if (!annotation.skipGet()) {
Object cacheResult = cache.get(key);
if (cacheResult != null) {
return cacheResult;
} else {
// check exception cache
if (cacheExceptions) {
Cache exceptionCache = resolverF.getExceptionCacheResolver(pctx).resolveCache(pctx);
Throwable e = (Throwable) exceptionCache.get(key);
if (e != null) {
throw e;
}
}
}
}
// call the method
Object result = null;
try {
result = ctx.proceed();
cache.put(key, result);
} catch (Throwable e) {
if (cacheExceptions) {
Cache exceptionCache = resolverF.getExceptionCacheResolver(pctx).resolveCache(pctx);
if (shouldICache(annotation.cachedExceptions(), annotation.nonCachedExceptions(), e, true)) {
exceptionCache.put(key, e);
}
}
throw e;
}
return result;
}
use of javax.interceptor.AroundInvoke in project Payara by payara.
the class RolesPermittedInterceptor 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.
* @throws java.lang.Exception
* @throws fish.payara.cdi.auth.roles.CallerAccessException if access is not permitted
*/
@AroundInvoke
public Object method(InvocationContext invocationContext) throws Exception {
RolesPermitted roles = getRolesPermitted(invocationContext);
boolean isAccessPermitted = checkAccessPermitted(roles, invocationContext);
if (!isAccessPermitted) {
throw new CallerAccessException("Caller was not permitted access to a protected resource");
}
return invocationContext.proceed();
}
Aggregations