Search in sources :

Example 56 with ConnectorRuntimeException

use of com.sun.appserv.connectors.internal.api.ConnectorRuntimeException in project Payara by payara.

the class ConnectorDDTransformUtils method getConnectorDescriptor.

/**
 * Get the ConnectorDescriptor object which represents the ra.xml and
 * sun-ra.xml from an exploded rar module.
 *
 * @param moduleDir Directory where rar is exploded.
 * @return ConnectorDescriptor object which
 *         represents the ra.xml and sun-ra.xml
 * @throws ConnectorRuntimeException if ra.xml could not be located or
 *                                   invalid. For 1.0 type rar if sun-ra.xml is not present or
 *                                   invalid this exception is thrown. For 1.5 type rar sun-ra.xml
 *                                   should not be  present.
 */
public static ConnectorDescriptor getConnectorDescriptor(String moduleDir, String rarModuleName) throws ConnectorRuntimeException {
    ClassLoader cl = Thread.currentThread().getContextClassLoader();
    try {
        File module = new File(moduleDir);
        FileArchive fileArchive = new FileArchive();
        // directory where rar is exploded
        fileArchive.open(module.toURI());
        ConnectorRuntime runtime = ConnectorRuntime.getRuntime();
        ClassLoader loader;
        if (ConnectorsUtil.belongsToSystemRA(rarModuleName)) {
            loader = ConnectorRuntime.getRuntime().getSystemRARClassLoader(rarModuleName);
            Thread.currentThread().setContextClassLoader(loader);
        } else {
            loader = runtime.createConnectorClassLoader(moduleDir, null, rarModuleName);
        }
        ConnectorArchivist connectorArchivist = runtime.getConnectorArchvist();
        // TODO V3 what happens to embedded .rar ? as its parent classloader should be application CL
        // setting the classloader so that annotation processor can make use of it.
        connectorArchivist.setClassLoader(loader);
        // fileArchive.entries("META-INF/ra.xml");
        // TODO V3 need to check whether ra.xml is present, if so, check the version. process annotations
        // only if its 1.6 or above ?
        connectorArchivist.setAnnotationProcessingRequested(true);
        return connectorArchivist.open(fileArchive);
    } catch (IOException ex) {
        ConnectorRuntimeException cre = new ConnectorRuntimeException("Failed to read the connector deployment descriptors");
        cre.initCause(ex);
        _logger.log(Level.SEVERE, "rardeployment.connector_descriptor_read_error", moduleDir);
        _logger.log(Level.SEVERE, "", cre);
        throw cre;
    } catch (SAXParseException ex) {
        ConnectorRuntimeException cre = new ConnectorRuntimeException("Failed to parse the connector deployment descriptors");
        cre.initCause(ex);
        _logger.log(Level.SEVERE, "rardeployment.connector_descriptor_parse_error", moduleDir);
        _logger.log(Level.SEVERE, "", cre);
        throw cre;
    } finally {
        Thread.currentThread().setContextClassLoader(cl);
    }
}
Also used : ConnectorRuntimeException(com.sun.appserv.connectors.internal.api.ConnectorRuntimeException) ConnectorArchivist(com.sun.enterprise.connectors.deployment.util.ConnectorArchivist) SAXParseException(org.xml.sax.SAXParseException) FileArchive(com.sun.enterprise.deploy.shared.FileArchive) IOException(java.io.IOException) File(java.io.File) ConnectorRuntime(com.sun.enterprise.connectors.ConnectorRuntime)

Example 57 with ConnectorRuntimeException

use of com.sun.appserv.connectors.internal.api.ConnectorRuntimeException in project Payara by payara.

the class ConnectorConnectionPoolDeployer method redeployResource.

/**
 * {@inheritDoc}
 */
