Search in sources :

Example 1 with Archivist

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

the class WebArchivist method readStandardFragments.

/**
 * This method will return the list of web fragment in the desired order.
 */
private List<WebFragmentDescriptor> readStandardFragments(WebBundleDescriptorImpl descriptor, ReadableArchive archive) throws IOException {
    List<WebFragmentDescriptor> wfList = new ArrayList<WebFragmentDescriptor>();
    Vector libs = getLibraries(archive);
    if (libs != null && libs.size() > 0) {
        for (int i = 0; i < libs.size(); i++) {
            String lib = (String) libs.get(i);
            Archivist wfArchivist = new WebFragmentArchivist(this, habitat);
            wfArchivist.setRuntimeXMLValidation(this.getRuntimeXMLValidation());
            wfArchivist.setRuntimeXMLValidationLevel(this.getRuntimeXMLValidationLevel());
            wfArchivist.setAnnotationProcessingRequested(false);
            WebFragmentDescriptor wfDesc = null;
            ReadableArchive embeddedArchive = archive.getSubArchive(lib);
            try {
                if (embeddedArchive != null && wfArchivist.hasStandardDeploymentDescriptor(embeddedArchive)) {
                    try {
                        wfDesc = (WebFragmentDescriptor) wfArchivist.open(embeddedArchive);
                    } catch (SAXParseException ex) {
                        IOException ioex = new IOException();
                        ioex.initCause(ex);
                        throw ioex;
                    }
                } else {
                    wfDesc = new WebFragmentDescriptor();
                    wfDesc.setExists(false);
                }
            } finally {
                if (embeddedArchive != null) {
                    embeddedArchive.close();
                }
            }
            wfDesc.setJarName(lib.substring(lib.lastIndexOf('/') + 1));
            wfList.add(wfDesc);
            descriptor.putJarNameWebFragmentNamePair(wfDesc.getJarName(), wfDesc.getName());
        }
        if (((WebBundleDescriptorImpl) descriptor).getAbsoluteOrderingDescriptor() != null) {
            wfList = ((WebBundleDescriptorImpl) descriptor).getAbsoluteOrderingDescriptor().order(wfList);
        } else {
            OrderingDescriptor.sort(wfList);
        }
        for (WebFragmentDescriptor wf : wfList) {
            descriptor.addOrderedLib(wf.getJarName());
        }
    }
    return wfList;
}
Also used : Archivist(com.sun.enterprise.deployment.archivist.Archivist) ExtensionsArchivist(com.sun.enterprise.deployment.archivist.ExtensionsArchivist) SAXParseException(org.xml.sax.SAXParseException) ArrayList(java.util.ArrayList) IOException(java.io.IOException) ReadableArchive(org.glassfish.api.deployment.archive.ReadableArchive) Vector(java.util.Vector)

Example 2 with Archivist

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

the class WebServicesDeployer method copyExtraFilesToGeneratedFolder.

/**
 * This is to be used for file publishing only. In case of wsdlImports and wsdlIncludes
 * we need to copy the nested wsdls from applications folder to the generated/xml folder
 */
private void copyExtraFilesToGeneratedFolder(DeploymentContext context) throws IOException {
    Archivist archivist = habitat.getService(Archivist.class);
    ReadableArchive archive = archiveFactory.openArchive(context.getSourceDir());
    WritableArchive archive2 = archiveFactory.createArchive(context.getScratchDir("xml"));
    // copy the additional webservice elements etc
    archivist.copyExtraElements(archive, archive2);
}
Also used : Archivist(com.sun.enterprise.deployment.archivist.Archivist) ReadableArchive(org.glassfish.api.deployment.archive.ReadableArchive) WritableArchive(org.glassfish.api.deployment.archive.WritableArchive)

Example 3 with Archivist

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

the class RegistrationSupport method getDeploymentDescriptor.

private String getDeploymentDescriptor(final BundleDescriptor bundleDesc) {
    final ArchivistFactory archivistFactory = J2EEInjectedValues.getInstance().getArchivistFactory();
    String dd = "unavailable";
    ByteArrayOutputStream out = null;
    try {
        final Archivist moduleArchivist = archivistFactory.getArchivist(bundleDesc.getModuleDescriptor().getModuleType());
        final DeploymentDescriptorFile ddFile = moduleArchivist.getStandardDDFile();
        out = new ByteArrayOutputStream();
        ddFile.write(bundleDesc, out);
        final String charsetName = "UTF-8";
        dd = out.toString(charsetName);
    } catch (final Exception e) {
        dd = null;
    } finally {
        if (out != null) {
            try {
                out.close();
            } catch (Exception ee) {
            }
        }
    }
    return dd;
}
Also used : Archivist(com.sun.enterprise.deployment.archivist.Archivist) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DeploymentDescriptorFile(com.sun.enterprise.deployment.io.DeploymentDescriptorFile) ArchivistFactory(com.sun.enterprise.deployment.archivist.ArchivistFactory)

