Search in sources :

Example 11 with ModuleDescriptor

use of org.glassfish.deployment.common.ModuleDescriptor 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 12 with ModuleDescriptor

use of org.glassfish.deployment.common.ModuleDescriptor in project Payara by payara.

the class ApplicationValidator method accept.

/**
 * visit an application object
 * @param application the application descriptor
 */
@Override
public void accept(Application application) {
    this.application = application;
    if (application.getBundleDescriptors().size() == 0) {
        throw new IllegalArgumentException("Application [" + application.getRegistrationName() + "] contains no valid components");
    }
    // now resolve any conflicted module names in the application
    // list to store the current conflicted modules
    List<ModuleDescriptor> conflicted = new ArrayList<ModuleDescriptor>();
    // make sure all the modules have unique names
    Set<ModuleDescriptor<BundleDescriptor>> modules = application.getModules();
    for (ModuleDescriptor module : modules) {
        // no need to process it again
        if (conflicted.contains(module)) {
            continue;
        }
        boolean foundConflictedModule = false;
        for (ModuleDescriptor module2 : modules) {
            // no need to process it again
            if (conflicted.contains(module2)) {
                continue;
            }
            if (!module.equals(module2) && module.getModuleName().equals(module2.getModuleName())) {
                conflicted.add(module2);
                foundConflictedModule = true;
            }
        }
        if (foundConflictedModule) {
            conflicted.add(module);
        }
    }
    // make the names unique
    for (ModuleDescriptor cModule : conflicted) {
        cModule.setModuleName(cModule.getModuleName() + cModule.getModuleType().toString());
    }
}
Also used : ModuleDescriptor(org.glassfish.deployment.common.ModuleDescriptor) ArrayList(java.util.ArrayList)

Example 13 with ModuleDescriptor

use of org.glassfish.deployment.common.ModuleDescriptor in project Payara by payara.

the class ModuleContentLinker method accept.

public void accept(ServiceReferenceDescriptor serviceRef) {
    try {
        ModuleDescriptor moduleDesc = serviceRef.getBundleDescriptor().getModuleDescriptor();
        if (serviceRef.hasWsdlFile()) {
            String wsdlFileUri = serviceRef.getWsdlFileUri();
            File tmpFile = new File(wsdlFileUri);
            if (tmpFile.isAbsolute()) {
                // This takes care of the case when we set wsdlFileUri from generated @WebClient
                // and the uri is an absolute path
                serviceRef.setWsdlFileUrl(tmpFile.toURI().toURL());
            } else {
                // If the given WSDL is an http URL, create a URL directly from this
                if (wsdlFileUri.startsWith("http")) {
                    serviceRef.setWsdlFileUrl(new URL(wsdlFileUri));
                } else {
                    // Given WSDL location is a relative path - append this to the module dir
                    URL wsdlFileUrl = internalGetUrl(moduleDesc, wsdlFileUri);
                    serviceRef.setWsdlFileUrl(wsdlFileUrl);
                }
            }
        } else {
            // Incase wsdl file is missing we can obtain it from the @WebServiceClient annotation
            ClassLoader classloader = Thread.currentThread().getContextClassLoader();
            Class serviceInterfaceClass = classloader.loadClass(serviceRef.getServiceInterface());
            WSDolSupport dolSupport = Globals.getDefaultHabitat().getService(WSDolSupport.class);
            if (dolSupport != null) {
                dolSupport.setServiceRef(serviceInterfaceClass, serviceRef);
            }
        }
        if (serviceRef.hasMappingFile()) {
            String mappingFileUri = serviceRef.getMappingFileUri();
            File mappingFile = new File(getModuleLocation(moduleDesc), mappingFileUri);
            serviceRef.setMappingFile(mappingFile);
        }
    } catch (java.net.MalformedURLException mex) {
        DOLUtils.getDefaultLogger().log(Level.SEVERE, "enterprise.deployment.backend.invalidWsdlURL", new Object[] { serviceRef.getWsdlFileUri() });
    } catch (Exception e) {
        DOLUtils.getDefaultLogger().log(Level.SEVERE, DOLUtils.INVALID_DESC_MAPPING, new Object[] { serviceRef.getName(), rootLocation_ });
    }
}
Also used : ModuleDescriptor(org.glassfish.deployment.common.ModuleDescriptor) MalformedURLException(java.net.MalformedURLException) WSDolSupport(com.sun.enterprise.deployment.WSDolSupport) File(java.io.File) URL(java.net.URL) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException)

Example 14 with ModuleDescriptor

use of org.glassfish.deployment.common.ModuleDescriptor in project Payara by payara.

the class ModuleContentLinker method accept.