public synchronized void redeployResource(Object resource) throws Exception {
    // Connector connection pool reconfiguration or
    // change in security maps
    org.glassfish.connectors.config.ConnectorConnectionPool domainCcp = (org.glassfish.connectors.config.ConnectorConnectionPool) resource;
    List<SecurityMap> securityMaps = domainCcp.getSecurityMap();
    // Since 8.1 PE/SE/EE, only if pool has already been deployed in this
    // server-instance earlier, reconfig this pool
    PoolInfo poolInfo = ConnectorsUtil.getPoolInfo(domainCcp);
    if (!runtime.isConnectorConnectionPoolDeployed(poolInfo)) {
        if (_logger.isLoggable(Level.FINE)) {
            _logger.fine("The connector connection pool " + poolInfo + " is either not referred or not yet created in " + "this server instance and pool and hence " + "redeployment is ignored");
        }
        return;
    }
    String rarName = domainCcp.getResourceAdapterName();
    String connDefName = domainCcp.getConnectionDefinitionName();
    List<Property> props = domainCcp.getProperty();
    ConnectorConnectionPool ccp = getConnectorConnectionPool(domainCcp, poolInfo);
    populateConnectorConnectionPool(ccp, connDefName, rarName, props, securityMaps);
    boolean poolRecreateRequired = false;
    try {
        if (_logger.isLoggable(Level.FINE)) {
            _logger.fine("Calling reconfigure pool");
        }
        poolRecreateRequired = runtime.reconfigureConnectorConnectionPool(ccp, new HashSet());
    } catch (ConnectorRuntimeException cre) {
        Object[] params = new Object[] { poolInfo, cre };
        _logger.log(Level.WARNING, "error.reconfiguring.pool", params);
    }
    if (poolRecreateRequired) {
        if (_logger.isLoggable(Level.FINE)) {
            _logger.fine("Pool recreation required");
        }
        runtime.recreateConnectorConnectionPool(ccp);
        if (_logger.isLoggable(Level.FINE)) {
            _logger.fine("Pool recreation done");
        }
    }
}
Also used : ConnectorRuntimeException(com.sun.appserv.connectors.internal.api.ConnectorRuntimeException) ConnectorConnectionPool(com.sun.enterprise.connectors.ConnectorConnectionPool) SecurityMap(org.glassfish.connectors.config.SecurityMap) PoolInfo(org.glassfish.resourcebase.resources.api.PoolInfo) ConnectorConfigProperty(com.sun.enterprise.deployment.ConnectorConfigProperty) Property(org.jvnet.hk2.config.types.Property)

Example 58 with ConnectorRuntimeException

use of com.sun.appserv.connectors.internal.api.ConnectorRuntimeException in project Payara by payara.

the class ConnectorConnectionPoolDeployer method getConnectorConnectionPool.