Example 4 with Archivist

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

the class DescriptorFactory method createApplicationDescriptor.

/**
 * Returns the parsed DOL object from archive
 *
 * @param archiveFile original archive file
 * @param destRootDir root destination directory where the application
 *        should be expanded under in case of archive deployment
 * @param parentCl parent classloader
 *
 * @return the parsed DOL object
 */
public ResultHolder createApplicationDescriptor(File archiveFile, File destRootDir, ClassLoader parentCl) throws IOException {
    ReadableArchive archive = null;
    Application application = null;
    try {
        Descriptor.setBoundsChecking(false);
        archive = archiveFactory.openArchive(archiveFile);
        ArchiveHandler archiveHandler = deployment.getArchiveHandler(archive);
        ActionReport dummyReport = new HTMLActionReporter();
        String appName = DeploymentUtils.getDefaultEEName(archiveFile.getName());
        DeployCommandParameters params = new DeployCommandParameters();
        params.name = appName;
        ExtendedDeploymentContext context = new DeploymentContextImpl(dummyReport, archive, params, env);
        context.setArchiveHandler(archiveHandler);
        if (!archiveFile.isDirectory()) {
            // expand archive
            File destDir = new File(destRootDir, appName);
            if (destDir.exists()) {
                FileUtils.whack(destDir);
            }
            destDir.mkdirs();
            archiveHandler.expand(archive, archiveFactory.createArchive(destDir), context);
            archive.close();
            archive = archiveFactory.openArchive(destDir);
            context.setSource(archive);
        }
        // issue 14564
        context.addTransientAppMetaData(ExtendedDeploymentContext.IS_TEMP_CLASSLOADER, Boolean.TRUE);
        String archiveType = context.getArchiveHandler().getArchiveType();
        ClassLoader cl = archiveHandler.getClassLoader(parentCl, context);
        Archivist archivist = archivistFactory.getArchivist(archiveType, cl);
        if (archivist == null) {
            throw new IOException("Cannot determine the Java EE module type for " + archive.getURI());
        }
        archivist.setAnnotationProcessingRequested(true);
        String xmlValidationLevel = dasConfig.getDeployXmlValidation();
        archivist.setXMLValidationLevel(xmlValidationLevel);
        if (xmlValidationLevel.equals("none")) {
            archivist.setXMLValidation(false);
        }
        archivist.setRuntimeXMLValidation(false);
        try {
            application = applicationFactory.openArchive(appName, archivist, archive, true);
        } catch (SAXParseException e) {
            throw new IOException(e);
        }
        if (application != null) {
            application.setClassLoader(cl);
            application.visit((ApplicationVisitor) new ApplicationValidator());
        }
    } finally {
        if (archive != null) {
            archive.close();
        }
        // We need to reset it after descriptor building
        Descriptor.setBoundsChecking(true);
    }
    ResultHolder result = new ResultHolder();
    result.application = application;
    result.archive = archive;
    return result;
}
Also used : ArchiveHandler(org.glassfish.api.deployment.archive.ArchiveHandler) Archivist(com.sun.enterprise.deployment.archivist.Archivist) IOException(java.io.IOException) ActionReport(org.glassfish.api.ActionReport) ExtendedDeploymentContext(org.glassfish.internal.deployment.ExtendedDeploymentContext) DeploymentContextImpl(org.glassfish.deployment.common.DeploymentContextImpl) DeployCommandParameters(org.glassfish.api.deployment.DeployCommandParameters) ApplicationValidator(com.sun.enterprise.deployment.util.ApplicationValidator) SAXParseException(org.xml.sax.SAXParseException) HTMLActionReporter(com.sun.enterprise.v3.common.HTMLActionReporter) ReadableArchive(org.glassfish.api.deployment.archive.ReadableArchive) Application(com.sun.enterprise.deployment.Application) File(java.io.File)

Example 5 with Archivist

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

the class UndeployedLaunchable method newUndeployedLaunchable.

