Search in sources :

Example 16 with Application

use of com.sun.enterprise.deployment.Application in project Payara by payara.

the class ResourceAdapterAdminServiceImpl method createActiveResourceAdapter.

/**
 * Creates Active resource Adapter which abstracts the rar module. During
 * the creation of ActiveResourceAdapter, default pools and resources also
 * are created.
 *
 * @param connectorDescriptor object which abstracts the connector deployment descriptor
 *                            i.e rar.xml and sun-ra.xml.
 * @param moduleName          Name of the module
 * @param moduleDir           Directory where rar module is exploded.
 * @param loader              Classloader to use
 * @throws ConnectorRuntimeException if creation fails.
 */
public void createActiveResourceAdapter(ConnectorDescriptor connectorDescriptor, String moduleName, String moduleDir, ClassLoader loader) throws ConnectorRuntimeException {
    synchronized (_registry.getLockObject(moduleName)) {
        if (_logger.isLoggable(Level.FINE)) {
            _logger.fine("ResourceAdapterAdminServiceImpl :: createActiveRA " + moduleName + " at " + moduleDir);
        }
        ActiveResourceAdapter activeResourceAdapter = _registry.getActiveResourceAdapter(moduleName);
        if (activeResourceAdapter != null) {
            if (_logger.isLoggable(Level.FINE)) {
                _logger.log(Level.FINE, "rardeployment.resourceadapter.already.started", moduleName);
            }
            return;
        }
        // TODO V3 works fine ?
        if (loader == null) {
            try {
                loader = connectorDescriptor.getClassLoader();
            } catch (Exception ex) {
                if (_logger.isLoggable(Level.FINE)) {
                    _logger.log(Level.FINE, "No classloader available with connector descriptor");
                }
                loader = null;
            }
        }
        ConnectorRuntime connectorRuntime = ConnectorRuntime.getRuntime();
        ModuleDescriptor moduleDescriptor = null;
        Application application = null;
        if (_logger.isLoggable(Level.FINE)) {
            _logger.fine("ResourceAdapterAdminServiceImpl :: createActiveRA " + moduleName + " at " + moduleDir + " loader :: " + loader);
        }
        // (standalone + embedded)
        if (loader == null && ConnectorsUtil.belongsToSystemRA(moduleName)) {
            if (connectorRuntime.isServer()) {
                loader = connectorRuntime.getSystemRARClassLoader(moduleName);
            }
        } else {
            connectorDescriptor.setClassLoader(null);
            moduleDescriptor = connectorDescriptor.getModuleDescriptor();
            application = connectorDescriptor.getApplication();
            connectorDescriptor.setModuleDescriptor(null);
            connectorDescriptor.setApplication(null);
        }
        try {
            activeResourceAdapter = connectorRuntime.getActiveRAFactory().createActiveResourceAdapter(connectorDescriptor, moduleName, loader);
            if (_logger.isLoggable(Level.FINE)) {
                _logger.fine("ResourceAdapterAdminServiceImpl :: createActiveRA " + moduleName + " at " + moduleDir + " adding to registry " + activeResourceAdapter);
            }
            _registry.addActiveResourceAdapter(moduleName, activeResourceAdapter);
            if (_logger.isLoggable(Level.FINE)) {
                _logger.fine("ResourceAdapterAdminServiceImpl:: createActiveRA " + moduleName + " at " + moduleDir + " env =server ? " + (connectorRuntime.isServer()));
            }
            if (connectorRuntime.isServer()) {
                // Update RAConfig in Connector Descriptor and bind in JNDI
                // so that ACC clients could use RAConfig
                updateRAConfigInDescriptor(connectorDescriptor, moduleName);
                String descriptorJNDIName = ConnectorAdminServiceUtils.getReservePrefixedJNDINameForDescriptor(moduleName);
                if (_logger.isLoggable(Level.FINE)) {
                    _logger.fine("ResourceAdapterAdminServiceImpl :: createActiveRA " + moduleName + " at " + moduleDir + " publishing descriptor " + descriptorJNDIName);
                }
                _runtime.getNamingManager().publishObject(descriptorJNDIName, connectorDescriptor, true);
                activeResourceAdapter.setup();
                if (System.getSecurityManager() != null) {
                    String securityWarningMessage = connectorRuntime.getSecurityPermissionSpec(moduleName);
                    // To i18N.
                    if (securityWarningMessage != null) {
                        _logger.log(Level.WARNING, securityWarningMessage);
                    }
                }
            }
        } catch (NullPointerException npEx) {
            ConnectorRuntimeException cre = new ConnectorRuntimeException("Error in creating active RAR");
            cre.initCause(npEx);
            _logger.log(Level.SEVERE, "rardeployment.nullPointerException", moduleName);
            _logger.log(Level.SEVERE, "", cre);
            throw cre;
        } catch (NamingException ne) {
            ConnectorRuntimeException cre = new ConnectorRuntimeException("Error in creating active RAR");
            cre.initCause(ne);
            _logger.log(Level.SEVERE, "rardeployment.jndi_publish_failure");
            _logger.log(Level.SEVERE, "", cre);
            throw cre;
        } finally {
            if (moduleDescriptor != null) {
                connectorDescriptor.setModuleDescriptor(moduleDescriptor);
                connectorDescriptor.setApplication(application);
                connectorDescriptor.setClassLoader(loader);
            }
        }
    }
}
Also used : ConnectorRuntimeException(com.sun.appserv.connectors.internal.api.ConnectorRuntimeException) ModuleDescriptor(org.glassfish.deployment.common.ModuleDescriptor) NamingException(javax.naming.NamingException) ActiveResourceAdapter(com.sun.enterprise.connectors.ActiveResourceAdapter) ConnectorApplication(com.sun.enterprise.connectors.module.ConnectorApplication) Application(com.sun.enterprise.deployment.Application) ResourceException(javax.resource.ResourceException) NamingException(javax.naming.NamingException) ConnectorRuntimeException(com.sun.appserv.connectors.internal.api.ConnectorRuntimeException) ConnectorRuntime(com.sun.enterprise.connectors.ConnectorRuntime)