private ConnectorConnectionPool getConnectorConnectionPool(org.glassfish.connectors.config.ConnectorConnectionPool domainCcp, PoolInfo poolInfo) throws Exception {
    ConnectorConnectionPool ccp;
    ccp = new ConnectorConnectionPool(poolInfo);
    ccp.setSteadyPoolSize(domainCcp.getSteadyPoolSize());
    ccp.setMaxPoolSize(domainCcp.getMaxPoolSize());
    ccp.setMaxWaitTimeInMillis(domainCcp.getMaxWaitTimeInMillis());
    ccp.setPoolResizeQuantity(domainCcp.getPoolResizeQuantity());
    ccp.setIdleTimeoutInSeconds(domainCcp.getIdleTimeoutInSeconds());
    ccp.setFailAllConnections(Boolean.valueOf(domainCcp.getFailAllConnections()));
    ccp.setAuthCredentialsDefinedInPool(isAuthCredentialsDefinedInPool(domainCcp));
    // The line below will change for 9.0. We will get this from
    // the domain.xml
    ccp.setConnectionValidationRequired(Boolean.valueOf(domainCcp.getIsConnectionValidationRequired()));
    String txSupport = domainCcp.getTransactionSupport();
    int txSupportIntVal = parseTransactionSupportString(txSupport);
    if (txSupportIntVal == -1) {
        // from the ra.xml
        if (_logger.isLoggable(Level.FINE)) {
            _logger.fine("Got transaction-support attr null from domain.xml");
        }
        txSupportIntVal = ConnectionPoolObjectsUtils.getTransactionSupportFromRaXml(domainCcp.getResourceAdapterName());
    } else {
        // the value specified in the ra.xml
        if (!ConnectionPoolObjectsUtils.isTxSupportConfigurationSane(txSupportIntVal, domainCcp.getResourceAdapterName())) {
            String i18nMsg = localStrings.getString("ccp_deployer.incorrect_tx_support");
            ConnectorRuntimeException cre = new ConnectorRuntimeException(i18nMsg);
            _logger.log(Level.SEVERE, "rardeployment.incorrect_tx_support", ccp.getName());
            throw cre;
        }
    }
    if (_logger.isLoggable(Level.FINE)) {
        _logger.fine("setting txSupportVal to " + txSupportIntVal + " in pool " + domainCcp.getName());
    }
    ccp.setTransactionSupport(txSupportIntVal);
    // Always for ccp
    ccp.setNonComponent(false);
    ccp.setNonTransactional(false);
    ccp.setConnectionLeakTracingTimeout(domainCcp.getConnectionLeakTimeoutInSeconds());
    ccp.setConnectionReclaim(Boolean.valueOf(domainCcp.getConnectionLeakReclaim()));
    ccp.setMatchConnections(Boolean.valueOf(domainCcp.getMatchConnections()));
    ccp.setAssociateWithThread(Boolean.valueOf(domainCcp.getAssociateWithThread()));
    ccp.setPooling(Boolean.valueOf(domainCcp.getPooling()));
    ccp.setPingDuringPoolCreation(Boolean.valueOf(domainCcp.getPing()));
    boolean lazyConnectionEnlistment = Boolean.valueOf(domainCcp.getLazyConnectionEnlistment());
    boolean lazyConnectionAssociation = Boolean.valueOf(domainCcp.getLazyConnectionAssociation());
    if (lazyConnectionAssociation) {
        if (lazyConnectionEnlistment) {
            ccp.setLazyConnectionAssoc(true);
            ccp.setLazyConnectionEnlist(true);
        } else {
            _logger.log(Level.SEVERE, "conn_pool_obj_utils.lazy_enlist-lazy_assoc-invalid-combination", domainCcp.getName());
            String i18nMsg = localStrings.getString("cpou.lazy_enlist-lazy_assoc-invalid-combination", domainCcp.getName());
            throw new RuntimeException(i18nMsg);
        }
    } else {
        ccp.setLazyConnectionAssoc(lazyConnectionAssociation);
        ccp.setLazyConnectionEnlist(lazyConnectionEnlistment);
    }
    boolean pooling = Boolean.valueOf(domainCcp.getPooling());
    // TODO: should this be added to the beginning of this method?
    if (!pooling) {
        // Throw exception if assoc with thread is set to true.
        if (Boolean.valueOf(domainCcp.getAssociateWithThread())) {
            _logger.log(Level.SEVERE, "conn_pool_obj_utils.pooling_disabled_assocwiththread_invalid_combination", domainCcp.getName());
            String i18nMsg = localStrings.getString("cpou.pooling_disabled_assocwiththread_invalid_combination", domainCcp.getName());
            throw new RuntimeException(i18nMsg);
        }
        // match-connections/max-connection-usage-count/idele-timeout
        if (Boolean.valueOf(domainCcp.getIsConnectionValidationRequired())) {
            _logger.log(Level.WARNING, "conn_pool_obj_utils.pooling_disabled_conn_validation_invalid_combination", domainCcp.getName());
        }
        if (Integer.parseInt(domainCcp.getValidateAtmostOncePeriodInSeconds()) > 0) {
            _logger.log(Level.WARNING, "conn_pool_obj_utils.pooling_disabled_validate_atmost_once_invalid_combination", domainCcp.getName());
        }
        if (Boolean.valueOf(domainCcp.getMatchConnections())) {
            _logger.log(Level.WARNING, "conn_pool_obj_utils.pooling_disabled_match_connections_invalid_combination", domainCcp.getName());
        }
        if (Integer.parseInt(domainCcp.getMaxConnectionUsageCount()) > 0) {
            _logger.log(Level.WARNING, "conn_pool_obj_utils.pooling_disabled_max_conn_usage_invalid_combination", domainCcp.getName());
        }
        if (Integer.parseInt(domainCcp.getIdleTimeoutInSeconds()) > 0) {
            _logger.log(Level.WARNING, "conn_pool_obj_utils.pooling_disabled_idle_timeout_invalid_combination", domainCcp.getName());
        }
    }
    ccp.setPooling(pooling);
    ccp.setMaxConnectionUsage(domainCcp.getMaxConnectionUsageCount());
    ccp.setValidateAtmostOncePeriod(domainCcp.getValidateAtmostOncePeriodInSeconds());
    ccp.setConCreationRetryAttempts(domainCcp.getConnectionCreationRetryAttempts());
    ccp.setConCreationRetryInterval(domainCcp.getConnectionCreationRetryIntervalInSeconds());
    // IMPORTANT
    // Here all properties that will be checked by the
    // convertElementPropertyToPoolProperty method need to be set to
    // their default values
    convertElementPropertyToPoolProperty(ccp, domainCcp);
    return ccp;
}
Also used : ConnectorRuntimeException(com.sun.appserv.connectors.internal.api.ConnectorRuntimeException) ConnectorConnectionPool(com.sun.enterprise.connectors.ConnectorConnectionPool) ConnectorRuntimeException(com.sun.appserv.connectors.internal.api.ConnectorRuntimeException)

