use of org.apache.openejb.core.ExceptionType in project tomee by apache.
the class MdbContainer method _invoke.
private Object _invoke(final Object instance, final Method runMethod, final Object[] args, final BeanContext beanContext, final InterfaceType interfaceType, final MdbCallContext mdbCallContext) throws SystemException, ApplicationException {
final Object returnValue;
try {
final List<InterceptorData> interceptors = beanContext.getMethodInterceptors(runMethod);
final InterceptorStack interceptorStack = new InterceptorStack(((Instance) instance).bean, runMethod, interfaceType == InterfaceType.TIMEOUT ? Operation.TIMEOUT : Operation.BUSINESS, interceptors, ((Instance) instance).interceptors);
returnValue = interceptorStack.invoke(args);
return returnValue;
} catch (Throwable e) {
// unwrap invocation target exception
if (e instanceof InvocationTargetException) {
e = ((InvocationTargetException) e).getTargetException();
}
// Any exception thrown by reflection; not by the enterprise bean. Possible
// Exceptions are:
// IllegalAccessException - if the underlying method is inaccessible.
// IllegalArgumentException - if the number of actual and formal parameters differ, or if an unwrapping conversion fails.
// NullPointerException - if the specified object is null and the method is an instance method.
// ExceptionInInitializerError - if the initialization provoked by this method fails.
final ExceptionType type = beanContext.getExceptionType(e);
if (type == ExceptionType.SYSTEM) {
//
/// System Exception ****************************
handleSystemException(mdbCallContext.txPolicy, e, ThreadContext.getThreadContext());
} else {
//
// Application Exception ***********************
handleApplicationException(mdbCallContext.txPolicy, e, false);
}
}
throw new AssertionError("Should not get here");
}
use of org.apache.openejb.core.ExceptionType in project tomee by apache.
the class ManagedContainer 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);
EjbTransactionUtil.handleSystemException(txPolicy, e, callContext);
} else {
EjbTransactionUtil.handleApplicationException(txPolicy, e, type == ExceptionType.APPLICATION_ROLLBACK);
}
}
use of org.apache.openejb.core.ExceptionType in project tomee by apache.
the class BeanContext method getExceptionType.
public ExceptionType getExceptionType(final Throwable e) {
// Errors are always system exceptions
if (!(e instanceof Exception)) {
return ExceptionType.SYSTEM;
}
// check the registered app exceptions
Class<?> exceptionClass = e.getClass();
boolean inherited = false;
while (exceptionClass != Object.class) {
final ExceptionType type = exceptions.get(exceptionClass);
if (type == ExceptionType.APPLICATION || type == ExceptionType.APPLICATION_ROLLBACK) {
return type;
}
if (type != null) {
if (inherited) {
return ExceptionType.SYSTEM;
}
if (type == ExceptionType.APPLICATION_NOT_INHERITED) {
return ExceptionType.APPLICATION;
}
return ExceptionType.APPLICATION_ROLLBACK;
}
exceptionClass = exceptionClass.getSuperclass();
inherited = true;
}
// Unregistered - runtime exceptions are system exception and the rest are application exceptions
final Class<? extends Throwable> eClass = e.getClass();
final ApplicationException applicationException = eClass.getAnnotation(ApplicationException.class);
if (applicationException != null) {
addApplicationException(eClass, applicationException.rollback(), applicationException.inherited());
return getExceptionType(e);
}
if (e instanceof RuntimeException) {
return ExceptionType.SYSTEM;
}
return ExceptionType.APPLICATION;
}
use of org.apache.openejb.core.ExceptionType in project tomee by apache.
the class CmpContainer method createEJBObject.
private ProxyInfo createEJBObject(final Method callMethod, 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 primaryKey = null;
try {
// Obtain a bean instance from the method ready pool
bean = createNewInstance(callContext);
// set the entity context
setEntityContext(bean);
// Obtain the proper ejbCreate() method
final Method ejbCreateMethod = beanContext.getMatchingBeanMethod(callMethod);
// Set current operation for allowed operations
callContext.setCurrentOperation(Operation.CREATE);
// Invoke the proper ejbCreate() method on the instance
ejbCreateMethod.invoke(bean, args);
// create the new bean
primaryKey = cmpEngine.createBean(bean, callContext);
// determine post create callback method
final Method ejbPostCreateMethod = beanContext.getMatchingPostCreateMethod(ejbCreateMethod);
// create a new context containing the pk for the post create call
final ThreadContext postCreateContext = new ThreadContext(beanContext, primaryKey);
postCreateContext.setCurrentOperation(Operation.POST_CREATE);
final ThreadContext oldContext = ThreadContext.enter(postCreateContext);
try {
// Invoke the ejbPostCreate method on the bean instance
ejbPostCreateMethod.invoke(bean, args);
// According to section 9.1.5.1 of the EJB 1.1 specification, the "ejbPostCreate(...)
// method executes in the same transaction context as the previous ejbCreate(...) method."
//
// The bean is first insterted using db.create( ) and then after ejbPostCreate( ) its
// updated using db.update(). This protocol allows for visablity of the bean after ejbCreate
// within the current trasnaction.
} finally {
ThreadContext.exit(oldContext);
}
// when there is not transaction, merge the data from the bean back into the cmp engine
cmpEngine.storeBeanIfNoTx(callContext, bean);
} 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 {
afterInvoke(txPolicy, callContext);
}
return new ProxyInfo(beanContext, primaryKey);
}
use of org.apache.openejb.core.ExceptionType in project tomee by apache.
the class CmpContainer method homeMethod.
private Object homeMethod(final Method callMethod, 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;
try {
/*
Obtain a bean instance from the method ready pool
*/
bean = createNewInstance(callContext);
// set the entity context
setEntityContext(bean);
try {
callContext.setCurrentOperation(Operation.HOME);
final Method runMethod = beanContext.getMatchingBeanMethod(callMethod);
try {
returnValue = runMethod.invoke(bean, args);
} catch (final IllegalArgumentException e) {
System.out.println("********************************************************");
System.out.println("callMethod = " + callMethod);
System.out.println("runMethod = " + runMethod);
System.out.println("bean = " + bean.getClass().getName());
throw e;
}
} finally {
unsetEntityContext(bean);
}
} 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 {
afterInvoke(txPolicy, callContext);
}
return returnValue;
}
Aggregations