public void accept(WebService webService) {
    try {
        ModuleDescriptor moduleDesc = webService.getBundleDescriptor().getModuleDescriptor();
        // already assigned or if URLs are forced to be assigned.
        if (webService.hasWsdlFile() && (webService.getWsdlFileUrl() == null || forceWSDLURLs)) {
            String wsdlFileUri = webService.getWsdlFileUri();
            URL wsdlFileURL = null;
            try {
                URL url = new URL(wsdlFileUri);
                if (url.getProtocol() != null && !url.getProtocol().equalsIgnoreCase("file")) {
                    wsdlFileURL = url;
                }
            } catch (java.net.MalformedURLException e) {
            // ignore, it could just be a relate URI
            }
            if (wsdlFileURL == null) {
                File wsdlFile = new File(getModuleLocation(moduleDesc), wsdlFileUri);
                wsdlFileURL = wsdlFile.toURI().toURL();
            }
            webService.setWsdlFileUrl(wsdlFileURL);
        }
        if (webService.hasMappingFile()) {
            String mappingFileUri = webService.getMappingFileUri();
            File mappingFile = new File(getModuleLocation(moduleDesc), mappingFileUri);
            webService.setMappingFile(mappingFile);
        }
    } catch (Exception e) {
        DOLUtils.getDefaultLogger().log(Level.SEVERE, DOLUtils.INVALID_DESC_MAPPING, new Object[] { webService.getName(), rootLocation_ });
    }
}
Also used : ModuleDescriptor(org.glassfish.deployment.common.ModuleDescriptor) MalformedURLException(java.net.MalformedURLException) File(java.io.File) URL(java.net.URL) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException)

Example 15 with ModuleDescriptor

use of org.glassfish.deployment.common.ModuleDescriptor in project Payara by payara.

the class ApplicationArchivist method readModulesDescriptors.

/**
 * read the modules deployment descriptor from this application object using the passed archive
 *
 * @param app
 *            application containing the list of modules.
 * @param appArchive
 *            containing the sub modules files.
 * @return true if everything went fine
 */