Example 59 with ConnectorRuntimeException

use of com.sun.appserv.connectors.internal.api.ConnectorRuntimeException in project Payara by payara.

the class ConnectorConnectionPoolDeployer method populateConnectorConnectionPool.

private void populateConnectorConnectionPool(ConnectorConnectionPool ccp, String connectionDefinitionName, String rarName, List<Property> props, List<SecurityMap> securityMaps) throws ConnectorRuntimeException {
    ConnectorDescriptor connectorDescriptor = runtime.getConnectorDescriptor(rarName);
    if (connectorDescriptor == null) {
        ConnectorRuntimeException cre = new ConnectorRuntimeException("Failed to get connection pool object");
        _logger.log(Level.SEVERE, "rardeployment.connector_descriptor_notfound_registry", rarName);
        _logger.log(Level.SEVERE, "", cre);
        throw cre;
    }
    Set connectionDefs = connectorDescriptor.getOutboundResourceAdapter().getConnectionDefs();
    ConnectionDefDescriptor cdd = null;
    Iterator it = connectionDefs.iterator();
    while (it.hasNext()) {
        cdd = (ConnectionDefDescriptor) it.next();
        if (connectionDefinitionName.equals(cdd.getConnectionFactoryIntf()))
            break;
    }
    ConnectorDescriptorInfo cdi = new ConnectorDescriptorInfo();
    cdi.setRarName(rarName);
    cdi.setResourceAdapterClassName(connectorDescriptor.getResourceAdapterClass());
    cdi.setConnectionDefinitionName(cdd.getConnectionFactoryIntf());
    cdi.setManagedConnectionFactoryClass(cdd.getManagedConnectionFactoryImpl());
    cdi.setConnectionFactoryClass(cdd.getConnectionFactoryImpl());
    cdi.setConnectionFactoryInterface(cdd.getConnectionFactoryIntf());
    cdi.setConnectionClass(cdd.getConnectionImpl());
    cdi.setConnectionInterface(cdd.getConnectionIntf());
    Properties properties = new Properties();
    // Refer Sun Bug :6579154 - Equivalent Oracle Bug :12206278
    if (rarName.trim().equals(ConnectorRuntime.DEFAULT_JMS_ADAPTER)) {
        properties.put("AddressList", "localhost");
    }
    Set mergedProps = ConnectorDDTransformUtils.mergeProps(props, cdd.getConfigProperties(), properties);
    cdi.setMCFConfigProperties(mergedProps);
    cdi.setResourceAdapterConfigProperties(connectorDescriptor.getConfigProperties());
    ccp.setConnectorDescriptorInfo(cdi);
    ccp.setSecurityMaps(SecurityMapUtils.getConnectorSecurityMaps(securityMaps));
}
Also used : ConnectorRuntimeException(com.sun.appserv.connectors.internal.api.ConnectorRuntimeException) ConnectorDescriptor(com.sun.enterprise.deployment.ConnectorDescriptor) ConnectionDefDescriptor(com.sun.enterprise.deployment.ConnectionDefDescriptor) ConnectorDescriptorInfo(com.sun.enterprise.connectors.ConnectorDescriptorInfo)

Example 60 with ConnectorRuntimeException

use of com.sun.appserv.connectors.internal.api.ConnectorRuntimeException in project Payara by payara.

the class AdministeredObjectFactory method getObjectInstance.