Example 17 with Application

use of com.sun.enterprise.deployment.Application in project Payara by payara.

the class AppSpecificConnectorClassLoaderUtil method detectResourceInRA.

private void detectResourceInRA(Application app, String moduleName, String jndiName) {
    // domain.xml
    Resource res = null;
    if (jndiName.startsWith(ConnectorConstants.JAVA_APP_SCOPE_PREFIX)) /*|| jndiName.startsWith("java:global/")*/
    {
        ApplicationInfo appInfo = appRegistry.get(app.getName());
        res = getApplicationScopedResource(jndiName, BindableResource.class, appInfo);
    } else if (jndiName.startsWith(ConnectorConstants.JAVA_MODULE_SCOPE_PREFIX)) {
        ApplicationInfo appInfo = appRegistry.get(app.getName());
        res = getModuleScopedResource(jndiName, moduleName, BindableResource.class, appInfo);
    } else {
        res = ConnectorsUtil.getResourceByName(getResources(), BindableResource.class, jndiName);
    }
    // (and .ear may refer to these resources in DD)
    if (res != null) {
        if (ConnectorResource.class.isAssignableFrom(res.getClass())) {
            ConnectorResource connResource = (ConnectorResource) res;
            String poolName = connResource.getPoolName();
            Resource pool;
            ApplicationInfo appInfo = appRegistry.get(app.getName());
            if (jndiName.startsWith(ConnectorConstants.JAVA_APP_SCOPE_PREFIX)) /*|| jndiName.startsWith("java:global/")*/
            {
                pool = getApplicationScopedResource(poolName, ResourcePool.class, appInfo);
            } else if (jndiName.startsWith(ConnectorConstants.JAVA_MODULE_SCOPE_PREFIX)) {
                pool = getModuleScopedResource(poolName, moduleName, ResourcePool.class, appInfo);
            } else {
                pool = ConnectorsUtil.getResourceByName(getResources(), ResourcePool.class, poolName);
            }
            if (ConnectorConnectionPool.class.isAssignableFrom(pool.getClass())) {
                String raName = ((ConnectorConnectionPool) pool).getResourceAdapterName();
                app.addResourceAdapter(raName);
            }
        } else if (AdminObjectResource.class.isAssignableFrom(res.getClass())) {
            String raName = ((AdminObjectResource) res).getResAdapter();
            app.addResourceAdapter(raName);
        }
    } else {
        boolean found = false;
        // detect sun-ra.xml
        // find all the standalone connector modules
        List<com.sun.enterprise.config.serverbeans.Application> applications = getApplications().getApplicationsWithSnifferType(com.sun.enterprise.config.serverbeans.ServerTags.CONNECTOR, true);
        Iterator itr = applications.iterator();
        while (itr.hasNext()) {
            com.sun.enterprise.config.serverbeans.Application application = (com.sun.enterprise.config.serverbeans.Application) itr.next();
            String appName = application.getName();
            ApplicationInfo appInfo = appRegistry.get(appName);
            if (appInfo == null) {
                // the app is not deployed on this node
                continue;
            }
            Application dolApp = appInfo.getMetaData(Application.class);
            Collection<ConnectorDescriptor> rarDescriptors = dolApp.getBundleDescriptors(ConnectorDescriptor.class);
            for (ConnectorDescriptor desc : rarDescriptors) {
                SunConnector sunraDesc = desc.getSunDescriptor();
                if (sunraDesc != null) {
                    String sunRAJndiName = (String) sunraDesc.getResourceAdapter().getValue(ResourceAdapter.JNDI_NAME);
                    if (jndiName.equals(sunRAJndiName)) {
                        app.addResourceAdapter(desc.getName());
                        found = true;
                        break;
                    }
                } else {
                    // check whether it is default resource in the connector
                    if (desc.getDefaultResourcesNames().contains(jndiName)) {
                        app.addResourceAdapter(desc.getName());
                        found = true;
                        break;
                    }
                }
            }
        }
        if (!found) {
            if (DOLUtils.getDefaultLogger().isLoggable(Level.FINEST)) {
                DOLUtils.getDefaultLogger().log(Level.FINEST, "could not find resource by name : " + jndiName);
            }
        }
    }
}
Also used : ConnectorConnectionPool(org.glassfish.connectors.config.ConnectorConnectionPool) AdminObjectResource(org.glassfish.connectors.config.AdminObjectResource) Resource(com.sun.enterprise.config.serverbeans.Resource) BindableResource(com.sun.enterprise.config.serverbeans.BindableResource) ConnectorResource(org.glassfish.connectors.config.ConnectorResource) ApplicationInfo(org.glassfish.internal.data.ApplicationInfo) ResourcePool(com.sun.enterprise.config.serverbeans.ResourcePool) ConnectorDescriptor(com.sun.enterprise.deployment.ConnectorDescriptor) BindableResource(com.sun.enterprise.config.serverbeans.BindableResource) Iterator(java.util.Iterator) SunConnector(com.sun.enterprise.deployment.runtime.connector.SunConnector) AdminObjectResource(org.glassfish.connectors.config.AdminObjectResource) Application(com.sun.enterprise.deployment.Application) ConnectorResource(org.glassfish.connectors.config.ConnectorResource)

