use of org.apache.openejb.core.ExceptionType in project tomee by apache.
the class EntityContainer method handleException.
private void handleException(final TransactionPolicy txPolicy, Throwable e, final ThreadContext callContext, final EntityBean bean) throws OpenEJBException {
final ExceptionType type;
if (e instanceof InvocationTargetException) {
e = ((InvocationTargetException) e).getTargetException();
type = callContext.getBeanContext().getExceptionType(e);
} else if (e instanceof ApplicationException) {
e = ((ApplicationException) e).getRootCause();
type = ExceptionType.APPLICATION;
} else if (e instanceof SystemException) {
e = ((SystemException) e).getRootCause();
type = ExceptionType.SYSTEM;
} else {
type = ExceptionType.SYSTEM;
}
if (type == ExceptionType.SYSTEM) {
// System Exception
if (bean != null) {
try {
instanceManager.discardInstance(callContext, bean);
} catch (final SystemException e1) {
logger.error("The instance manager encountered an unkown system exception while trying to discard the entity instance with primary key " + callContext.getPrimaryKey());
}
}
handleSystemException(txPolicy, e, callContext);
} else {
// Application Exception
instanceManager.poolInstance(callContext, bean, callContext.getPrimaryKey());
handleApplicationException(txPolicy, e, type == ExceptionType.APPLICATION_ROLLBACK);
}
}
use of org.apache.openejb.core.ExceptionType in project tomee by apache.
the class CmpContainer method businessMethod.
private Object businessMethod(final Method callMethod, final Method runMethod, final Object[] args, final ThreadContext callContext, final InterfaceType interfaceType) throws OpenEJBException {
final BeanContext beanContext = callContext.getBeanContext();
final TransactionPolicy txPolicy = createTransactionPolicy(beanContext.getTransactionType(callMethod, interfaceType), callContext);
final EntityBean bean;
Object returnValue = null;
entrancyTracker.enter(beanContext, callContext.getPrimaryKey());
try {
bean = (EntityBean) cmpEngine.loadBean(callContext, callContext.getPrimaryKey());
if (bean == null) {
throw new NoSuchObjectException(beanContext.getDeploymentID() + " : " + callContext.getPrimaryKey());
}
returnValue = runMethod.invoke(bean, args);
// when there is not transaction, merge the data from the bean back into the cmp engine
cmpEngine.storeBeanIfNoTx(callContext, bean);
} catch (final NoSuchObjectException e) {
handleApplicationException(txPolicy, e, false);
} catch (Throwable e) {
if (e instanceof InvocationTargetException) {
e = ((InvocationTargetException) e).getTargetException();
}
final ExceptionType type = callContext.getBeanContext().getExceptionType(e);
if (type == ExceptionType.SYSTEM) {
/* System Exception ****************************/
handleSystemException(txPolicy, e, callContext);
} else {
/* Application Exception ***********************/
handleApplicationException(txPolicy, e, type == ExceptionType.APPLICATION_ROLLBACK);
}
} finally {
entrancyTracker.exit(beanContext, callContext.getPrimaryKey());
afterInvoke(txPolicy, callContext);
}
return returnValue;
}
use of org.apache.openejb.core.ExceptionType in project tomee by apache.
the class SingletonContainer method _invoke.
protected Object _invoke(final Method callMethod, final Method runMethod, final Object[] args, final Instance instance, final ThreadContext callContext, final InterfaceType callType) throws OpenEJBException {
final BeanContext beanContext = callContext.getBeanContext();
final Duration accessTimeout = getAccessTimeout(beanContext, runMethod);
final boolean read = javax.ejb.LockType.READ.equals(beanContext.getConcurrencyAttribute(runMethod));
final Lock lock = aquireLock(read, accessTimeout, instance, runMethod);
Object returnValue;
try {
final TransactionPolicy txPolicy = createTransactionPolicy(beanContext.getTransactionType(callMethod, callType), callContext);
returnValue = null;
try {
if (callType == InterfaceType.SERVICE_ENDPOINT) {
callContext.setCurrentOperation(Operation.BUSINESS_WS);
returnValue = invokeWebService(args, beanContext, runMethod, instance);
} else {
final List<InterceptorData> interceptors = beanContext.getMethodInterceptors(runMethod);
final InterceptorStack interceptorStack = new InterceptorStack(instance.bean, runMethod, callType == InterfaceType.TIMEOUT ? Operation.TIMEOUT : Operation.BUSINESS, interceptors, instance.interceptors);
returnValue = interceptorStack.invoke(args);
}
} catch (final Throwable e) {
// handle reflection exception
final ExceptionType type = beanContext.getExceptionType(e);
if (type == ExceptionType.SYSTEM) {
/* System Exception ****************************/
// The bean instance is not put into the pool via instanceManager.poolInstance
// and therefore the instance will be garbage collected and destroyed.
// For this reason the discardInstance method of the StatelessInstanceManager
// does nothing.
handleSystemException(txPolicy, e, callContext);
} else {
/* Application Exception ***********************/
handleApplicationException(txPolicy, e, type == ExceptionType.APPLICATION_ROLLBACK);
}
} finally {
afterInvoke(txPolicy, callContext);
}
} finally {
lock.unlock();
}
return returnValue;
}
use of org.apache.openejb.core.ExceptionType in project tomee by apache.
the class StatelessContainer method _invoke.
@SuppressWarnings("ThrowFromFinallyBlock")
private Object _invoke(final Method callMethod, final Method runMethod, final Object[] args, final Instance instance, final ThreadContext callContext, final InterfaceType type) throws OpenEJBException {
final BeanContext beanContext = callContext.getBeanContext();
final TransactionPolicy txPolicy = createTransactionPolicy(beanContext.getTransactionType(callMethod, type), callContext);
Object returnValue = null;
try {
if (type == InterfaceType.SERVICE_ENDPOINT) {
callContext.setCurrentOperation(Operation.BUSINESS_WS);
returnValue = invokeWebService(args, beanContext, runMethod, instance);
} else {
final List<InterceptorData> interceptors = beanContext.getMethodInterceptors(runMethod);
final Operation operation = type == InterfaceType.TIMEOUT ? Operation.TIMEOUT : Operation.BUSINESS;
final InterceptorStack interceptorStack = new InterceptorStack(instance.bean, runMethod, operation, interceptors, instance.interceptors);
returnValue = interceptorStack.invoke(args);
}
} catch (final Throwable re) {
// handle reflection exception
final ExceptionType exceptionType = beanContext.getExceptionType(re);
if (exceptionType == ExceptionType.SYSTEM) {
/* System Exception ****************************/
// The bean instance is not put into the pool via instanceManager.poolInstance
// and therefore the instance will be garbage collected and destroyed.
// In case of StrictPooling flag being set to true we also release the semaphore
// in the discardInstance method of the instanceManager.
callContext.setDiscardInstance(true);
handleSystemException(txPolicy, re, callContext);
} else {
/* Application Exception ***********************/
handleApplicationException(txPolicy, re, exceptionType == ExceptionType.APPLICATION_ROLLBACK);
}
} finally {
try {
afterInvoke(txPolicy, callContext);
} catch (final SystemException | RuntimeException e) {
callContext.setDiscardInstance(true);
throw e;
}
}
return returnValue;
}
use of org.apache.openejb.core.ExceptionType in project tomee by apache.
the class StatefulContainer method handleException.
private void handleException(final ThreadContext callContext, final TransactionPolicy txPolicy, final Throwable e) throws ApplicationException {
if (e instanceof ApplicationException) {
throw (ApplicationException) e;
}
final ExceptionType type = callContext.getBeanContext().getExceptionType(e);
if (type == ExceptionType.SYSTEM) {
discardInstance(callContext.getPrimaryKey(), null);
EjbTransactionUtil.handleSystemException(txPolicy, e, callContext);
} else {
EjbTransactionUtil.handleApplicationException(txPolicy, e, type == ExceptionType.APPLICATION_ROLLBACK);
}
}
Aggregations