Search in sources :

Example 6 with WebBundleDescriptorImpl

use of org.glassfish.web.deployment.descriptor.WebBundleDescriptorImpl in project Payara by payara.

the class ExceptionType method check.

/**
 * Exception-type element contains a fully qualified class name of a Java
 * exception type.
 *
 * @param descriptor the Web deployment descriptor
 *
 * @return <code>Result</code> the results for this assertion
 */
public Result check(WebBundleDescriptor descriptor) {
    Result result = loadWarFile(descriptor);
    ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
    if (((WebBundleDescriptorImpl) descriptor).getErrorPageDescriptors().hasMoreElements()) {
        boolean oneFailed = false;
        int oneExceptionType = 0;
        int oneNA = 0;
        boolean foundIt = false;
        // get the errorpage's in this .war
        for (Enumeration e = ((WebBundleDescriptorImpl) descriptor).getErrorPageDescriptors(); e.hasMoreElements(); ) {
            foundIt = false;
            oneExceptionType++;
            ErrorPageDescriptor errorpage = (ErrorPageDescriptor) e.nextElement();
            if (errorpage.getErrorCode() == 0) {
                String exceptionType = errorpage.getExceptionType();
                if ((exceptionType != null) && (exceptionType.length() > 0)) {
                    boolean isValidExceptionType = false;
                    try {
                        Class c = loadClass(result, exceptionType);
                        if (isSubclassOf(c, "java.lang.Exception")) {
                            isValidExceptionType = true;
                        }
                    } catch (Exception ex) {
                        // should already be set
                        isValidExceptionType = false;
                    }
                    if (isValidExceptionType) {
                        foundIt = true;
                    } else {
                        foundIt = false;
                    }
                    if (foundIt) {
                        result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                        result.addGoodDetails(smh.getLocalString(getClass().getName() + ".passed", "Exception type [ {0} ] contains a fully qualified class name of a Java exception type within web application [ {1} ]", new Object[] { exceptionType, descriptor.getName() }));
                    } else {
                        if (!oneFailed) {
                            oneFailed = true;
                        }
                        result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                        result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed", "Error: Exception type [ {0} ] does not contain a fully qualified class name of a Java exception type within web application [ {1} ]", new Object[] { exceptionType, descriptor.getName() }));
                    }
                } else {
                    if (!oneFailed) {
                        oneFailed = true;
                    }
                    Integer errorCode = new Integer(errorpage.getErrorCode());
                    result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                    result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed", "Error: Exception type [ {0} ] does not contain a fully qualified class name of a Java exception type within web application [ {1} ]", new Object[] { errorCode.toString(), descriptor.getName() }));
                    oneNA++;
                }
            } else {
                // maybe Exception is null 'cause we are using ErrorCode
                // if that is the case, then test is N/A,
                Integer errorCode = new Integer(errorpage.getErrorCode());
                result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                result.addNaDetails(smh.getLocalString(getClass().getName() + ".notApplicable1", "Exception type is null, using error-code [ {0} ] instead within web application [ {1} ]", new Object[] { errorCode.toString(), descriptor.getName() }));
                oneNA++;
            }
        }
        if (oneFailed) {
            result.setStatus(Result.FAILED);
        } else if (oneNA == oneExceptionType) {
            result.setStatus(Result.NOT_APPLICABLE);
        } else {
            result.setStatus(Result.PASSED);
        }
    } else {
        result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
        result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable", "There are no exception-type elements within the web archive [ {0} ]", new Object[] { descriptor.getName() }));
    }
    return result;
}
Also used : WebBundleDescriptorImpl(org.glassfish.web.deployment.descriptor.WebBundleDescriptorImpl) ErrorPageDescriptor(org.glassfish.web.deployment.descriptor.ErrorPageDescriptor)

Example 7 with WebBundleDescriptorImpl

use of org.glassfish.web.deployment.descriptor.WebBundleDescriptorImpl in project Payara by payara.

the class VirtualServer method getDefaultWebModule.