Example 18 with Application

use of com.sun.enterprise.deployment.Application in project Payara by payara.

the class DOLUtils method isRAConnectionFactory.

/**
 * Returns true if there is a resource connection definition of the type with the application
 * @param habitat
 * @param type
 * @param thisApp
 * @return
 */
public static boolean isRAConnectionFactory(ServiceLocator habitat, String type, Application thisApp) {
    // adapter in this application
    if (isRAConnectionFactory(type, thisApp)) {
        return true;
    }
    // then check if this is a connection factory defined in a standalone
    // resource adapter
    Applications applications = habitat.getService(Applications.class);
    if (applications != null) {
        List<com.sun.enterprise.config.serverbeans.Application> raApps = applications.getApplicationsWithSnifferType(com.sun.enterprise.config.serverbeans.ServerTags.CONNECTOR, true);
        ApplicationRegistry appRegistry = habitat.getService(ApplicationRegistry.class);
        for (com.sun.enterprise.config.serverbeans.Application raApp : raApps) {
            ApplicationInfo appInfo = appRegistry.get(raApp.getName());
            if (appInfo == null)
                continue;
            if (isRAConnectionFactory(type, appInfo.getMetaData(Application.class))) {
                return true;
            }
        }
    }
    return false;
}
Also used : ApplicationRegistry(org.glassfish.internal.data.ApplicationRegistry) Applications(com.sun.enterprise.config.serverbeans.Applications) ApplicationInfo(org.glassfish.internal.data.ApplicationInfo) Application(com.sun.enterprise.deployment.Application)

Example 19 with Application

use of com.sun.enterprise.deployment.Application in project Payara by payara.

the class DOLUtils method getCurrentBundleForContext.

