Search in sources :

Example 46 with BundleDescriptor

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

the class ApplicationArchivist method getApplicationFromIntrospection.

/**
 * This method introspect an ear file and populate the Application object. We follow the Java EE platform specification,
 * Section EE.8.4.2 to determine the type of the modules included in this application.
 *
 * @param archive
 *            the archive representing the application root
 * @param directory
 *            whether this is a directory deployment
 */
private Application getApplicationFromIntrospection(ReadableArchive archive, boolean directory) {
    // archive is a directory
    String appRoot = archive.getURI().getSchemeSpecificPart();
    if (appRoot.endsWith(File.separator)) {
        appRoot = appRoot.substring(0, appRoot.length() - 1);
    }
    Application app = Application.createApplication();
    app.setLoadedFromApplicationXml(false);
    app.setVirtual(false);
    // name of the file without its extension
    String appName = appRoot.substring(appRoot.lastIndexOf(File.separatorChar) + 1);
    app.setName(appName);
    List<ReadableArchive> unknowns = new ArrayList<ReadableArchive>();
    File[] files = getEligibleEntries(new File(appRoot), directory);
    for (File subModule : files) {
        ReadableArchive subArchive = null;
        try {
            try {
                subArchive = archiveFactory.openArchive(subModule);
            } catch (IOException ex) {
                logger.log(Level.WARNING, ex.getMessage());
            }
            // for archive deployment, we check the sub archives by its
            // file extension; for directory deployment, we check the sub
            // directories by its name. We are now supporting directory
            // names with both "_suffix" and ".suffix".
            // Section EE.8.4.2.1.a
            String name = subModule.getName();
            String uri = deriveArchiveUri(appRoot, subModule, directory);
            if ((!directory && name.endsWith(".war")) || (directory && (name.endsWith("_war") || name.endsWith(".war")))) {
                ModuleDescriptor<BundleDescriptor> md = new ModuleDescriptor<BundleDescriptor>();
                md.setArchiveUri(uri);
                md.setModuleType(DOLUtils.warType());
                // the context root will be set later after
                // we process the sub modules
                app.addModule(md);
            } else // Section EE.8.4.2.1.b
            if ((!directory && name.endsWith(".rar")) || (directory && (name.endsWith("_rar") || name.endsWith(".rar")))) {
                ModuleDescriptor<BundleDescriptor> md = new ModuleDescriptor<BundleDescriptor>();
                md.setArchiveUri(uri);
                md.setModuleType(DOLUtils.rarType());
                app.addModule(md);
            } else if ((!directory && name.endsWith(".jar")) || (directory && (name.endsWith("_jar") || name.endsWith(".jar")))) {
                try {
                    // Section EE.8.4.2.1.d.i
                    AppClientArchivist acArchivist = new AppClientArchivist();
                    if (acArchivist.hasStandardDeploymentDescriptor(subArchive) || acArchivist.hasRuntimeDeploymentDescriptor(subArchive) || acArchivist.getMainClassName(subArchive.getManifest()) != null) {
                        ModuleDescriptor<BundleDescriptor> md = new ModuleDescriptor<BundleDescriptor>();
                        md.setArchiveUri(uri);
                        md.setModuleType(DOLUtils.carType());
                        md.setManifest(subArchive.getManifest());
                        app.addModule(md);
                        continue;
                    }
                    // Section EE.8.4.2.1.d.ii
                    Archivist ejbArchivist = archivistFactory.get().getArchivist(DOLUtils.ejbType());
                    if (ejbArchivist.hasStandardDeploymentDescriptor(subArchive) || ejbArchivist.hasRuntimeDeploymentDescriptor(subArchive)) {
                        ModuleDescriptor<BundleDescriptor> md = new ModuleDescriptor<BundleDescriptor>();
                        md.setArchiveUri(uri);
                        md.setModuleType(DOLUtils.ejbType());
                        app.addModule(md);
                        continue;
                    }
                } catch (IOException ex) {
                    logger.log(Level.WARNING, ex.getMessage());
                }
                // Still could not decide between an ejb and a library
                unknowns.add(subArchive);
                // Prevent this unknown archive from being closed in the
                // finally block, because the same object will be used in
                // the block below where unknowns are checked one more time.
                subArchive = null;
            } else {
            // ignored
            }
        } finally {
            if (subArchive != null) {
                try {
                    subArchive.close();
                } catch (IOException ioe) {
                    logger.log(Level.WARNING, localStrings.getLocalString("enterprise.deployment.errorClosingSubArch", "Error closing subarchive {0}", new Object[] { subModule.getAbsolutePath() }), ioe);
                }
            }
        }
    }
    if (unknowns.size() > 0) {
        AnnotationDetector detector = new AnnotationDetector(new EjbComponentAnnotationScanner());
        for (int i = 0; i < unknowns.size(); i++) {
            File jarFile = new File(unknowns.get(i).getURI().getSchemeSpecificPart());
            try {
                if (detector.hasAnnotationInArchive(unknowns.get(i))) {
                    String uri = deriveArchiveUri(appRoot, jarFile, directory);
                    // Section EE.8.4.2.1.d.ii, alas EJB
                    ModuleDescriptor<BundleDescriptor> md = new ModuleDescriptor<BundleDescriptor>();
                    md.setArchiveUri(uri);
                    md.setModuleType(DOLUtils.ejbType());
                    app.addModule(md);
                }
                /*
                     * The subarchive was opened by the anno detector. Close it.
                     */
                unknowns.get(i).close();
            } catch (IOException ex) {
                logger.log(Level.WARNING, ex.getMessage());
            }
        }
    }
    return app;
}
Also used : DOLUtils.setExtensionArchivistForSubArchivist(com.sun.enterprise.deployment.util.DOLUtils.setExtensionArchivistForSubArchivist) EjbComponentAnnotationScanner(com.sun.enterprise.deployment.annotation.introspection.EjbComponentAnnotationScanner) ArrayList(java.util.ArrayList) IOException(java.io.IOException) AnnotationDetector(com.sun.enterprise.deployment.util.AnnotationDetector) BundleDescriptor(com.sun.enterprise.deployment.BundleDescriptor) WebBundleDescriptor(com.sun.enterprise.deployment.WebBundleDescriptor) ModuleDescriptor(org.glassfish.deployment.common.ModuleDescriptor) ReadableArchive(org.glassfish.api.deployment.archive.ReadableArchive) Application(com.sun.enterprise.deployment.Application) DeploymentDescriptorFile(com.sun.enterprise.deployment.io.DeploymentDescriptorFile) ApplicationDeploymentDescriptorFile(com.sun.enterprise.deployment.io.ApplicationDeploymentDescriptorFile) File(java.io.File) ConfigurationDeploymentDescriptorFile(com.sun.enterprise.deployment.io.ConfigurationDeploymentDescriptorFile)

