Search in sources :

Example 1 with InvocationException

use of org.glassfish.api.invocation.InvocationException in project Payara by payara.

the class ResourceManagerImpl method unregisterResource.

/**
 * Unregister the <code>ResourceHandle</code> from the transaction
 *
 * @param resource	<code>ResourceHandle</code> object
 * @param xaresFlag flag indicating transaction success. This can
 *        be XAResource.TMSUCCESS or XAResource.TMFAIL
 * @exception <code>PoolingException</code>
 */
public void unregisterResource(ResourceHandle resource, int xaresFlag) {
    JavaEETransactionManager tm = ConnectorRuntime.getRuntime().getTransactionManager();
    Transaction tran = null;
    try {
        // delist with TMSUCCESS if necessary
        if (resource.isTransactional()) {
            InvocationManager invmgr = ConnectorRuntime.getRuntime().getInvocationManager();
            ComponentInvocation inv = invmgr.getCurrentInvocation();
            if (inv == null) {
                // in that, you return the transaction from the TxManager
                try {
                    tran = tm.getTransaction();
                } catch (Exception e) {
                    tran = null;
                    _logger.log(Level.INFO, e.getMessage());
                }
            } else {
                tran = (Transaction) inv.getTransaction();
                tm.unregisterComponentResource(resource);
            }
            if (tran != null && resource.isEnlisted()) {
                tm.delistResource(tran, resource, xaresFlag);
            }
        }
    } catch (SystemException ex) {
        _logger.log(Level.WARNING, "poolmgr.system_exception", ex);
    } catch (IllegalStateException ex) {
    // transaction aborted. Do nothing
    } catch (InvocationException ex) {
    // unregisterResource is called outside of component context
    // likely to be container-forced destroy. Do nothing
    }
}
Also used : ComponentInvocation(org.glassfish.api.invocation.ComponentInvocation) InvocationException(org.glassfish.api.invocation.InvocationException) InvocationManager(org.glassfish.api.invocation.InvocationManager) JavaEETransactionManager(com.sun.enterprise.transaction.api.JavaEETransactionManager) InvocationException(org.glassfish.api.invocation.InvocationException) PoolingException(com.sun.appserv.connectors.internal.api.PoolingException)

Example 2 with InvocationException

use of org.glassfish.api.invocation.InvocationException in project Payara by payara.

the class JavaEETransactionManagerSimplified method delistComponentResources.

private void delistComponentResources(ComponentInvocation inv, boolean suspend) throws InvocationException {
    try {
        Transaction tran = (Transaction) inv.getTransaction();
        if (isTransactionActive(tran)) {
            List l = getExistingResourceList(inv.getInstance(), inv);
            if (l == null || l.size() == 0)
                return;
            int flag = (suspend) ? XAResource.TMSUSPEND : XAResource.TMSUCCESS;
            Iterator it = l.iterator();
            while (it.hasNext()) {
                TransactionalResource h = (TransactionalResource) it.next();
                try {
                    if (h.isEnlisted()) {
                        delistResource(tran, h, flag);
                    }
                } catch (IllegalStateException ex) {
                    if (_logger.isLoggable(Level.FINE))
                        _logger.log(Level.FINE, "TM: Exception in delistResource", ex);
                // ignore error due to tx time out
                } catch (Exception ex) {
                    if (_logger.isLoggable(Level.FINE))
                        _logger.log(Level.FINE, "TM: Exception in delistResource", ex);
                    it.remove();
                    handleResourceError(h, ex, tran);
                }
            }
        // END OF IASRI 4658504
        }
    } catch (Exception ex) {
        _logger.log(Level.SEVERE, "enterprise_distributedtx.excep_in_delist", ex);
    }
}
Also used : JavaEETransaction(com.sun.enterprise.transaction.api.JavaEETransaction) TransactionalResource(com.sun.enterprise.transaction.spi.TransactionalResource) PluginPoint(org.glassfish.external.probe.provider.PluginPoint) InvocationException(org.glassfish.api.invocation.InvocationException) WorkException(javax.resource.spi.work.WorkException) RemoteException(java.rmi.RemoteException) XAException(javax.transaction.xa.XAException)

Example 3 with InvocationException

use of org.glassfish.api.invocation.InvocationException in project Payara by payara.

the class JavaEETransactionManagerSimplified method enlistComponentResources.

public void enlistComponentResources() throws RemoteException {
    if (_logger.isLoggable(Level.FINE))
        _logger.log(Level.FINE, "TM: enlistComponentResources");
    ComponentInvocation inv = invMgr.getCurrentInvocation();
    if (inv == null)
        return;
    try {
        Transaction tran = getTransaction();
        inv.setTransaction((JavaEETransaction) tran);
        enlistComponentResources(inv);
    } catch (InvocationException ex) {
        _logger.log(Level.SEVERE, "enterprise_distributedtx.excep_in_enlist", ex);
        throw new RemoteException(ex.getMessage(), ex.getNestedException());
    } catch (Exception ex) {
        _logger.log(Level.SEVERE, "enterprise_distributedtx.excep_in_enlist", ex);
        throw new RemoteException(ex.getMessage(), ex);
    }
}
Also used : JavaEETransaction(com.sun.enterprise.transaction.api.JavaEETransaction) ComponentInvocation(org.glassfish.api.invocation.ComponentInvocation) InvocationException(org.glassfish.api.invocation.InvocationException) RemoteException(java.rmi.RemoteException) InvocationException(org.glassfish.api.invocation.InvocationException) WorkException(javax.resource.spi.work.WorkException) RemoteException(java.rmi.RemoteException) XAException(javax.transaction.xa.XAException)