/**
 * Gets the associated descriptor with the context
 * @param context
 * @return null if there is no associated application
 */
public static BundleDescriptor getCurrentBundleForContext(DeploymentContext context) {
    ExtendedDeploymentContext ctx = (ExtendedDeploymentContext) context;
    Application application = context.getModuleMetaData(Application.class);
    // this can happen for non-JavaEE type deployment. e.g., issue 15869
    if (application == null)
        return null;
    if (ctx.getParentContext() == null) {
        if (application.isVirtual()) {
            // standalone module
            return application.getStandaloneBundleDescriptor();
        } else {
            // top level
            return application;
        }
    } else {
        // a sub module of ear
        return application.getModuleByUri(ctx.getModuleUri());
    }
}
Also used : ExtendedDeploymentContext(org.glassfish.internal.deployment.ExtendedDeploymentContext) Application(com.sun.enterprise.deployment.Application)

Example 20 with Application

use of com.sun.enterprise.deployment.Application in project Payara by payara.

the class DOLUtils method getApplicationFromEnv.

/**
 * @param env
 * @return
 */
public static Application getApplicationFromEnv(JndiNameEnvironment env) {
    Application app = null;
    if (env instanceof EjbDescriptor) {
        // EJB component
        EjbDescriptor ejbEnv = (EjbDescriptor) env;
        app = ejbEnv.getApplication();
    } else if (env instanceof EjbBundleDescriptor) {
        EjbBundleDescriptor ejbBundle = (EjbBundleDescriptor) env;
        app = ejbBundle.getApplication();
    } else if (env instanceof WebBundleDescriptor) {
        WebBundleDescriptor webEnv = (WebBundleDescriptor) env;
        app = webEnv.getApplication();
    } else if (env instanceof ApplicationClientDescriptor) {
        ApplicationClientDescriptor appEnv = (ApplicationClientDescriptor) env;
        app = appEnv.getApplication();
    } else if (env instanceof ManagedBeanDescriptor) {
        ManagedBeanDescriptor mb = (ManagedBeanDescriptor) env;
        app = mb.getBundle().getApplication();
    } else if (env instanceof Application) {
        app = ((Application) env);
    } else {
        throw new IllegalArgumentException("IllegalJndiNameEnvironment : env");
    }
    return app;
}
Also used : EjbBundleDescriptor(com.sun.enterprise.deployment.EjbBundleDescriptor) WebBundleDescriptor(com.sun.enterprise.deployment.WebBundleDescriptor) ApplicationClientDescriptor(com.sun.enterprise.deployment.ApplicationClientDescriptor) ManagedBeanDescriptor(com.sun.enterprise.deployment.ManagedBeanDescriptor) Application(com.sun.enterprise.deployment.Application) EjbDescriptor(com.sun.enterprise.deployment.EjbDescriptor)

Aggregations

Application (com.sun.enterprise.deployment.Application)66 BundleDescriptor (com.sun.enterprise.deployment.BundleDescriptor)17 WebBundleDescriptor (com.sun.enterprise.deployment.WebBundleDescriptor)10 DeployCommandParameters (org.glassfish.api.deployment.DeployCommandParameters)10 ApplicationInfo (org.glassfish.internal.data.ApplicationInfo)10 IOException (java.io.IOException)9 File (java.io.File)8 ModuleDescriptor (org.glassfish.deployment.common.ModuleDescriptor)8 EjbBundleDescriptor (com.sun.enterprise.deployment.EjbBundleDescriptor)7 ReadableArchive (org.glassfish.api.deployment.archive.ReadableArchive)7 EjbDescriptor (com.sun.enterprise.deployment.EjbDescriptor)5 DeploymentException (org.glassfish.deployment.common.DeploymentException)5 SAXParseException (org.xml.sax.SAXParseException)5 ApplicationClientDescriptor (com.sun.enterprise.deployment.ApplicationClientDescriptor)4 ArrayList (java.util.ArrayList)4 WebappClassLoader (org.glassfish.web.loader.WebappClassLoader)4 OpsParams (org.glassfish.api.deployment.OpsParams)3 EjbBundleDescriptorImpl (org.glassfish.ejb.deployment.descriptor.EjbBundleDescriptorImpl)3 Applications (com.sun.enterprise.config.serverbeans.Applications)2 WebComponentDescriptor (com.sun.enterprise.deployment.WebComponentDescriptor)2