Example 47 with BundleDescriptor

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

the class TracerVisitor method accept.

@Override
public void accept(BundleDescriptor descriptor) {
    if (descriptor instanceof Application) {
        Application application = (Application) descriptor;
        accept(application);
        for (BundleDescriptor ebd : application.getBundleDescriptorsOfType(DOLUtils.ejbType())) {
            ebd.visit(getSubDescriptorVisitor(ebd));
        }
        for (BundleDescriptor wbd : application.getBundleDescriptorsOfType(DOLUtils.warType())) {
            // the validation step from bombing.
            if (wbd != null) {
                wbd.visit(getSubDescriptorVisitor(wbd));
            }
        }
        for (BundleDescriptor cd : application.getBundleDescriptorsOfType(DOLUtils.rarType())) {
            cd.visit(getSubDescriptorVisitor(cd));
        }
        for (BundleDescriptor acd : application.getBundleDescriptorsOfType(DOLUtils.carType())) {
            acd.visit(getSubDescriptorVisitor(acd));
        }
        super.accept(descriptor);
    } else {
        super.accept(descriptor);
    }
}
Also used : BundleDescriptor(com.sun.enterprise.deployment.BundleDescriptor) Application(com.sun.enterprise.deployment.Application)

Example 48 with BundleDescriptor

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

the class GetContextRootCommand method execute.

/**
 * Entry point from the framework into the command execution
 * @param context context for the command.
 */
public void execute(AdminCommandContext context) {
    final ActionReport report = context.getActionReport();
    ActionReport.MessagePart part = report.getTopMessagePart();
    ApplicationInfo appInfo = appRegistry.get(appname);
    if (appInfo != null) {
        Application app = appInfo.getMetaData(Application.class);
        if (app != null) {
            // strip the version suffix (delimited by colon), if present
            int versionSuffix = modulename.indexOf(':');
            String versionLessModuleName = versionSuffix > 0 ? modulename.substring(0, versionSuffix) : modulename;
            BundleDescriptor bundleDesc = app.getModuleByUri(versionLessModuleName);
            if (bundleDesc != null && bundleDesc instanceof WebBundleDescriptor) {
                String contextRoot = ((WebBundleDescriptor) bundleDesc).getContextRoot();
                part.addProperty(DeploymentProperties.CONTEXT_ROOT, contextRoot);
                part.setMessage(contextRoot);
            }
        }
    }
}
Also used : WebBundleDescriptor(com.sun.enterprise.deployment.WebBundleDescriptor) BundleDescriptor(com.sun.enterprise.deployment.BundleDescriptor) ApplicationInfo(org.glassfish.internal.data.ApplicationInfo) WebBundleDescriptor(com.sun.enterprise.deployment.WebBundleDescriptor) ActionReport(org.glassfish.api.ActionReport) Application(com.sun.enterprise.deployment.Application)

