Search in sources :

Example 1 with ResourceSpec

use of com.sun.enterprise.resource.ResourceSpec in project Payara by payara.

the class BasicResourceAllocator method createResource.

public ResourceHandle createResource(XAResource xaResource) throws PoolingException {
    ResourceHandle resourceHandle = null;
    ResourceSpec spec = new ResourceSpec(JMS_RESOURCE_FACTORY, ResourceSpec.JMS);
    if (xaResource != null) {
        logger.logp(Level.FINEST, "BasicResourceAllocator", "createResource", "NOT NULL", xaResource);
        try {
            resourceHandle = new ResourceHandle(// no object present
            null, spec, this, null);
            if (logger.isLoggable(Level.FINEST)) {
                xaResource = new XAResourceWrapper(xaResource);
            }
            resourceHandle.fillInResourceObjects(null, xaResource);
        } catch (Exception e) {
            throw (PoolingException) (new PoolingException()).initCause(e);
        }
    } else {
        logger.logp(Level.FINEST, "BasicResourceAllocator", "createResource", "NULL");
    }
    return resourceHandle;
}
Also used : PoolingException(com.sun.appserv.connectors.internal.api.PoolingException) ResourceHandle(com.sun.enterprise.resource.ResourceHandle) ResourceSpec(com.sun.enterprise.resource.ResourceSpec) XAResourceWrapper(com.sun.enterprise.resource.XAResourceWrapper) PoolingException(com.sun.appserv.connectors.internal.api.PoolingException) ResourceException(javax.resource.ResourceException)

Example 2 with ResourceSpec

use of com.sun.enterprise.resource.ResourceSpec in project Payara by payara.

the class ConnectionManagerImpl method internalGetConnection.

protected Object internalGetConnection(ManagedConnectionFactory mcf, final ResourcePrincipal prin, ConnectionRequestInfo cxRequestInfo, boolean shareable, String jndiNameToUse, Object conn, boolean isUnknownAuth) throws ResourceException {
    try {
        PoolManager poolmgr = ConnectorRuntime.getRuntime().getPoolManager();
        ConnectorRegistry registry = ConnectorRegistry.getInstance();
        PoolMetaData pmd = registry.getPoolMetaData(poolInfo);
        ResourceSpec spec = new ResourceSpec(jndiNameToUse, ResourceSpec.JNDI_NAME, pmd);
        spec.setPoolInfo(this.poolInfo);
        ManagedConnectionFactory freshMCF = pmd.getMCF();
        if (getLogger().isLoggable(Level.INFO)) {
            if (!freshMCF.equals(mcf)) {
                getLogger().info("conmgr.mcf_not_equal");
            }
        }
        ConnectorDescriptor desc = registry.getDescriptor(rarName);
        Subject subject = null;
        ClientSecurityInfo info = null;
        boolean subjectDefined = false;
        if (isUnknownAuth && rarName.equals(ConnectorConstants.DEFAULT_JMS_ADAPTER) && !(pmd.isAuthCredentialsDefinedInPool())) {
            // System.out.println("Unkown Auth - pobably nonACC client");
            // Unknown authorization. This is the case for standalone java clients,
            // where the authorization is neither container nor component
            // managed. In this case we associate an non-null Subject with no
            // credentials, so that the RA can either use its own custom logic
            // for figuring out the credentials. Relevant connector spec section
            // is 9.1.8.2.
            // create non-null Subject associated with no credentials
            // System.out.println("RAR name "+ rarName);
            subject = ConnectionPoolObjectsUtils.createSubject(mcf, null);
        } else {
            if (prin == null) {
                info = new ClientSecurityInfo(cxRequestInfo);
            } else {
                info = new ClientSecurityInfo(prin);
                if (prin.equals(defaultPrin)) {
                    subject = pmd.getSubject();
                } else {
                    subject = ConnectionPoolObjectsUtils.createSubject(mcf, prin);
                }
            }
        }
        int txLevel = pmd.getTransactionSupport();
        if (getLogger().isLoggable(Level.FINE)) {
            logFine("ConnectionMgr: poolName " + poolInfo + "  txLevel : " + txLevel);
        }
        if (conn != null) {
            spec.setConnectionToAssociate(conn);
        }
        return getResource(txLevel, poolmgr, mcf, spec, subject, cxRequestInfo, info, desc, shareable);
    } catch (PoolingException ex) {
        Object[] params = new Object[] { poolInfo, ex };
        getLogger().log(Level.WARNING, "poolmgr.get_connection_failure", params);
        // GLASSFISH-19609
        // we can't simply look for ResourceException and throw back since
        // Connector Container also throws ResourceException which might
        // hide the SecurityException thrown by RA.
        // So, we try to track SecurityException
        unwrapSecurityException(ex);
        String i18nMsg = getLocalStrings().getString("con_mgr.error_creating_connection", ex.getMessage());
        ResourceAllocationException rae = new ResourceAllocationException(i18nMsg);
        rae.initCause(ex);
        throw rae;
    }
}
Also used : ClientSecurityInfo(com.sun.enterprise.resource.ClientSecurityInfo) ResourceSpec(com.sun.enterprise.resource.ResourceSpec) PoolManager(com.sun.enterprise.resource.pool.PoolManager) Subject(javax.security.auth.Subject) PoolingException(com.sun.appserv.connectors.internal.api.PoolingException) ConnectorDescriptor(com.sun.enterprise.deployment.ConnectorDescriptor)

Example 3 with ResourceSpec

use of com.sun.enterprise.resource.ResourceSpec 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

ResourceSpec (com.sun.enterprise.resource.ResourceSpec)3 PoolingException (com.sun.appserv.connectors.internal.api.PoolingException)2 ResourceHandle (com.sun.enterprise.resource.ResourceHandle)2 ResourceException (javax.resource.ResourceException)2 ConnectorDescriptor (com.sun.enterprise.deployment.ConnectorDescriptor)1 ClientSecurityInfo (com.sun.enterprise.resource.ClientSecurityInfo)1 XAResourceWrapper (com.sun.enterprise.resource.XAResourceWrapper)1 PoolManager (com.sun.enterprise.resource.pool.PoolManager)1 JavaEETransactionManager (com.sun.enterprise.transaction.api.JavaEETransactionManager)1 Subject (javax.security.auth.Subject)1 InvocationException (org.glassfish.api.invocation.InvocationException)1