static UndeployedLaunchable newUndeployedLaunchable(final ServiceLocator habitat, final ReadableArchive ra, final String callerSuppliedMainClassName, final String callerSuppliedAppName, final ClassLoader classLoader) throws IOException, SAXParseException, UserError {
    ArchivistFactory af = Util.getArchivistFactory();
    /*
         * Try letting the factory decide what type of archive this is.  That
         * will often allow an app client or an EAR archive to be detected
         * automatically.
         */
    Archivist archivist = af.getArchivist(ModuleType.CAR.toString(), classLoader);
    if (archivist == null) {
        throw new UserError(localStrings.get("appclient.invalidArchive", ra.getURI().toASCIIString()));
    }
    final ArchiveType moduleType = archivist.getModuleType();
    if (moduleType != null && moduleType.equals(DOLUtils.carType())) {
        return new UndeployedLaunchable(habitat, ra, (AppClientArchivist) archivist, callerSuppliedMainClassName);
    } else if (moduleType != null && moduleType.equals(DOLUtils.earType())) {
        /*
             * Locate the app client submodule that matches the main class name
             * or the app client name.
             */
        Application app = (Application) archivist.open(ra);
        for (ModuleDescriptor<BundleDescriptor> md : app.getModules()) {
            if (!md.getModuleType().equals(DOLUtils.carType())) {
                continue;
            }
            ApplicationClientDescriptor acd = (ApplicationClientDescriptor) md.getDescriptor();
            final String displayName = acd.getDisplayName();
            final String appName = acd.getModuleID();
            ArchiveFactory archiveFactory = Util.getArchiveFactory();
            ReadableArchive clientRA = archiveFactory.openArchive(ra.getURI().resolve(md.getArchiveUri()));
            /*
                 * Choose this nested app client if the caller-supplied name
                 * matches, or if the caller-supplied main class matches, or
                 * if neither was provided.  
                 */
            final boolean useThisClient = (displayName != null && displayName.equals(callerSuppliedAppName)) || (appName != null && appName.equals(callerSuppliedAppName)) || (callerSuppliedMainClassName != null && clientRA.exists(classToResource(callerSuppliedMainClassName)) || (callerSuppliedAppName == null && callerSuppliedMainClassName == null));
            if (useThisClient) {
                return new UndeployedLaunchable(habitat, clientRA, acd, callerSuppliedMainClassName);
            }
            clientRA.close();
        }
        throw new UserError(localStrings.get("appclient.noMatchingClientInEAR", ra.getURI(), callerSuppliedMainClassName, callerSuppliedAppName));
    } else {
        /*
             * There is a possibility that the user is trying to launch an
             * archive that is more than one type of archive: such as an EJB
             * but also an app client (because the manifest identifies a main
             * class, for example).
             *
             * Earlier the archivist factory might have returned the other type
             * of archivist - such as the EJB archivist.  Now see if the app
             * client archivist will work when selected directly.
             */
        archivist = af.getArchivist(DOLUtils.carType());
        /*
             * Try to open the archive as an app client archive just to see
             * if it works.
             */
        RootDeploymentDescriptor tempACD = archivist.open(ra);
        if (tempACD != null && tempACD instanceof ApplicationClientDescriptor) {
            /*
                 * Start with a fresh archivist - unopened - so we can request
                 * anno processing, etc. before opening it for real.
                 */
            archivist = af.getArchivist(DOLUtils.carType());
            return new UndeployedLaunchable(habitat, ra, (AppClientArchivist) archivist, callerSuppliedMainClassName);
        }
        throw new UserError(localStrings.get("appclient.unexpectedArchive", ra.getURI()));
    }
}
Also used : ArchiveFactory(com.sun.enterprise.deploy.shared.ArchiveFactory) AppClientArchivist(com.sun.enterprise.deployment.archivist.AppClientArchivist) Archivist(com.sun.enterprise.deployment.archivist.Archivist) ArchiveType(org.glassfish.api.deployment.archive.ArchiveType) ApplicationClientDescriptor(com.sun.enterprise.deployment.ApplicationClientDescriptor) AppClientArchivist(com.sun.enterprise.deployment.archivist.AppClientArchivist) ArchivistFactory(com.sun.enterprise.deployment.archivist.ArchivistFactory) ModuleDescriptor(org.glassfish.deployment.common.ModuleDescriptor) RootDeploymentDescriptor(org.glassfish.deployment.common.RootDeploymentDescriptor) ReadableArchive(org.glassfish.api.deployment.archive.ReadableArchive) Application(com.sun.enterprise.deployment.Application)

Aggregations

Archivist (com.sun.enterprise.deployment.archivist.Archivist)6 ReadableArchive (org.glassfish.api.deployment.archive.ReadableArchive)4 Application (com.sun.enterprise.deployment.Application)2 AppClientArchivist (com.sun.enterprise.deployment.archivist.AppClientArchivist)2 ArchivistFactory (com.sun.enterprise.deployment.archivist.ArchivistFactory)2 IOException (java.io.IOException)2 SAXParseException (org.xml.sax.SAXParseException)2 ArchiveFactory (com.sun.enterprise.deploy.shared.ArchiveFactory)1 ApplicationClientDescriptor (com.sun.enterprise.deployment.ApplicationClientDescriptor)1 ExtensionsArchivist (com.sun.enterprise.deployment.archivist.ExtensionsArchivist)1 DeploymentDescriptorFile (com.sun.enterprise.deployment.io.DeploymentDescriptorFile)1 ApplicationValidator (com.sun.enterprise.deployment.util.ApplicationValidator)1 HTMLActionReporter (com.sun.enterprise.v3.common.HTMLActionReporter)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 Vector (java.util.Vector)1 ActionReport (org.glassfish.api.ActionReport)1 DeployCommandParameters (org.glassfish.api.deployment.DeployCommandParameters)1 ArchiveHandler (org.glassfish.api.deployment.archive.ArchiveHandler)1