Example 49 with BundleDescriptor

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

the class ListSubComponentsCommand method getAppLevelComponents.

private Map<String, String> getAppLevelComponents(com.sun.enterprise.deployment.Application application, String type, Map<String, String> subComponentsMap) {
    Map<String, String> subComponentList = new LinkedHashMap<String, String>();
    if (application.isVirtual()) {
        // for standalone module, get servlets or ejbs
        BundleDescriptor bundleDescriptor = application.getStandaloneBundleDescriptor();
        subComponentList = getModuleLevelComponents(bundleDescriptor, type, subComponentsMap);
    } else {
        // for ear case, get modules
        Collection<ModuleDescriptor<BundleDescriptor>> modules = getSubModuleListForEar(application, type);
        for (ModuleDescriptor module : modules) {
            StringBuffer sb = new StringBuffer();
            String moduleName = module.getArchiveUri();
            sb.append("<");
            String moduleType = getModuleType(module);
            sb.append(moduleType);
            sb.append(">");
            subComponentList.put(moduleName, sb.toString());
            subComponentsMap.put(module.getArchiveUri(), moduleType);
        }
    }
    return subComponentList;
}
Also used : BundleDescriptor(com.sun.enterprise.deployment.BundleDescriptor) WebBundleDescriptor(com.sun.enterprise.deployment.WebBundleDescriptor) EjbBundleDescriptor(com.sun.enterprise.deployment.EjbBundleDescriptor) ModuleDescriptor(org.glassfish.deployment.common.ModuleDescriptor) LinkedHashMap(java.util.LinkedHashMap)

Example 50 with BundleDescriptor

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

the class ListSubComponentsCommand method execute.

