try {
// set up java:comp JNDI Context
RootContext.setComponentContext(componentContext);
TransactionContext oldTransactionContext = transactionContextManager.getContext();
TransactionContext newTransactionContext = null;
if (oldTransactionContext == null || !(oldTransactionContext instanceof InheritableTransactionContext)) {
newTransactionContext = transactionContextManager.newUnspecifiedTransactionContext();
}
try {
try {
oldInstanceContext = trackedConnectionAssociator.enter(new DefaultInstanceContext(unshareableResources, applicationManagedSecurityResources));
} catch (ResourceException e) {
throw new RuntimeException(e);
}
super.handle(pathInContext, pathParams, httpRequest, httpResponse);
} finally {
try {
if (newTransactionContext != null) {
if (newTransactionContext != transactionContextManager.getContext()) {
transactionContextManager.getContext().rollback();
newTransactionContext.rollback();
throw new HttpException(500, "WRONG EXCEPTION! returned from servlet call with wrong tx context");
}
newTransactionContext.commit();
} else {
if (oldTransactionContext != transactionContextManager.getContext()) {
if (transactionContextManager.getContext() != null) {
transactionContextManager.getContext().rollback();