use of org.apache.openejb.SystemException in project tomee by apache.
the class SimplePassivater method activate.
@Override
public Object activate(final Object primaryKey) throws SystemException {
try {
final String filename = primaryKey.toString().replace(':', '=');
final File sessionFile = new File(sessionDirectory, filename);
if (sessionFile.exists()) {
logger.info("Activating from file " + sessionFile);
try (final InputStream source = IO.read(sessionFile);
final ObjectInputStream ois = new ObjectInputStreamFiltered(source)) {
final Object state = ois.readObject();
if (!sessionFile.delete()) {
sessionFile.deleteOnExit();
}
return state;
}
} else {
logger.info("Activation failed: file not found " + sessionFile);
return null;
}
} catch (final Exception t) {
logger.info("Activation failed ", t);
throw new SystemException(t);
}
}
use of org.apache.openejb.SystemException in project tomee by apache.
the class MdbContainer method afterDelivery.
public void afterDelivery(final Object instance) throws SystemException {
// get the mdb call context
final ThreadContext callContext = ThreadContext.getThreadContext();
final MdbCallContext mdbCallContext = callContext.get(MdbCallContext.class);
// invoke the tx after method
try {
afterInvoke(mdbCallContext.txPolicy, callContext);
} catch (final ApplicationException e) {
throw new SystemException("Should never get an Application exception", e);
} finally {
ThreadContext.exit(mdbCallContext.oldCallContext);
}
}
use of org.apache.openejb.SystemException in project tomee by apache.
the class MdbContainer method invoke.
public Object invoke(final Object instance, final Method method, final InterfaceType type, Object... args) throws SystemException, ApplicationException {
if (args == null) {
args = NO_ARGS;
}
// get the context data
final ThreadContext callContext = ThreadContext.getThreadContext();
final BeanContext deployInfo = callContext.getBeanContext();
final MdbCallContext mdbCallContext = callContext.get(MdbCallContext.class);
if (mdbCallContext == null) {
throw new IllegalStateException("beforeDelivery was not called");
}
// verify the delivery method passed to beforeDeliver is the same method that was invoked
if (!mdbCallContext.deliveryMethod.getName().equals(method.getName()) || !Arrays.deepEquals(mdbCallContext.deliveryMethod.getParameterTypes(), method.getParameterTypes())) {
throw new IllegalStateException("Delivery method specified in beforeDelivery is not the delivery method called");
}
// remember the return value or exception so it can be logged
Object returnValue = null;
OpenEJBException openEjbException = null;
final Operation oldOperation = callContext.getCurrentOperation();
callContext.setCurrentOperation(type == InterfaceType.TIMEOUT ? Operation.TIMEOUT : Operation.BUSINESS);
try {
if (logger.isDebugEnabled()) {
logger.info("invoking method " + method.getName() + " on " + deployInfo.getDeploymentID());
}
// determine the target method on the bean instance class
final Method targetMethod = deployInfo.getMatchingBeanMethod(method);
callContext.set(Method.class, targetMethod);
// invoke the target method
returnValue = _invoke(instance, targetMethod, args, deployInfo, type, mdbCallContext);
return returnValue;
} catch (final ApplicationException | SystemException e) {
openEjbException = e;
throw e;
} finally {
callContext.setCurrentOperation(oldOperation);
// Log the invocation results
if (logger.isDebugEnabled()) {
if (openEjbException == null) {
logger.debug("finished invoking method " + method.getName() + ". Return value:" + returnValue);
} else {
final Throwable exception = openEjbException.getRootCause() != null ? openEjbException.getRootCause() : openEjbException;
logger.debug("finished invoking method " + method.getName() + " with exception " + exception);
}
}
}
}
use of org.apache.openejb.SystemException in project tomee by apache.
the class MdbInstanceManager method poolInstance.
/**
* All instances are removed from the pool in getInstance(...). They are only
* returned by the Container via this method under two circumstances.
* <p/>
* 1. The business method returns normally
* 2. The business method throws an application exception
* <p/>
* Instances are not returned to the pool if the business method threw a system
* exception.
*
* @param callContext ThreadContext
* @param bean Object
* @throws OpenEJBException
*/
public void poolInstance(final ThreadContext callContext, final Object bean) throws OpenEJBException {
if (bean == null) {
throw new SystemException("Invalid arguments");
}
final Instance instance = Instance.class.cast(bean);
final BeanContext beanContext = callContext.getBeanContext();
final Data data = (Data) beanContext.getContainerData();
final Pool<Instance> pool = data.getPool();
if (instance.getPoolEntry() != null) {
pool.push(instance.getPoolEntry());
} else {
pool.push(instance);
}
}
use of org.apache.openejb.SystemException in project tomee by apache.
the class PoolEndpointHandler method beforeDelivery.
@Override
public void beforeDelivery(final Method method) throws ApplicationServerInternalException {
// verify current state
switch(state) {
case RELEASED:
throw new IllegalStateException("Message endpoint factory has been released");
case BEFORE_CALLED:
throw new IllegalStateException("beforeDelivery can not be called again until message is delivered and afterDelivery is called");
case METHOD_CALLED:
case SYSTEM_EXCEPTION:
throw new IllegalStateException("The last message delivery must be completed with an afterDeliver before beforeDeliver can be called again");
}
// call beforeDelivery on the container
try {
instance = instanceManager.getInstance(new ThreadContext(deployment, null));
container.beforeDelivery(deployment, instance, method, xaResource);
} catch (final SystemException se) {
final Throwable throwable = se.getRootCause() != null ? se.getRootCause() : se;
throw new ApplicationServerInternalException(throwable);
} catch (OpenEJBException oe) {
throw new ApplicationServerInternalException(oe);
}
// before completed successfully we are now ready to invoke bean
state = State.BEFORE_CALLED;
}
Aggregations