public void execute(AdminCommandContext context) {
    final ActionReport report = context.getActionReport();
    ActionReport.MessagePart part = report.getTopMessagePart();
    String applicationName = modulename;
    if (appname != null) {
        applicationName = appname;
    }
    try {
        VersioningUtils.checkIdentifier(applicationName);
    } catch (VersioningSyntaxException ex) {
        report.setMessage(ex.getLocalizedMessage());
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    if (!deployment.isRegistered(applicationName)) {
        report.setMessage(localStrings.getLocalString("application.notreg", "Application {0} not registered", applicationName));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    Application application = applications.getApplication(applicationName);
    if (application.isLifecycleModule()) {
        if (!terse) {
            part.setMessage(localStrings.getLocalString("listsubcomponents.no.elements.to.list", "Nothing to List."));
        }
        return;
    }
    ApplicationInfo appInfo = appRegistry.get(applicationName);
    if (appInfo == null) {
        report.setMessage(localStrings.getLocalString("application.not.enabled", "Application {0} is not in an enabled state", applicationName));
        return;
    }
    com.sun.enterprise.deployment.Application app = appInfo.getMetaData(com.sun.enterprise.deployment.Application.class);
    if (app == null) {
        if (!terse) {
            part.setMessage(localStrings.getLocalString("listsubcomponents.no.elements.to.list", "Nothing to List."));
        }
        return;
    }
    Map<String, String> subComponents;
    Map<String, String> subComponentsMap = new HashMap<String, String>();
    if (appname == null) {
        subComponents = getAppLevelComponents(app, type, subComponentsMap);
    } else {
        // strip the version suffix (delimited by colon), if present
        int versionSuffix = modulename.indexOf(':');
        String versionLessModuleName = versionSuffix > 0 ? modulename.substring(0, versionSuffix) : modulename;
        BundleDescriptor bundleDesc = app.getModuleByUri(versionLessModuleName);
        if (bundleDesc == null) {
            report.setMessage(localStrings.getLocalString("listsubcomponents.invalidmodulename", "Invalid module name", appname, modulename));
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            return;
        }
        subComponents = getModuleLevelComponents(bundleDesc, type, subComponentsMap);
    }
    // the type param can only have values "ejbs" and "servlets"
    if (type != null) {
        if (!type.equals("servlets") && !type.equals("ejbs")) {
            report.setMessage(localStrings.getLocalString("listsubcomponents.invalidtype", "The type option has invalid value {0}. It should have a value of servlets or ejbs.", type));
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            return;
        }
    }
    List<String> subModuleInfos = new ArrayList<String>();
    if (!app.isVirtual()) {
        subModuleInfos = getSubModulesForEar(app, type);
    }
    int[] longestValue = new int[2];
    for (Map.Entry<String, String> entry : subComponents.entrySet()) {
        String key = entry.getKey();
        if (key.length() > longestValue[0]) {
            longestValue[0] = key.length();
        }
        String value = entry.getValue();
        if (value.length() > longestValue[1]) {
            longestValue[1] = value.length();
        }
    }
    StringBuilder formattedLineBuf = new StringBuilder();
    for (int j = 0; j < 2; j++) {
        longestValue[j] += 2;
        formattedLineBuf.append("%-").append(longestValue[j]).append("s");
    }
    String formattedLine = formattedLineBuf.toString();
    if (!terse && subComponents.isEmpty()) {
        part.setMessage(localStrings.getLocalString("listsubcomponents.no.elements.to.list", "Nothing to List."));
    }
    int i = 0;
    for (String key : subComponents.keySet()) {
        ActionReport.MessagePart childPart = part.addChild();
        childPart.setMessage(String.format(formattedLine, new Object[] { key, subComponents.get(key) }));
        if (appname == null && !app.isVirtual()) {
            // support for JSR88 client
            if (subModuleInfos.get(i) != null) {
                childPart.addProperty("moduleInfo", subModuleInfos.get(i));
            }
        }
        if (resources) {
            Module module = application.getModule(key);
            if (module != null) {
                ActionReport subReport = report.addSubActionsReport();
                CommandRunner.CommandInvocation inv = commandRunner.getCommandInvocation("_list-resources", subReport, context.getSubject());
                final ParameterMap parameters = new ParameterMap();
                parameters.add("appname", application.getName());
                parameters.add("modulename", module.getName());
                inv.parameters(parameters).execute();
                ActionReport.MessagePart subPart = subReport.getTopMessagePart();
                for (ActionReport.MessagePart cp : subPart.getChildren()) {
                    ActionReport.MessagePart resourcesChildPart = childPart.addChild();
                    resourcesChildPart.setMessage("  " + cp.getMessage());
                }
            }
        }
        i++;
    }
    // add the properties for GUI to display
    Set<String> keys = subComponentsMap.keySet();
    for (String key : keys) {
        part.addProperty(key, subComponentsMap.get(key));
    }
    // now this is the normal output for the list-sub-components command
    report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ApplicationInfo(org.glassfish.internal.data.ApplicationInfo) ArrayList(java.util.ArrayList) ActionReport(org.glassfish.api.ActionReport) CommandRunner(org.glassfish.api.admin.CommandRunner) VersioningSyntaxException(org.glassfish.deployment.versioning.VersioningSyntaxException) ParameterMap(org.glassfish.api.admin.ParameterMap) RestEndpoint(org.glassfish.api.admin.RestEndpoint) BundleDescriptor(com.sun.enterprise.deployment.BundleDescriptor) WebBundleDescriptor(com.sun.enterprise.deployment.WebBundleDescriptor) EjbBundleDescriptor(com.sun.enterprise.deployment.EjbBundleDescriptor) Module(com.sun.enterprise.config.serverbeans.Module) Application(com.sun.enterprise.config.serverbeans.Application) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) ParameterMap(org.glassfish.api.admin.ParameterMap)

Aggregations

BundleDescriptor (com.sun.enterprise.deployment.BundleDescriptor)51 EjbBundleDescriptor (com.sun.enterprise.deployment.EjbBundleDescriptor)24 WebBundleDescriptor (com.sun.enterprise.deployment.WebBundleDescriptor)24 Application (com.sun.enterprise.deployment.Application)17 EjbDescriptor (com.sun.enterprise.deployment.EjbDescriptor)10 ModuleDescriptor (org.glassfish.deployment.common.ModuleDescriptor)9 ManagedBeanDescriptor (com.sun.enterprise.deployment.ManagedBeanDescriptor)8 JndiNameEnvironment (com.sun.enterprise.deployment.JndiNameEnvironment)7 WeldBootstrap (org.jboss.weld.bootstrap.WeldBootstrap)7 BeanDeploymentArchive (org.jboss.weld.bootstrap.spi.BeanDeploymentArchive)7 JCDIService (com.sun.enterprise.container.common.spi.JCDIService)6 ApplicationInfo (org.glassfish.internal.data.ApplicationInfo)6 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5 RootDeploymentDescriptor (org.glassfish.deployment.common.RootDeploymentDescriptor)5 InterceptorInvoker (com.sun.enterprise.container.common.spi.InterceptorInvoker)4 HashSet (java.util.HashSet)4 JavaEEInterceptorBuilder (com.sun.enterprise.container.common.spi.JavaEEInterceptorBuilder)3 File (java.io.File)3 IOException (java.io.IOException)3