use of javax.transaction.SystemException in project wildfly by wildfly.
the class TestEJBRunnable method run.
@Override
public void run() {
// asserts correct class loader is set
try {
Thread.currentThread().getContextClassLoader().loadClass(this.getClass().getName());
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
// asserts correct naming context is set
final InitialContext initialContext;
try {
initialContext = new InitialContext();
} catch (NamingException e) {
throw new RuntimeException(e);
}
final EJBContext ejbContext;
try {
ejbContext = (SessionContext) initialContext.lookup("java:comp/EJBContext");
} catch (NamingException e) {
throw new RuntimeException(e);
}
// asserts correct security context is set
final Principal callerPrincipal = ejbContext.getCallerPrincipal();
if (expectedPrincipal != null) {
if (!expectedPrincipal.equals(callerPrincipal)) {
throw new IllegalStateException("the caller principal " + callerPrincipal + " is not the expected " + expectedPrincipal);
}
} else {
if (callerPrincipal != null) {
throw new IllegalStateException("the caller principal " + callerPrincipal + " is not the expected " + expectedPrincipal);
}
}
// assert tx context is set
try {
final UserTransaction userTransaction = (UserTransaction) initialContext.lookup("java:comp/UserTransaction");
userTransaction.begin();
userTransaction.rollback();
} catch (NamingException | SystemException | NotSupportedException e) {
throw new RuntimeException(e);
}
}
use of javax.transaction.SystemException in project wildfly by wildfly.
the class BMTStateful method createTransaction.
public void createTransaction() {
try {
final UserTransaction userTransaction = ejbContext.getUserTransaction();
Assert.assertEquals(Status.STATUS_NO_TRANSACTION, userTransaction.getStatus());
userTransaction.begin();
} catch (SystemException e) {
throw new RuntimeException(e);
} catch (NotSupportedException e) {
throw new RuntimeException(e);
}
}
use of javax.transaction.SystemException in project wildfly by wildfly.
the class BMTStateful method rollbackTransaction.
public void rollbackTransaction() {
try {
final UserTransaction userTransaction = ejbContext.getUserTransaction();
Assert.assertEquals(Status.STATUS_ACTIVE, userTransaction.getStatus());
userTransaction.rollback();
} catch (SystemException e) {
throw new RuntimeException(e);
}
}
use of javax.transaction.SystemException in project wildfly by wildfly.
the class JBossContextXATerminator method startWork.
/**
* <p>
* Start work gets imported transaction and assign it to current thread.
* <p>
* This method mimics behavior of Narayana's {@link JBossXATerminator}.
*/
@Override
public void startWork(Work work, Xid xid) throws WorkCompletedException {
LocalTransaction transaction = null;
try {
ImportResult<LocalTransaction> transactionImportResult = localTransactionContext.findOrImportTransaction(xid, 0);
transaction = transactionImportResult.getTransaction();
ContextTransactionManager.getInstance().resume(transaction);
} catch (XAException xae) {
throw TransactionLogger.ROOT_LOGGER.cannotFindOrImportInflowTransaction(xid, work, xae);
} catch (InvalidTransactionException ite) {
throw TransactionLogger.ROOT_LOGGER.importedInflowTransactionIsInactive(xid, work, ite);
} catch (SystemException se) {
throw TransactionLogger.ROOT_LOGGER.cannotResumeInflowTransactionUnexpectedError(transaction, work, se);
}
}
use of javax.transaction.SystemException in project wildfly by wildfly.
the class TransactionSynchronizationRegistryWrapper method registerInterposedSynchronization.
@Override
public void registerInterposedSynchronization(Synchronization sync) throws IllegalStateException {
try {
Transaction tx = transactionManager.getTransaction();
JCAOrderedLastSynchronizationList jcaOrderedLastSynchronization = interposedSyncs.get(tx);
if (jcaOrderedLastSynchronization == null) {
JCAOrderedLastSynchronizationList toPut = new JCAOrderedLastSynchronizationList((com.arjuna.ats.jta.transaction.Transaction) tx, interposedSyncs);
jcaOrderedLastSynchronization = interposedSyncs.putIfAbsent(tx, toPut);
if (jcaOrderedLastSynchronization == null) {
jcaOrderedLastSynchronization = toPut;
delegate.registerInterposedSynchronization(jcaOrderedLastSynchronization);
}
}
jcaOrderedLastSynchronization.registerInterposedSynchronization(sync);
} catch (SystemException e) {
throw new IllegalStateException(e);
}
}
Aggregations