protected WebModuleConfig getDefaultWebModule(Domain domain, WebArchivist webArchivist, ApplicationRegistry appRegistry) {
    WebModuleConfig wmInfo = null;
    String wmID = getDefaultWebModuleID();
    if (wmID != null) {
        // Check if the default-web-module is part of a
        // j2ee-application
        Applications appsBean = domain.getApplications();
        wmInfo = findWebModuleInJ2eeApp(appsBean, wmID, appRegistry);
        if (wmInfo == null) {
            ConfigBeansUtilities cbu = getConfigBeansUtilities();
            String contextRoot = null;
            String location = null;
            if (cbu != null) {
                contextRoot = cbu.getContextRoot(wmID);
                location = cbu.getLocation(wmID);
            }
            if (contextRoot != null && location != null) {
                File docroot = new File(location);
                final WebBundleDescriptorImpl wbd = webArchivist.getDefaultWebXmlBundleDescriptor();
                wmInfo = new WebModuleConfig();
                wbd.setName(Constants.DEFAULT_WEB_MODULE_NAME);
                wbd.setContextRoot(contextRoot);
                wmInfo.setLocation(docroot);
                wmInfo.setDescriptor(wbd);
                wmInfo.setParentLoader(EmbeddedWebContainer.class.getClassLoader());
                WebappClassLoader cloader = AccessController.doPrivileged(new PrivilegedAction<WebappClassLoader>() {

                    @Override
                    public WebappClassLoader run() {
                        return new WebappClassLoader(EmbeddedWebContainer.class.getClassLoader(), wbd.getApplication());
                    }
                });
                wmInfo.setAppClassLoader(cloader);
            }
        }
        if (wmInfo == null) {
            _logger.log(Level.SEVERE, LogFacade.VS_DEFAULT_WEB_MODULE_NOT_FOUND, new Object[] { wmID, getID() });
        }
    }
    return wmInfo;
}
Also used : WebappClassLoader(org.glassfish.web.loader.WebappClassLoader) Applications(com.sun.enterprise.config.serverbeans.Applications) WebBundleDescriptorImpl(org.glassfish.web.deployment.descriptor.WebBundleDescriptorImpl) ConfigBeansUtilities(com.sun.enterprise.config.serverbeans.ConfigBeansUtilities) File(java.io.File)

Example 8 with WebBundleDescriptorImpl

use of org.glassfish.web.deployment.descriptor.WebBundleDescriptorImpl in project Payara by payara.

the class VirtualServer method createSystemDefaultWebModuleIfNecessary.

/**
 * If a default web module has not yet been configured and added to this
 * virtual server's list of web modules then return the configuration
 * information needed in order to create a default web module for this
 * virtual server.
 *
 * This method should be invoked only after all the standalone modules
 * and the modules within j2ee-application elements have been added to
 * this virtual server's list of modules (only then will one know whether
 * the user has already configured a default web module or not).
 * @param webArchivist
 * @return
 */
public WebModuleConfig createSystemDefaultWebModuleIfNecessary(WebArchivist webArchivist) {
    WebModuleConfig wmInfo = null;
    // Add a default context only if one hasn't already been loaded
    // and then too only if docroot is not null
    // 
    String docroot = getAppBase();
    if (getDefaultWebModuleID() == null && findChild("") == null && docroot != null) {
        final WebBundleDescriptorImpl wbd = webArchivist.getDefaultWebXmlBundleDescriptor();
        wmInfo = new WebModuleConfig();
        wbd.setModuleID(Constants.DEFAULT_WEB_MODULE_NAME);
        wbd.setContextRoot("");
        wmInfo.setLocation(new File(docroot));
        wmInfo.setDescriptor(wbd);
        wmInfo.setParentLoader(serverContext.getCommonClassLoader());
        if (wbd.getApplication() == null) {
            Application application = Application.createApplication();
            application.setVirtual(true);
            application.setName(Constants.DEFAULT_WEB_MODULE_NAME);
            wbd.setApplication(application);
        }
        WebappClassLoader loader = AccessController.doPrivileged(new PrivilegedAction<WebappClassLoader>() {

            @Override
            public WebappClassLoader run() {
                return new WebappClassLoader(serverContext.getCommonClassLoader(), wbd.getApplication());
            }
        });
        loader.start();
        wmInfo.setAppClassLoader(loader);
    }
    return wmInfo;
}
Also used : WebappClassLoader(org.glassfish.web.loader.WebappClassLoader) WebBundleDescriptorImpl(org.glassfish.web.deployment.descriptor.WebBundleDescriptorImpl) File(java.io.File) Application(com.sun.enterprise.deployment.Application)

Example 9 with WebBundleDescriptorImpl

use of org.glassfish.web.deployment.descriptor.WebBundleDescriptorImpl in project Payara by payara.

the class VirtualServer method findWebModuleInJ2eeApp.

/**
 * Finds and returns information about a web module embedded within a
 * J2EE application, which is identified by a string of the form
 * <code>a:b</code> or <code>a#b</code>, where <code>a</code> is the name
 * of the J2EE application and <code>b</code> is the name of the embedded
 * web module.
 *
 * @param appsBean
 * @param id
 * @return null if <code>id</code> does not identify a web module embedded
 * within a J2EE application.
 */
