use of javax.ejb.EJBException in project Payara by payara.
the class SafeProperties method postInvoke.
protected void postInvoke(EjbInvocation inv, boolean doTxProcessing) {
if (containerState != CONTAINER_STARTED) {
throw new EJBException(localStrings.getLocalString("ejb.container_not_started", "Attempt to invoke when container is in {0}", containerStateToString(containerState)));
}
inv.setDoTxProcessingInPostInvoke(doTxProcessing);
if (inv.mustInvokeAsynchronously()) {
EjbAsyncInvocationManager asyncManager = ((EjbContainerUtilImpl) ejbContainerUtilImpl).getEjbAsyncInvocationManager();
asyncManager.submit(inv);
return;
}
if (inv.ejb != null) {
// counterpart of invocationManager.preInvoke
if (!inv.useFastPath) {
invocationManager.postInvoke(inv);
delistExtendedEntityManagers(inv.context);
} else {
doTxProcessing = doTxProcessing && (inv.exception != null);
}
try {
if (doTxProcessing) {
postInvokeTx(inv);
}
} catch (Exception ex) {
_logger.log(Level.FINE, "Exception occurred in postInvokeTx : [{0}]", ex);
if (ex instanceof EJBException)
inv.exception = (EJBException) ex;
else
inv.exception = new EJBException(ex);
}
releaseContext(inv);
}
if (inv.exception != null) {
// Unwrap the PreInvokeException if necessary
if (inv.exception instanceof PreInvokeException) {
inv.exception = ((PreInvokeException) inv.exception).exception;
}
if (isSystemUncheckedException(inv.exception)) {
_logger.log(Level.WARNING, SYSTEM_EXCEPTION, new Object[] { ejbDescriptor.getName(), inv.beanMethod });
_logger.log(Level.WARNING, "", inv.exception);
} else {
_logger.log(Level.FINE, "An application exception occurred during an invocation on EJB {0}, method: {1}", new Object[] { ejbDescriptor.getName(), inv.beanMethod });
_logger.log(Level.FINE, "", inv.exception);
}
if (inv.isRemote) {
if (protocolMgr != null) {
// For remote business case, exception mapping is performed
// in client wrapper.
// TODO need extra logic to handle implementation-specific ejb exceptions
// (ParallelAccessEXCeption etc. that used to be handled by iiop glue code
inv.exception = mapRemoteException(inv);
}
// The most useful portion of the system exception is logged
// above. Only log mapped form when log level is FINE or
// higher.
_logger.log(Level.FINE, "", inv.exception);
} else {
if (inv.isBusinessInterface) {
inv.exception = mapLocal3xException(inv.exception);
}
}
}
if (_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE, "Leaving BaseContainer::postInvoke : " + inv);
}
}
use of javax.ejb.EJBException in project Payara by payara.
the class EJBContainerTransactionManager method processSystemException.
private Throwable processSystemException(Throwable sysEx) {
Throwable newException;
if (sysEx instanceof EJBException)
return sysEx;
// EJB2.0 section 18.3.4
if (sysEx instanceof NoSuchEntityException) {
// for EntityBeans only
newException = new NoSuchObjectLocalException("NoSuchEntityException thrown by EJB method.");
newException.initCause(sysEx);
} else {
newException = new EJBException();
newException.initCause(sysEx);
}
return newException;
}
use of javax.ejb.EJBException in project Payara by payara.
the class EJBContainerTransactionManager method preInvokeTx.
/**
* Handle transaction requirements, if any, before invoking bean method
*/
final void preInvokeTx(EjbInvocation inv) throws Exception {
// Get existing Tx status: this tells us if the client
// started a transaction which was propagated on this invocation.
Integer preInvokeTxStatus = inv.getPreInvokeTxStatus();
int status = (preInvokeTxStatus != null) ? preInvokeTxStatus.intValue() : transactionManager.getStatus();
// For EntityBeans, ejbCreate/ejbRemove/ejbFind must be called with a Tx so no special work needed.
if (container.suspendTransaction(inv)) {
if (status != Status.STATUS_NO_TRANSACTION) {
// client request is associated with a Tx
try {
inv.clientTx = transactionManager.suspend();
} catch (SystemException ex) {
throw new EJBException(ex);
}
}
return;
}
// isNullTx is true if the client sent a null tx context
// (i.e. a tx context with a null Coordinator objref)
// or if this server's tx interop mode flag is false.
// Follow the tables in EJB2.0 sections 19.6.2.2.1 and 19.6.2.2.2.
boolean isNullTx = false;
if (inv.isRemote) {
isNullTx = transactionManager.isNullTransaction();
}
int txAttr = container.getTxAttr(inv);
EJBContextImpl context = (EJBContextImpl) inv.context;
// Note: in the code below, inv.clientTx is set ONLY if the
// client's Tx is actually suspended.
// get the Tx associated with the EJB from previous invocation,
// if any.
Transaction prevTx = context.getTransaction();
switch(txAttr) {
case Container.TX_BEAN_MANAGED:
// Note: only MDBs and SessionBeans can be TX_BEAN_MANAGED
if (status != Status.STATUS_NO_TRANSACTION) {
// client request associated with a Tx, always suspend
inv.clientTx = transactionManager.suspend();
}
if (container.isStatefulSession && prevTx != null && prevTx.getStatus() != Status.STATUS_NO_TRANSACTION) {
// Note: if prevTx != null , then it means
// afterCompletion was not called yet for the
// previous transaction on the EJB.
// The EJB was previously associated with a Tx which was
// begun by the EJB itself in a previous invocation.
// This is only possible for stateful SessionBeans
// not for StatelessSession or Entity.
transactionManager.resume(prevTx);
// This allows the TM to enlist resources
// used by the EJB with the transaction
transactionManager.enlistComponentResources();
}
break;
case Container.TX_NOT_SUPPORTED:
if (status != Status.STATUS_NO_TRANSACTION) {
inv.clientTx = transactionManager.suspend();
}
container.checkUnfinishedTx(prevTx, inv);
container.preInvokeNoTx(inv);
break;
case Container.TX_MANDATORY:
if (isNullTx || status == Status.STATUS_NO_TRANSACTION) {
throw new TransactionRequiredLocalException();
}
useClientTx(prevTx, inv);
break;
case Container.TX_REQUIRED:
if (isNullTx) {
throw new TransactionRequiredLocalException();
}
if (status == Status.STATUS_NO_TRANSACTION) {
inv.clientTx = null;
startNewTx(prevTx, inv);
} else {
// There is a client Tx
inv.clientTx = transactionManager.getTransaction();
useClientTx(prevTx, inv);
}
break;
case Container.TX_REQUIRES_NEW:
if (status != Status.STATUS_NO_TRANSACTION) {
inv.clientTx = transactionManager.suspend();
}
startNewTx(prevTx, inv);
break;
case Container.TX_SUPPORTS:
if (isNullTx) {
throw new TransactionRequiredLocalException();
}
if (status != Status.STATUS_NO_TRANSACTION) {
useClientTx(prevTx, inv);
} else {
// we need to invoke the EJB with no Tx.
container.checkUnfinishedTx(prevTx, inv);
container.preInvokeNoTx(inv);
}
break;
case Container.TX_NEVER:
if (isNullTx || status != Status.STATUS_NO_TRANSACTION) {
throw new EJBException("EJB cannot be invoked in global transaction");
} else {
// we need to invoke the EJB with no Tx.
container.checkUnfinishedTx(prevTx, inv);
container.preInvokeNoTx(inv);
}
break;
default:
throw new EJBException("Bad transaction attribute");
}
}
use of javax.ejb.EJBException in project Payara by payara.
the class DeploymentElement method getOrCreateApplication.
/**
* Create deployable application from a Set of DeploymentElements.
* @param modules the Set of DeploymentElements.
* @return deployable application.
*/
public static ResultApplication getOrCreateApplication(Set<DeploymentElement> modules, String appName) throws EJBException, IOException {
Object result = null;
boolean deleteOnExit = false;
if (modules == null || modules.size() == 0 || !DeploymentElement.hasEJBModule(modules)) {
_logger.severe("[DeploymentElement] No modules found");
} else if (appName == null && DeploymentElement.countEJBModules(modules) == 1) {
// Use the single component as-is
if (modules.size() == 1) {
// Single EJB module
result = modules.iterator().next().getElement();
} else if (DeploymentElement.countEJBModules(modules) == 1 && DeploymentElement.hasWar(modules)) {
// A WAR file with an EJB
result = DeploymentElement.getWar(modules).getElement();
} else {
// EJB molule with libraries - create ScatteredArchive
ScatteredArchive sa = null;
for (DeploymentElement m : modules) {
if (m.isEJBModule) {
// XXX Work around GLASSFISH-16618
// The name was already calculated when DeploymentElement was created
sa = new ScatteredArchive(m.mname, ScatteredArchive.Type.JAR);
if (_logger.isLoggable(Level.INFO)) {
_logger.info("[DeploymentElement] adding EJB module to ScatteredArchive " + m.mname);
}
sa.addClassPath(m.element);
break;
}
}
if (sa != null) {
for (DeploymentElement m : modules) {
if (!m.isEJBModule) {
if (_logger.isLoggable(Level.INFO)) {
_logger.info("[DeploymentElement] adding library to ScatteredArchive " + m.element.getName());
}
sa.addClassPath(m.element);
}
}
result = sa;
}
}
} else {
// Create an ear if appName is set or if there is more than 1 EJB module
// Create a temp dir by creating a temp file first, then
// delete the file and create a directory in its place.
File resultFile = File.createTempFile("ejb-app", "");
File lib = null;
if (resultFile.delete() && resultFile.mkdirs()) {
if (_logger.isLoggable(Level.FINE)) {
_logger.fine("[DeploymentElement] temp dir created at " + resultFile.getAbsolutePath());
}
// Create lib dir if there are library entries
if (DeploymentElement.hasLibrary(modules)) {
if (_logger.isLoggable(Level.FINE)) {
_logger.fine("[DeploymentElement] lib dir added ... ");
}
lib = new File(resultFile, "lib");
}
} else {
throw new EJBException("Not able to create temp dir " + resultFile.getAbsolutePath());
}
// Copy module directories and explode module jars
int duplicate_dir_counter = 0;
for (DeploymentElement m : modules) {
File f = m.element;
if (_logger.isLoggable(Level.INFO)) {
_logger.info("[DeploymentElement] adding " + f.getName() + " to exploded ear " + " isEJBModule? " + m.isEJBModule + " isWebApp? " + m.isWebApp);
}
String filename = f.toURI().getSchemeSpecificPart();
if (filename.endsWith(File.separator) || filename.endsWith("/")) {
int length = filename.length();
filename = filename.substring(0, length - 1);
}
int lastpart = filename.lastIndexOf(File.separatorChar);
if (lastpart == -1) {
lastpart = filename.lastIndexOf('/');
}
String name = filename.substring(lastpart + 1);
if (_logger.isLoggable(Level.FINE)) {
_logger.fine("[DeploymentElement] Converted file name: " + filename + " to " + name);
}
File base = (m.isEJBModule) ? resultFile : lib;
if (!f.isDirectory() && m.isEJBModule) {
File out = new File(base, FileUtils.makeFriendlyFilename(name));
if (_logger.isLoggable(Level.FINE)) {
_logger.fine("[DeploymentElement] Exploding jar to: " + out);
}
ModuleExploder.explodeJar(f, out);
} else {
if (f.isDirectory()) {
name = name + (m.isWebApp ? "_war" : (m.isEJBModule ? "_jar" : ".jar"));
}
File out = new File(base, name);
if (out.exists()) {
out = new File(base, "d__" + ++duplicate_dir_counter + "__" + name);
}
if (_logger.isLoggable(Level.FINE)) {
_logger.fine("[DeploymentElement] Copying element to: " + out);
}
FileUtils.copy(f, out);
}
}
// Check if the archive should not be deleted at the end
deleteOnExit = !Boolean.getBoolean(EJBContainerProviderImpl.KEEP_TEMPORARY_FILES);
if (appName == null) {
appName = "ejb-app";
}
result = resultFile;
}
return new ResultApplication(result, appName, deleteOnExit);
}
use of javax.ejb.EJBException in project Payara by payara.
the class EJBTimerService method createTimer.
/**
* @param timedObjectPrimaryKey can be null if timed object is not an entity bean.
* @return Primary key of newly created timer
*/
private TimerPrimaryKey createTimer(long containerId, long applicationId, Object timedObjectPrimaryKey, Date initialExpiration, long intervalDuration, EJBTimerSchedule schedule, TimerConfig timerConfig, String server_name) throws CreateException {
BaseContainer container = getContainer(containerId);
boolean startTimers = ownerIdOfThisServer_.equals(server_name);
if (startTimers) {
if (container == null) {
throw new CreateException("invalid container id " + containerId + " in createTimer request");
}
Class ejbClass = container.getEJBClass();
if (!container.isTimedObject()) {
throw new CreateException("Attempt to create an EJB Timer from a bean that is " + "not a Timed Object. EJB class " + ejbClass + " must implement javax.ejb.TimedObject or " + " annotation a timeout method with @Timeout");
}
}
TimerPrimaryKey timerId = new TimerPrimaryKey(getNextTimerId());
if (schedule != null) {
Calendar next = schedule.getNextTimeout();
if (!schedule.isValid(next)) {
initialExpiration = new Date();
} else {
initialExpiration = next.getTime();
}
}
if (logger.isLoggable(Level.FINE)) {
logger.log(Level.FINE, "@@@ Created timer [" + timerId + "] with the first expiration set to: " + initialExpiration);
}
if (timerConfig == null) {
// Easier create one than check everywhere for null...
timerConfig = new TimerConfig();
}
RuntimeTimerState timerState = new RuntimeTimerState(timerId, initialExpiration, intervalDuration, containerId, container, timedObjectPrimaryKey, schedule, timerConfig.getInfo(), timerConfig.isPersistent());
synchronized (timerState) {
// need access to timer cache.
if (startTimers) {
timerCache_.addTimer(timerId, timerState);
}
try {
_createTimer(timerId, containerId, applicationId, timedObjectPrimaryKey, server_name, initialExpiration, intervalDuration, schedule, timerConfig);
} catch (Exception e) {
logger.log(Level.SEVERE, "ejb.create_timer_failure", new Object[] { String.valueOf(containerId), timedObjectPrimaryKey, timerConfig.getInfo() });
logger.log(Level.SEVERE, "", e);
// Since timer was never created, remove it from cache.
timerCache_.removeTimer(timerId);
if (e instanceof CreateException) {
throw ((CreateException) e);
} else {
EJBException ejbEx = new EJBException();
ejbEx.initCause(e);
throw ejbEx;
}
}
}
return timerId;
}
Aggregations