Example 4 with InvocationException

use of org.glassfish.api.invocation.InvocationException in project Payara by payara.

the class EJBSecurityManager method getCallerPrincipal.

/**
 * This method returns the Client Principal who initiated the current
 * Invocation.
 *
 * @return A Principal object of the client who made this invocation.
 *         or null if the SecurityContext has not been established by the client.
 */
public Principal getCallerPrincipal() {
    SecurityContext sc = null;
    if (runAs != null) {
        // Run As
        // return the principal associated with the old security context
        ComponentInvocation ci = invMgr.getCurrentInvocation();
        if (ci == null) {
            // 4646060
            throw new InvocationException();
        }
        sc = (SecurityContext) ci.getOldSecurityContext();
    } else {
        // lets optimize a little. no need to look up oldsecctx
        // its the same as the new one
        sc = SecurityContext.getCurrent();
    }
    Principal prin;
    if (sc != null) {
        prin = sc.getCallerPrincipal();
    } else {
        prin = SecurityContext.getDefaultCallerPrincipal();
    }
    return prin;
}
Also used : ComponentInvocation(org.glassfish.api.invocation.ComponentInvocation) InvocationException(org.glassfish.api.invocation.InvocationException) SecurityContext(com.sun.enterprise.security.SecurityContext) Principal(java.security.Principal)

Example 5 with InvocationException

use of org.glassfish.api.invocation.InvocationException in project Payara by payara.

the class PoolManagerImpl method handleLazilyAssociatedConnectionPools.

/**
 * If the connections associated with the component are lazily-associatable, dissociate them.
 * @param comp Component that acquired connections
 * @param invToUse component invocation
 */
private void handleLazilyAssociatedConnectionPools(Object comp, ComponentInvocation invToUse) {
    JavaEETransactionManager tm = getConnectorRuntime().getTransactionManager();
    List list = tm.getExistingResourceList(comp, invToUse);
    if (list == null) {
        // have any resources and hence the existingResourcesList is null
        return;
    }
    if (list.isEmpty())
        return;
    ResourceHandle[] handles = new ResourceHandle[list.size()];
    handles = (ResourceHandle[]) list.toArray(handles);
    for (ResourceHandle h : handles) {
        if (h == null) {
            _logger.log(Level.WARNING, "lazy_association.lazy_association_resource_handle");
            continue;
        }
        ResourceSpec spec = h.getResourceSpec();
        if (spec == null) {
            _logger.log(Level.WARNING, "lazy_association.lazy_association_resource_spec");
            continue;
        }
        if (spec.isLazyAssociatable()) {
            // of type DissociatableManagedConnection
            if (h.getResource() != null) {
                javax.resource.spi.DissociatableManagedConnection mc = (javax.resource.spi.DissociatableManagedConnection) h.getResource();
                if (h.isEnlisted()) {
                    getResourceManager(spec).delistResource(h, XAResource.TMSUCCESS);
                }
                try {
                    mc.dissociateConnections();
                } catch (ResourceException re) {
                    InvocationException ie = new InvocationException(re.getMessage());
                    ie.initCause(re);
                    throw ie;
                } finally {
                    if (h.getResourceState().isBusy()) {
                        putbackDirectToPool(h, spec.getPoolInfo());
                    }
                }
            } else {
                _logger.log(Level.WARNING, "lazy_association.lazy_association_resource");
            }
        }
    }
}
Also used : InvocationException(org.glassfish.api.invocation.InvocationException) ResourceHandle(com.sun.enterprise.resource.ResourceHandle) ResourceSpec(com.sun.enterprise.resource.ResourceSpec) JavaEETransactionManager(com.sun.enterprise.transaction.api.JavaEETransactionManager) ResourceException(javax.resource.ResourceException)

Aggregations

InvocationException (org.glassfish.api.invocation.InvocationException)7 ComponentInvocation (org.glassfish.api.invocation.ComponentInvocation)4 JavaEETransaction (com.sun.enterprise.transaction.api.JavaEETransaction)3 RemoteException (java.rmi.RemoteException)3 WorkException (javax.resource.spi.work.WorkException)3 XAException (javax.transaction.xa.XAException)3 JavaEETransactionManager (com.sun.enterprise.transaction.api.JavaEETransactionManager)2 TransactionalResource (com.sun.enterprise.transaction.spi.TransactionalResource)2 InvocationManager (org.glassfish.api.invocation.InvocationManager)2 PoolingException (com.sun.appserv.connectors.internal.api.PoolingException)1 NamingObjectFactory (com.sun.enterprise.naming.spi.NamingObjectFactory)1 ResourceHandle (com.sun.enterprise.resource.ResourceHandle)1 ResourceSpec (com.sun.enterprise.resource.ResourceSpec)1 SecurityContext (com.sun.enterprise.security.SecurityContext)1 Principal (java.security.Principal)1 ArrayList (java.util.ArrayList)1 Context (javax.naming.Context)1 InitialContext (javax.naming.InitialContext)1 NamingException (javax.naming.NamingException)1 ResourceException (javax.resource.ResourceException)1