use of javax.resource.ResourceException in project tomee by apache.
the class MdbContainer method deploy.
public void deploy(final BeanContext beanContext) throws OpenEJBException {
final Object deploymentId = beanContext.getDeploymentID();
if (!beanContext.getMdbInterface().equals(messageListenerInterface)) {
throw new OpenEJBException("Deployment '" + deploymentId + "' has message listener interface " + beanContext.getMdbInterface().getName() + " but this MDB container only supports " + messageListenerInterface);
}
// create the activation spec
final ActivationSpec activationSpec = createActivationSpec(beanContext);
if (inboundRecovery != null) {
inboundRecovery.recover(resourceAdapter, activationSpec, containerID.toString());
}
final Options options = new Options(beanContext.getProperties());
final int instanceLimit = options.get("InstanceLimit", this.instanceLimit);
// create the message endpoint
final MdbInstanceFactory instanceFactory = new MdbInstanceFactory(beanContext, securityService, instanceLimit);
final EndpointFactory endpointFactory = new EndpointFactory(activationSpec, this, beanContext, instanceFactory, xaResourceWrapper);
// update the data structures
// this must be done before activating the endpoint since the ra may immedately begin delivering messages
beanContext.setContainer(this);
beanContext.setContainerData(endpointFactory);
deployments.put(deploymentId, beanContext);
// Create stats interceptor
if (StatsInterceptor.isStatsActivated()) {
final StatsInterceptor stats = new StatsInterceptor(beanContext.getBeanClass());
beanContext.addFirstSystemInterceptor(stats);
final MBeanServer server = LocalMBeanServer.get();
final ObjectNameBuilder jmxName = new ObjectNameBuilder("openejb.management");
jmxName.set("J2EEServer", "openejb");
jmxName.set("J2EEApplication", null);
jmxName.set("EJBModule", beanContext.getModuleID());
jmxName.set("StatelessSessionBean", beanContext.getEjbName());
jmxName.set("j2eeType", "");
jmxName.set("name", beanContext.getEjbName());
// register the invocation stats interceptor
try {
final ObjectName objectName = jmxName.set("j2eeType", "Invocations").build();
if (server.isRegistered(objectName)) {
server.unregisterMBean(objectName);
}
server.registerMBean(new ManagedMBean(stats), objectName);
endpointFactory.jmxNames.add(objectName);
} catch (final Exception e) {
logger.error("Unable to register MBean ", e);
}
}
// activate the endpoint
CURRENT.set(beanContext);
try {
resourceAdapter.endpointActivation(endpointFactory, activationSpec);
} catch (final ResourceException e) {
// activation failed... clean up
beanContext.setContainer(null);
beanContext.setContainerData(null);
deployments.remove(deploymentId);
throw new OpenEJBException(e);
} finally {
CURRENT.remove();
}
}
use of javax.resource.ResourceException in project wildfly by wildfly.
the class LazyAssociationSharableFalseTestCase method verifyDisabledLazyAssociation.
@Test
public void verifyDisabledLazyAssociation() {
assertNotNull(lcf);
LazyConnection lc1 = null;
LazyConnection lc2 = null;
try {
lc1 = lcf.getConnection();
assertTrue(lc1.isManagedConnectionSet());
try {
lc2 = lcf.getConnection();
fail("Exception should have been thrown");
} catch (ResourceException re) {
// expected
}
} catch (Throwable t) {
logger.error(t.getMessage(), t);
fail("Throwable:" + t.getLocalizedMessage());
} finally {
if (lc1 != null) {
lc1.close();
}
if (lc2 != null) {
lc2.close();
}
}
}
use of javax.resource.ResourceException in project geode by apache.
the class JCALocalTransaction method begin.
@Override
public void begin() throws ResourceException {
try {
if (!this.initDone || this.cache.isClosed()) {
this.init();
}
LogWriter logger = this.cache.getLogger();
if (logger.fineEnabled()) {
logger.fine("JCALocalTransaction::begin:");
}
TransactionManager tm = this.cache.getJTATransactionManager();
if (this.tid != null) {
throw new LocalTransactionException(" A transaction is already in progress");
}
if (tm != null && tm.getTransaction() != null) {
if (logger.fineEnabled()) {
logger.fine("JCAManagedConnection: JTA transaction is on");
}
// This is having a JTA transaction. Assuming ignore jta flag is true,
// explicitly being a gemfire transaction.
TXStateProxy tsp = this.gfTxMgr.getTXState();
if (tsp == null) {
this.gfTxMgr.begin();
tsp = this.gfTxMgr.getTXState();
tsp.setJCATransaction();
this.tid = tsp.getTransactionId();
if (logger.fineEnabled()) {
logger.fine("JCALocalTransaction:begun GFE transaction");
}
} else {
throw new LocalTransactionException("GemFire is already associated with a transaction");
}
} else {
if (logger.fineEnabled()) {
logger.fine("JCAManagedConnection: JTA Transaction does not exist.");
}
}
} catch (SystemException e) {
throw new ResourceException(e);
}
}
use of javax.resource.ResourceException in project geode by apache.
the class FacetsJCAConnectionManagerImpl method allocateConnection.
/*
* allocates a ManagedConnection from the ConnectionPool or creates a new
* ManagedConnection. @param javax.resource.spi.ManagedConnectionFactory
*
* @param javax.resource.spi.ConnectionRequestInfo
*
* @throws ResourceException
*/
public Object allocateConnection(ManagedConnectionFactory mcf, ConnectionRequestInfo reqInfo) throws ResourceException {
if (!isActive) {
throw new ResourceException(LocalizedStrings.FacetsJCAConnectionManagerImpl_FACETSJCACONNECTIONMANAGERIMPLALLOCATECONNECTIONNO_VALID_CONNECTION_AVAILABLE.toLocalizedString());
}
ManagedConnection conn = null;
try {
conn = (ManagedConnection) mannPoolCache.getPooledConnectionFromPool();
} catch (PoolException ex) {
ex.printStackTrace();
throw new ResourceException(LocalizedStrings.FacetsJCAConnectionManagerImpl_FACETSJCACONNECTIONMANAGERIMPL_ALLOCATECONNECTION_IN_GETTING_CONNECTION_FROM_POOL_DUE_TO_0.toLocalizedString(ex.getMessage()), ex);
}
// Transaction Manager.
try {
synchronized (this) {
if (transManager == null) {
transManager = JNDIInvoker.getTransactionManager();
}
}
Transaction txn = transManager.getTransaction();
if (txn != null) {
// Check if Data Source provides XATransaction
// if(configs.getTransactionType = "XATransaction")
XAResource xar = conn.getXAResource();
txn.enlistResource(xar);
java.util.List resList = (List) xalistThreadLocal.get();
if (resList.size() == 0) {
// facets specific implementation
// register syschronisation only once
txn.registerSynchronization(this);
}
resList.add(conn);
// xalistThreadLocal.set(resList);
// Asif :Add in the Map after successful registration of XAResource
// xaResourcesMap.put(conn, xar);
// else throw a resource exception
}
} catch (RollbackException ex) {
String exception = LocalizedStrings.FacetsJCAConnectionManagerImpl_FACETSJCACONNECTIONMANAGERIMPL_AN_EXCEPTION_WAS_CAUGHT_WHILE_ALLOCATING_A_CONNECTION_DUE_TO_0.toLocalizedString(ex.getMessage());
throw new ResourceException(exception, ex);
} catch (SystemException ex) {
throw new ResourceException(LocalizedStrings.FacetsJCAConnectionManagerImpl_FACETSJCACONNECTIONMANAGERIMPL_ALLOCATECONNECTION_SYSTEM_EXCEPTION_DUE_TO_0.toLocalizedString(ex.getMessage()), ex);
}
return conn.getConnection(subject, reqInfo);
}
use of javax.resource.ResourceException in project jackrabbit by apache.
the class JCAManagedConnectionFactory method createRepository.
/**
* Create/startup the repository.
*/
@SuppressWarnings("deprecation")
private void createRepository() throws ResourceException {
if (repository == null) {
try {
JCARepositoryManager mgr = JCARepositoryManager.getInstance();
repository = mgr.createRepository(parameters);
log("Created repository (" + repository + ")");
} catch (RepositoryException e) {
log("Failed to create repository", e);
ResourceException exception = new ResourceException("Failed to create repository: " + e.getMessage());
exception.setLinkedException(e);
throw exception;
}
}
}
Aggregations