protected WebModuleConfig findWebModuleInJ2eeApp(Applications appsBean, String id, ApplicationRegistry appRegistry) {
    WebModuleConfig wmInfo = null;
    // Check for ':' separator
    int separatorIndex = id.indexOf(Constants.NAME_SEPARATOR);
    if (separatorIndex == -1) {
        // Check for '#' separator
        separatorIndex = id.indexOf('#');
    }
    if (separatorIndex != -1) {
        String appID = id.substring(0, separatorIndex);
        String moduleID = id.substring(separatorIndex + 1);
        com.sun.enterprise.config.serverbeans.Application appBean = appsBean.getModule(com.sun.enterprise.config.serverbeans.Application.class, appID);
        if ((appBean != null) && Boolean.valueOf(appBean.getEnabled())) {
            String location = appBean.getLocation();
            String moduleDir = DeploymentUtils.getRelativeEmbeddedModulePath(location, moduleID);
            ApplicationInfo appInfo = appRegistry.get(appID);
            final Application app = appInfo != null ? appInfo.getMetaData(Application.class) : null;
            if (appInfo == null) {
                // XXX ApplicaionInfo is NULL after restart
                Object[] params = { id, getID() };
                _logger.log(Level.SEVERE, LogFacade.VS_DEFAULT_WEB_MODULE_DISABLED, params);
                return wmInfo;
            }
            final WebBundleDescriptorImpl wbd = app.getModuleByTypeAndUri(WebBundleDescriptorImpl.class, moduleID);
            String webUri = wbd.getModuleDescriptor().getArchiveUri();
            String contextRoot = wbd.getModuleDescriptor().getContextRoot();
            if (moduleID.equals(webUri)) {
                StringBuilder dir = new StringBuilder(location);
                dir.append(File.separator);
                dir.append(moduleDir);
                File docroot = new File(dir.toString());
                wmInfo = new WebModuleConfig();
                wbd.setName(moduleID);
                wbd.setContextRoot(contextRoot);
                wmInfo.setDescriptor(wbd);
                wmInfo.setLocation(docroot);
                wmInfo.setParentLoader(EmbeddedWebContainer.class.getClassLoader());
                WebappClassLoader cloader = AccessController.doPrivileged(new PrivilegedAction<WebappClassLoader>() {

                    @Override
                    public WebappClassLoader run() {
                        return new WebappClassLoader(EmbeddedWebContainer.class.getClassLoader(), app);
                    }
                });
                wmInfo.setAppClassLoader(cloader);
            }
        } else {
            Object[] params = { id, getID() };
            _logger.log(Level.SEVERE, LogFacade.VS_DEFAULT_WEB_MODULE_DISABLED, params);
        }
    }
    return wmInfo;
}
Also used : ApplicationInfo(org.glassfish.internal.data.ApplicationInfo) WebappClassLoader(org.glassfish.web.loader.WebappClassLoader) WebBundleDescriptorImpl(org.glassfish.web.deployment.descriptor.WebBundleDescriptorImpl) Application(com.sun.enterprise.deployment.Application) File(java.io.File)

Example 10 with WebBundleDescriptorImpl

use of org.glassfish.web.deployment.descriptor.WebBundleDescriptorImpl in project Payara by payara.

the class WebApplication method applyApplicationConfig.

/**
 * Applies application config customization (stored temporarily in the
 * start-up context's start-up parameters) to the web app's descriptor.
 * @param appContext
 */
private void applyApplicationConfig(ApplicationContext appContext) {
    WebBundleDescriptorImpl descriptor = wmInfo.getDescriptor();
    try {
        if (appConfigCustomizations != null) {
            EnvEntryCustomizer envEntryCustomizer = new EnvEntryCustomizer(descriptor.getEnvironmentEntrySet(), appConfigCustomizations.getEnvEntry());
            ContextParamCustomizer contextParamCustomizer = new ContextParamCustomizer(descriptor.getContextParametersSet(), appConfigCustomizations.getContextParam());
            envEntryCustomizer.applyCustomizations();
            contextParamCustomizer.applyCustomizations();
        }
    } catch (ClassCastException ex) {
        /*
             * If the user specified an env-entry value that does not
             * work with the env-entry type it can cause a class cast
             * exception.  Log the warning but continue working.
             */
        logger.log(Level.WARNING, "", ex);
    }
}
Also used : WebBundleDescriptorImpl(org.glassfish.web.deployment.descriptor.WebBundleDescriptorImpl)

Aggregations

WebBundleDescriptorImpl (org.glassfish.web.deployment.descriptor.WebBundleDescriptorImpl)13 File (java.io.File)5 ErrorPageDescriptor (org.glassfish.web.deployment.descriptor.ErrorPageDescriptor)4 WebappClassLoader (org.glassfish.web.loader.WebappClassLoader)3 FileArchive (com.sun.enterprise.deploy.shared.FileArchive)2 Application (com.sun.enterprise.deployment.Application)2 String (java.lang.String)2 DeployCommandParameters (org.glassfish.api.deployment.DeployCommandParameters)2 Applications (com.sun.enterprise.config.serverbeans.Applications)1 ConfigBeansUtilities (com.sun.enterprise.config.serverbeans.ConfigBeansUtilities)1 TagLibDescriptor (com.sun.enterprise.tools.verifier.TagLibDescriptor)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 LogRecord (java.util.logging.LogRecord)1 ServletContainerInitializer (javax.servlet.ServletContainerInitializer)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 DeploymentContext (org.glassfish.api.deployment.DeploymentContext)1 ApplicationConfigInfo (org.glassfish.deployment.common.ApplicationConfigInfo)1 DeploymentException (org.glassfish.deployment.common.DeploymentException)1