@Override
public Object processInvocation(InterceptorContext context) throws Exception {
final EJBComponent component = getComponent(context, EJBComponent.class);
// create the instance
final ComponentInstance componentInstance = component.createInstance();
context.putPrivateData(ComponentInstance.class, componentInstance);
//if this is set to true we do not invoke instance.destroy
//as we are not allowed to invoke pre-destroy callbacks
boolean discard = false;
try {
return context.proceed();
} catch (Exception ex) {
final EJBComponent ejbComponent = component;
// Detect app exception
if (ejbComponent.getApplicationException(ex.getClass(), context.getMethod()) != null) {
// it's an application exception, just throw it back.
throw ex;
}
if (ex instanceof ConcurrentAccessTimeoutException || ex instanceof ConcurrentAccessException) {
throw ex;
}
if (ex instanceof RuntimeException || ex instanceof RemoteException) {
discard = true;
}
throw ex;
} catch (final Error e) {
discard = true;
throw e;
} catch (final Throwable t) {
discard = true;
throw new RuntimeException(t);
} finally {
context.putPrivateData(ComponentInstance.class, null);
// destroy the instance
if (!discard) {
componentInstance.destroy();
}
}
}