public boolean readModulesDescriptors(Application app, ReadableArchive appArchive) throws IOException, SAXParseException {
    List<ModuleDescriptor> nonexistentModules = new ArrayList<ModuleDescriptor>();
    List<ModuleDescriptor> sortedModules = sortModules(app);
    for (ModuleDescriptor aModule : sortedModules) {
        if (aModule.getArchiveUri().indexOf(" ") != -1) {
            throw new IllegalArgumentException(localStrings.getLocalString("enterprise.deployment.unsupporturi", "Unsupported module URI {0}, it contains space(s)", new Object[] { aModule.getArchiveUri() }));
        }
        if (getDefaultLogger().isLoggable(FINE)) {
            getDefaultLogger().fine("Opening sub-module " + aModule);
        }
        BundleDescriptor descriptor = null;
        Archivist newArchivist = archivistFactory.get().getArchivist(aModule.getModuleType());
        newArchivist.initializeContext(this);
        newArchivist.setRuntimeXMLValidation(this.getRuntimeXMLValidation());
        newArchivist.setRuntimeXMLValidationLevel(this.getRuntimeXMLValidationLevel());
        newArchivist.setAnnotationProcessingRequested(annotationProcessingRequested);
        ReadableArchive embeddedArchive = appArchive.getSubArchive(aModule.getArchiveUri());
        if (embeddedArchive == null) {
            throw new IllegalArgumentException(localStrings.getLocalString("enterprise.deployment.nosuchmodule", "Could not find sub module [{0}] as defined in application.xml", new Object[] { aModule.getArchiveUri() }));
        }
        embeddedArchive.setParentArchive(appArchive);
        setExtensionArchivistForSubArchivist(habitat, embeddedArchive, aModule, app, newArchivist);
        if (aModule.getAlternateDescriptor() != null) {
            // The module use alternate deployement descriptor, ignore the DDs in the archive.
            InputStream is = appArchive.getEntry(aModule.getAlternateDescriptor());
            DeploymentDescriptorFile ddFile = newArchivist.getStandardDDFile();
            ddFile.setXMLValidation(newArchivist.getXMLValidation());
            ddFile.setXMLValidationLevel(newArchivist.getXMLValidationLevel());
            if (appArchive.getURI() != null) {
                ddFile.setErrorReportingString(appArchive.getURI().getSchemeSpecificPart());
            }
            descriptor = (BundleDescriptor) ddFile.read(is);
            descriptor.setApplication(app);
            is.close();
            // TODO : JD need to be revisited for EAR files with Alternative descriptors, what does
            // it mean for sub components.
            Map<ExtensionsArchivist, RootDeploymentDescriptor> extensions = new HashMap<ExtensionsArchivist, RootDeploymentDescriptor>();
            List<ExtensionsArchivist> extensionsArchivists = newArchivist.getExtensionArchivists();
            if (extensionsArchivists != null) {
                for (ExtensionsArchivist extension : extensionsArchivists) {
                    Object rdd = extension.open(newArchivist, embeddedArchive, descriptor);
                    if (rdd instanceof RootDeploymentDescriptor) {
                        extensions.put(extension, (RootDeploymentDescriptor) rdd);
                    }
                }
            }
            newArchivist.postStandardDDsRead(descriptor, embeddedArchive, extensions);
            newArchivist.readAnnotations(embeddedArchive, descriptor, extensions);
            newArchivist.postAnnotationProcess(descriptor, embeddedArchive);
            newArchivist.postOpen(descriptor, embeddedArchive);
            // Now reads the runtime deployment descriptor...
            if (isHandlingRuntimeInfo()) {
                readAlternativeRuntimeDescriptor(appArchive, embeddedArchive, newArchivist, descriptor, aModule.getAlternateDescriptor());
                // Read extensions runtime deployment descriptors if any
                for (Map.Entry<ExtensionsArchivist, RootDeploymentDescriptor> extension : extensions.entrySet()) {
                    // After standard DD and annotations are processed we should have an extension descriptor now
                    if (extension.getValue() != null) {
                        extension.getKey().readRuntimeDeploymentDescriptor(newArchivist, embeddedArchive, extension.getValue());
                    }
                }
            }
        } else {
            // Open the subarchive to get the deployment descriptor...
            descriptor = newArchivist.open(embeddedArchive, app);
        }
        embeddedArchive.close();
        if (descriptor != null) {
            descriptor.getModuleDescriptor().setArchiveUri(aModule.getArchiveUri());
            aModule.setModuleName(descriptor.getModuleDescriptor().getModuleName());
            aModule.setDescriptor(descriptor);
            descriptor.setApplication(app);
            aModule.setManifest(newArchivist.getManifest());
            // For optional application.xml case, set the context root as module name for web modules
            if (!appArchive.exists("META-INF/application.xml")) {
                if (aModule.getModuleType().equals(DOLUtils.warType())) {
                    WebBundleDescriptor wbd = (WebBundleDescriptor) descriptor;
                    if (wbd.getContextRoot() != null && !wbd.getContextRoot().equals("")) {
                        aModule.setContextRoot(wbd.getContextRoot());
                    } else {
                        aModule.setContextRoot(aModule.getModuleName());
                    }
                }
            }
        } else {
            // Display a message only if we had a handle on the sub archive
            return false;
        }
    }
    // don't get processed further
    for (ModuleDescriptor nonexistentModule : nonexistentModules) {
        app.removeModule(nonexistentModule);
    }
    return true;
}
Also used : DOLUtils.setExtensionArchivistForSubArchivist(com.sun.enterprise.deployment.util.DOLUtils.setExtensionArchivistForSubArchivist) HashMap(java.util.HashMap) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) DeploymentDescriptorFile(com.sun.enterprise.deployment.io.DeploymentDescriptorFile) ApplicationDeploymentDescriptorFile(com.sun.enterprise.deployment.io.ApplicationDeploymentDescriptorFile) ConfigurationDeploymentDescriptorFile(com.sun.enterprise.deployment.io.ConfigurationDeploymentDescriptorFile) ModuleDescriptor(org.glassfish.deployment.common.ModuleDescriptor) BundleDescriptor(com.sun.enterprise.deployment.BundleDescriptor) WebBundleDescriptor(com.sun.enterprise.deployment.WebBundleDescriptor) RootDeploymentDescriptor(org.glassfish.deployment.common.RootDeploymentDescriptor) WebBundleDescriptor(com.sun.enterprise.deployment.WebBundleDescriptor) ReadableArchive(org.glassfish.api.deployment.archive.ReadableArchive) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

ModuleDescriptor (org.glassfish.deployment.common.ModuleDescriptor)44 BundleDescriptor (com.sun.enterprise.deployment.BundleDescriptor)13 Application (com.sun.enterprise.deployment.Application)8 ReadableArchive (org.glassfish.api.deployment.archive.ReadableArchive)7 WebBundleDescriptor (com.sun.enterprise.deployment.WebBundleDescriptor)6 RootDeploymentDescriptor (org.glassfish.deployment.common.RootDeploymentDescriptor)6 DOLUtils.setExtensionArchivistForSubArchivist (com.sun.enterprise.deployment.util.DOLUtils.setExtensionArchivistForSubArchivist)5 File (java.io.File)5 IOException (java.io.IOException)5 ArrayList (java.util.ArrayList)5 EjbBundleDescriptor (com.sun.enterprise.deployment.EjbBundleDescriptor)4 InputStream (java.io.InputStream)4 ApplicationDeploymentDescriptorFile (com.sun.enterprise.deployment.io.ApplicationDeploymentDescriptorFile)3 ConfigurationDeploymentDescriptorFile (com.sun.enterprise.deployment.io.ConfigurationDeploymentDescriptorFile)3 DeploymentDescriptorFile (com.sun.enterprise.deployment.io.DeploymentDescriptorFile)3 FileArchive (com.sun.enterprise.deploy.shared.FileArchive)2 MalformedURLException (java.net.MalformedURLException)2 URL (java.net.URL)2 Enumeration (java.util.Enumeration)2 Vector (java.util.Vector)2