public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable env) throws Exception {
    Reference ref = (Reference) obj;
    if (logger.isLoggable(Level.FINE)) {
        logger.fine("AdministeredObjectFactory: " + ref + " Name:" + name);
    }
    AdministeredObjectResource aor = (AdministeredObjectResource) ref.get(0).getContent();
    String moduleName = aor.getResourceAdapter();
    // If call fom application client, start resource adapter lazily.
    // todo: Similar code in ConnectorObjectFactory - to refactor.
    ConnectorRuntime runtime = ConnectorNamingUtils.getRuntime();
    if (runtime.isACCRuntime() || runtime.isNonACCRuntime()) {
        ConnectorDescriptor connectorDescriptor = null;
        try {
            Context ic = new InitialContext();
            String descriptorJNDIName = ConnectorAdminServiceUtils.getReservePrefixedJNDINameForDescriptor(moduleName);
            connectorDescriptor = (ConnectorDescriptor) ic.lookup(descriptorJNDIName);
        } catch (NamingException ne) {
            if (logger.isLoggable(Level.FINE)) {
                logger.log(Level.FINE, "Failed to look up ConnectorDescriptor " + "from JNDI", moduleName);
            }
            throw new ConnectorRuntimeException("Failed to look up " + "ConnectorDescriptor from JNDI");
        }
        runtime.createActiveResourceAdapter(connectorDescriptor, moduleName, null);
    }
    ClassLoader loader = Thread.currentThread().getContextClassLoader();
    if (runtime.checkAccessibility(moduleName, loader) == false) {
        throw new NamingException("Only the application that has the embedded resource" + "adapter can access the resource adapter");
    }
    if (logger.isLoggable(Level.FINE)) {
        logger.fine("[AdministeredObjectFactory] ==> Got AdministeredObjectResource = " + aor);
    }
    // all RARs except system RARs should have been available now.
    if (ConnectorsUtil.belongsToSystemRA(moduleName)) {
        // make sure that system rar is started and hence added to connector classloader chain
        if (ConnectorRegistry.getInstance().getActiveResourceAdapter(moduleName) == null) {
            String moduleLocation = ConnectorsUtil.getSystemModuleLocation(moduleName);
            runtime.createActiveResourceAdapter(moduleLocation, moduleName, null);
        }
        loader = ConnectorRegistry.getInstance().getActiveResourceAdapter(moduleName).getClassLoader();
    } else if (runtime.isServer()) {
        if (ConnectorsUtil.isStandAloneRA(moduleName)) {
            loader = ConnectorRegistry.getInstance().getActiveResourceAdapter(moduleName).getClassLoader();
        }
    }
    return aor.createAdministeredObject(loader);
}
Also used : ConnectorRuntimeException(com.sun.appserv.connectors.internal.api.ConnectorRuntimeException) ConnectorDescriptor(com.sun.enterprise.deployment.ConnectorDescriptor) AdministeredObjectResource(com.sun.enterprise.resource.beans.AdministeredObjectResource) ConnectorRuntime(com.sun.enterprise.connectors.ConnectorRuntime)

Aggregations

ConnectorRuntimeException (com.sun.appserv.connectors.internal.api.ConnectorRuntimeException)69 NamingException (javax.naming.NamingException)16 URISyntaxException (java.net.URISyntaxException)13 PoolInfo (org.glassfish.resourcebase.resources.api.PoolInfo)12 ConnectorDescriptor (com.sun.enterprise.deployment.ConnectorDescriptor)10 PrivilegedActionException (java.security.PrivilegedActionException)9 ExecutionException (java.util.concurrent.ExecutionException)8 ResourceAdapterInternalException (javax.resource.spi.ResourceAdapterInternalException)8 MultiException (org.glassfish.hk2.api.MultiException)8 JmsService (com.sun.enterprise.connectors.jms.config.JmsService)7 ConnectorConfigProperty (com.sun.enterprise.deployment.ConnectorConfigProperty)7 ManagedConnectionFactory (javax.resource.spi.ManagedConnectionFactory)7 ActiveResourceAdapter (com.sun.enterprise.connectors.ActiveResourceAdapter)5 ConnectorRuntime (com.sun.enterprise.connectors.ConnectorRuntime)5 ConnectorConnectionPool (com.sun.enterprise.connectors.ConnectorConnectionPool)4 IOException (java.io.IOException)4 ResourceInfo (org.glassfish.resourcebase.resources.api.ResourceInfo)4 Resource (com.sun.enterprise.config.serverbeans.Resource)3 ResourcePool (com.sun.enterprise.config.serverbeans.ResourcePool)3 File (java.io.File)3