Hi

I have written a database security realm for SUN AS 8.1. I want to get database connections from a datasource, but it doesn't work. DataSource.getConnection() throws InvocationException

#|2005-06-20T18:52:02.406+0300|WARNING|sun-appserver-pe8.1_02|javax.enterprise. system.stream.err|_ThreadID=11;|com.sun.enterprise.InvocationException
at com.sun.enterprise.resource.ResourceManagerImpl.getTransaction(ResourceManagerI mpl.java:41)
at com.sun.enterprise.resource.PoolManagerImpl.getResource(PoolManagerImpl.java:14 1)
at com.sun.enterprise.connectors.ConnectionManagerImpl.internalGetConnection(Co nnectionManagerImpl.java:258)
at com.sun.enterprise.connectors.ConnectionManagerImpl.allocateConnection(Connecti onManagerImpl.java:147)
at com.sun.enterprise.connectors.ConnectionManagerImpl.allocateConnection(Connecti onManagerImpl.java:122)
at com.sun.gjc.spi.DataSource.getConnection(DataSource.java:70)


Here is SUN application server code that throws the exception. It would be very interesting to know what is the reason to do so.

    private Object internalGetConnection(ManagedConnectionFactory mcf,
                                         final ResourcePrincipal prin,
                                         ConnectionRequestInfo cxRequestInfo,
                                         boolean shareable, String jndiNameToUse)
        throws ResourceException {
        try {
            PoolManager poolmgr = Switch.getSwitch().getPoolManager();
ConnectorRegistry registry = ConnectorRegistry.getInstance();
            PoolMetaData pmd = registry.getPoolMetaData( poolName );
 
            ResourceSpec spec = new ResourceSpec(jndiNameToUse,
                    ResourceSpec.JNDI_NAME, pmd);
spec.setConnectionPoolName(this.poolName);
ManagedConnectionFactory freshMCF = pmd.getMCF();
 
if (! freshMCF.equals(mcf)) {
_logger.log(Level.INFO, "conmgr.mcf_not_equal");
}
            ConnectorDescriptor desc = registry.getDescriptor(rarName);
 
            Subject subject = null;
            ClientSecurityInfo info = null;
            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 (_logger.isLoggable(Level.FINE)) {
_logger.fine( "ConnectionMgr: poolName " + poolName +
" txLevel : " + txLevel );
}
            
 
            ResourceAllocator alloc = null;
            switch (txLevel) {
            
            case ConnectorConstants.NO_TRANSACTION_INT:
                alloc =
                    new NoTxConnectorAllocator(poolmgr, mcf, spec,
                                               subject, cxRequestInfo, info,
                                               desc);
                return poolmgr.getResource(spec, alloc, info);
                
            case ConnectorConstants.LOCAL_TRANSACTION_INT:
                if (!shareable) {
                    StringManager localStrings =
                        StringManager.getManager(ConnectionManagerImpl.class);
String i18nMsg = localStrings.getString(
"con_mgr.resource_not_shareable");
 
                   // ----- SUN AS THROWS EXCEPTION HERE --------
throw new ResourceAllocationException( i18nMsg );
                }
                alloc =
                    new LocalTxConnectorAllocator(poolmgr, mcf, spec,
                                                  subject, cxRequestInfo,
                                                  info, desc);
                return poolmgr.getResource(spec, alloc, info);
            case ConnectorConstants.XA_TRANSACTION_INT:
                if (rarName.equals(ConnectorRuntime.DEFAULT_JMS_ADAPTER)) {
                    shareable = false;
                }
spec.markAsXA();
                alloc =
                    new ConnectorAllocator(poolmgr, mcf, spec,
                                           subject, cxRequestInfo, info, desc,
                                           shareable);
                return poolmgr.getResource(spec, alloc, info);
            default:
                StringManager localStrings =
                    StringManager.getManager(ConnectionManagerImpl.class);
String i18nMsg = localStrings.getString(
"con_mgr.illegal_tx_level", txLevel+ " ");
                throw new IllegalStateException(i18nMsg);
            }
 
        } catch (PoolingException ex) {
            _logger.log(Level.WARNING,"poolmgr.get_connection_failure",ex.getMessage());
            StringManager localStrings =
                StringManager.getManager(ConnectionManagerImpl.class);
            String i18nMsg = localStrings.getString(
"con_mgr.error_creating_connection", ex.getMessage() );
            ResourceAllocationException rae = new ResourceAllocationException(
i18nMsg );
rae.initCause( ex );
            throw rae;
        }
    }





I don't want to use driver manager to get database connections ! Other app. servers allow to use datasources from security realms (WebLogic) and some of them even provide already written RDBMS realms.