Search in sources :

Example 6 with ConnectorRuntime

use of com.sun.enterprise.connectors.ConnectorRuntime 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 7 with ConnectorRuntime

use of com.sun.enterprise.connectors.ConnectorRuntime in project Payara by payara.

the class ResourceAdapterConfigDeployer method undeployResource.

/**
 * {@inheritDoc}
 */
public synchronized void undeployResource(Object resource) throws Exception {
    ResourceAdapterConfig domainConfig = (ResourceAdapterConfig) resource;
    String rarName = domainConfig.getResourceAdapterName();
    ConnectorRuntime crt = getConnectorRuntime();
    crt.deleteResourceAdapterConfig(rarName);
}
Also used : ResourceAdapterConfig(org.glassfish.connectors.config.ResourceAdapterConfig) ConnectorRuntime(com.sun.enterprise.connectors.ConnectorRuntime)

Example 8 with ConnectorRuntime

use of com.sun.enterprise.connectors.ConnectorRuntime in project Payara by payara.

the class ResourceAdapterConfigDeployer method deployResource.

/**
 * {@inheritDoc}
 */
public synchronized void deployResource(Object resource) throws Exception {
    ResourceAdapterConfig domainConfig = (ResourceAdapterConfig) resource;
    String rarName = domainConfig.getResourceAdapterName();
    ConnectorRuntime crt = getConnectorRuntime();
    if (_logger.isLoggable(Level.FINE)) {
        _logger.log(Level.FINE, "Calling backend to add resource adapterConfig ", rarName);
    }
    crt.addResourceAdapterConfig(rarName, domainConfig);
    if (_logger.isLoggable(Level.FINE)) {
        _logger.log(Level.FINE, "Added resource adapterConfig in backend", rarName);
    }
}
Also used : ResourceAdapterConfig(org.glassfish.connectors.config.ResourceAdapterConfig) ConnectorRuntime(com.sun.enterprise.connectors.ConnectorRuntime)

Example 9 with ConnectorRuntime

use of com.sun.enterprise.connectors.ConnectorRuntime 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)

Example 10 with ConnectorRuntime

use of com.sun.enterprise.connectors.ConnectorRuntime in project Payara by payara.

the class ConnectorsRecoveryResourceHandler method createActiveResourceAdapter.

private void createActiveResourceAdapter(String rarModuleName) throws ConnectorRuntimeException {
    ConnectorRuntime cr = ConnectorRuntime.getRuntime();
    ConnectorRegistry creg = ConnectorRegistry.getInstance();
    if (creg.isRegistered(rarModuleName))
        return;
    if (ConnectorAdminServiceUtils.isEmbeddedConnectorModule(rarModuleName)) {
        cr.createActiveResourceAdapterForEmbeddedRar(rarModuleName);
    } else {
        String moduleDir;
        if (ConnectorsUtil.belongsToSystemRA(rarModuleName)) {
            moduleDir = ConnectorsUtil.getSystemModuleLocation(rarModuleName);
        } else {
            moduleDir = configBeansUtilities.getLocation(rarModuleName);
        }
        ClassLoader loader = cr.createConnectorClassLoader(moduleDir, null, rarModuleName);
        cr.createActiveResourceAdapter(moduleDir, rarModuleName, loader);
    }
}
Also used : ConnectorRegistry(com.sun.enterprise.connectors.ConnectorRegistry) ConnectorRuntime(com.sun.enterprise.connectors.ConnectorRuntime)

Aggregations

ConnectorRuntime (com.sun.enterprise.connectors.ConnectorRuntime)13 ConnectorRuntimeException (com.sun.appserv.connectors.internal.api.ConnectorRuntimeException)7 PoolInfo (org.glassfish.resourcebase.resources.api.PoolInfo)3 ActiveResourceAdapter (com.sun.enterprise.connectors.ActiveResourceAdapter)2 ConnectorApplication (com.sun.enterprise.connectors.module.ConnectorApplication)2 ConnectorDescriptor (com.sun.enterprise.deployment.ConnectorDescriptor)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 NamingException (javax.naming.NamingException)2 ResourceException (javax.resource.ResourceException)2 UnavailableException (javax.resource.spi.UnavailableException)2 ResourceAdapterConfig (org.glassfish.connectors.config.ResourceAdapterConfig)2 ResourceInfo (org.glassfish.resourcebase.resources.api.ResourceInfo)2 Resource (com.sun.enterprise.config.serverbeans.Resource)1 ConnectorRegistry (com.sun.enterprise.connectors.ConnectorRegistry)1 ConnectorArchivist (com.sun.enterprise.connectors.deployment.util.ConnectorArchivist)1 FileArchive (com.sun.enterprise.deploy.shared.FileArchive)1 Application (com.sun.enterprise.deployment.Application)1 MessageListener (com.sun.enterprise.deployment.MessageListener)1 ResourcePrincipal (com.sun.enterprise.deployment.ResourcePrincipal)1 AdministeredObjectResource (com.sun.enterprise.resource.beans.AdministeredObjectResource)1