Search in sources :

Example 1 with WebBundleDescriptorImpl

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

the class WebArchiveClassesLoadable method getClassNames.

/**
 * Looks for Servlet classes, ServletFilter classes, Listener classes and
 * Exception classes in the webBundleDescriptor. The closure is computed
 * starting from these classes.
 * @param descriptor
 * @return returns a list of class names in the form that can be used in
 * classloader.load()
 * @throws Exception
 */
private List getClassNames(WebBundleDescriptor descriptor) throws Exception {
    final List<String> results = new LinkedList<String>();
    for (Object obj : descriptor.getServletDescriptors()) {
        String servletClassName = (WebComponentDescriptor.class.cast(obj)).getWebComponentImplementation();
        results.add(servletClassName);
    }
    for (Object obj : descriptor.getServletFilterDescriptors()) {
        String filterClassName = (ServletFilter.class.cast(obj)).getClassName();
        results.add(filterClassName);
    }
    for (Object obj : descriptor.getAppListenerDescriptors()) {
        String listenerClassName = (AppListenerDescriptor.class.cast(obj)).getListener();
        results.add(listenerClassName);
    }
    results.addAll(getVerifierContext().getFacesConfigDescriptor().getManagedBeanClasses());
    Enumeration en = ((WebBundleDescriptorImpl) descriptor).getErrorPageDescriptors();
    while (en.hasMoreElements()) {
        ErrorPageDescriptor errorPageDescriptor = (ErrorPageDescriptor) en.nextElement();
        String exceptionType = errorPageDescriptor.getExceptionType();
        if (exceptionType != null && !exceptionType.equals(""))
            results.add(exceptionType);
    }
    File file = getVerifierContext().getOutDir();
    if (!file.exists())
        return results;
    FileArchive arch = new FileArchive();
    arch.open(file.toURI());
    Enumeration entries = arch.entries();
    while (entries.hasMoreElements()) {
        String name = (String) entries.nextElement();
        if (name.startsWith("org/apache/jsp") && name.endsWith(".class"))
            results.add(name.substring(0, name.lastIndexOf(".")).replace('/', '.'));
    }
    return results;
}
Also used : WebBundleDescriptorImpl(org.glassfish.web.deployment.descriptor.WebBundleDescriptorImpl) FileArchive(com.sun.enterprise.deploy.shared.FileArchive) ErrorPageDescriptor(org.glassfish.web.deployment.descriptor.ErrorPageDescriptor) File(java.io.File)

Example 2 with WebBundleDescriptorImpl

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

the class TagLibFactory method getTagLibDescriptors.

/**
 * This method is responsible for creating a document object from the tld
 * files and then returning the array TagLibDescriptor objects based on tld
 * version.
 *
 * @param descriptor the web bundle descriptor giving the tlds contained
 * in the war.
 * @return the tag lib descriptor array for all the tlds defined in the war.
 */
public TagLibDescriptor[] getTagLibDescriptors(WebBundleDescriptor descriptor) {
    ArrayList<TagLibDescriptor> tmp = new ArrayList<TagLibDescriptor>();
    Iterable<TaglibDescriptor> taglibConfig = null;
    if (((WebBundleDescriptorImpl) descriptor).getJspConfigDescriptor() != null) {
        taglibConfig = ((WebBundleDescriptorImpl) descriptor).getJspConfigDescriptor().getTaglibs();
    } else {
        return null;
    }
    init();
    for (TaglibDescriptor taglibDescriptor : taglibConfig) {
        // test all the Tag lib descriptors.
        String taglibLocation = taglibDescriptor.getTaglibLocation();
        Document d = null;
        try {
            d = createDocument(taglibLocation, descriptor);
        } catch (Exception e) {
            logger.log(Level.WARNING, smh.getLocalString(// NOI18N
            getClass().getName() + ".exception", // NOI18N
            "Continuing, though problem in creating taglib document. Cause: {0}", new Object[] { e.getMessage() }));
            if (e instanceof SAXParseException) {
                LogRecord logRecord = new LogRecord(Level.SEVERE, smh.getLocalString(// NOI18N
                getClass().getName() + ".exception2", // NOI18N
                "XML Error line : {0} in [ {1} ]. {2}", new Object[] { ((SAXParseException) e).getLineNumber(), taglibLocation, e.getLocalizedMessage() }));
                logRecord.setThrown(e);
                verifierFrameworkContext.getResultManager().log(logRecord);
            }
            // we are continuing with creating the next document.
            continue;
        }
        String version = getTLDSpecVersion(d);
        TagLibDescriptor taglib = null;
        taglib = new TagLibDescriptor(d, version, taglibLocation);
        tmp.add(taglib);
    }
    int count = tmp.size();
    TagLibDescriptor[] arr = new TagLibDescriptor[count];
    int i = 0;
    for (Iterator e = tmp.iterator(); e.hasNext(); i++) {
        arr[i] = (TagLibDescriptor) e.next();
    }
    return arr;
}
Also used : ArrayList(java.util.ArrayList) Document(org.w3c.dom.Document) IOException(java.io.IOException) SAXParseException(org.xml.sax.SAXParseException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException) WebBundleDescriptorImpl(org.glassfish.web.deployment.descriptor.WebBundleDescriptorImpl) LogRecord(java.util.logging.LogRecord) SAXParseException(org.xml.sax.SAXParseException) TagLibDescriptor(com.sun.enterprise.tools.verifier.TagLibDescriptor) Iterator(java.util.Iterator)

Example 3 with WebBundleDescriptorImpl

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

the class Location method check.

/**
 * Location element contains the location of the resource in the web
 * application
 *
 * @param descriptor the Web deployment descriptor
 *
 * @return <code>Result</code> the results for this assertion
 */
public Result check(WebBundleDescriptor descriptor) {
    Result result = getInitializedResult();
    ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
    if (((WebBundleDescriptorImpl) descriptor).getErrorPageDescriptors().hasMoreElements()) {
        boolean oneFailed = false;
        boolean foundIt = false;
        // ZipEntry ze = null;
        // JarFile jar =null;
        FileArchive arch = null;
        // get the errorpage's in this .war
        for (Enumeration e = ((WebBundleDescriptorImpl) descriptor).getErrorPageDescriptors(); e.hasMoreElements(); ) {
            foundIt = false;
            ErrorPageDescriptor errorpage = (ErrorPageDescriptor) e.nextElement();
            String location = errorpage.getLocation();
            String uri = null;
            try {
                // File f = Verifier.getArchiveFile(descriptor.getModuleDescriptor().getArchiveUri());
                // if(f==null){
                uri = getAbstractArchiveUri(descriptor);
                try {
                    arch = new FileArchive();
                    arch.open(uri);
                } catch (IOException ioe) {
                    throw ioe;
                }
                // }
                if (location.startsWith("/"))
                    location = location.substring(1);
                // if (f!=null){
                // ze = jar.getEntry(location);
                // foundIt = (ze != null);
                // }
                // else{
                File loc = new File(new File(arch.getURI()), location);
                if (loc.exists())
                    foundIt = true;
                loc = null;
            // }
            // if (jar!=null)
            // jar.close();
            } catch (Exception ex) {
                if (!oneFailed) {
                    oneFailed = true;
                }
            }
            if (foundIt) {
                result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                result.addGoodDetails(smh.getLocalString(getClass().getName() + ".passed", "Location [ {0} ] contains the location of the resource within web application [ {1} ]", new Object[] { location, 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: Location [ {0} ] is not found within [ {1} ] or does not contain the location of the resource within web application [ {2} ]", new Object[] { location, uri, descriptor.getName() }));
            }
        }
        if (oneFailed) {
            result.setStatus(Result.FAILED);
        } 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 location elements within the web archive [ {0} ]", new Object[] { descriptor.getName() }));
    }
    return result;
}
Also used : WebBundleDescriptorImpl(org.glassfish.web.deployment.descriptor.WebBundleDescriptorImpl) FileArchive(com.sun.enterprise.deploy.shared.FileArchive) ErrorPageDescriptor(org.glassfish.web.deployment.descriptor.ErrorPageDescriptor)

Example 4 with WebBundleDescriptorImpl

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

the class DynamicWebServletRegistrationImpl method start.

/**
 * Starts this web module.
 */
@Override
public synchronized void start() throws LifecycleException {
    // Get interestList of ServletContainerInitializers present, if any.
    List<Object> orderingList = null;
    boolean hasOthers = false;
    Map<String, String> webFragmentMap = Collections.emptyMap();
    if (webBundleDescriptor != null) {
        AbsoluteOrderingDescriptor aod = ((WebBundleDescriptorImpl) webBundleDescriptor).getAbsoluteOrderingDescriptor();
        if (aod != null) {
            orderingList = aod.getOrdering();
            hasOthers = aod.hasOthers();
        }
        webFragmentMap = webBundleDescriptor.getJarNameToWebFragmentNameMap();
    }
    boolean servletInitializersEnabled = true;
    if (webBundleDescriptor != null) {
        servletInitializersEnabled = webBundleDescriptor.getServletInitializersEnabled();
    }
    Iterable<ServletContainerInitializer> allInitializers = ServletContainerInitializerUtil.getServletContainerInitializers(webFragmentMap, orderingList, hasOthers, wmInfo.getAppClassLoader(), servletInitializersEnabled);
    setServletContainerInitializerInterestList(allInitializers);
    DeploymentContext dc = getWebModuleConfig().getDeploymentContext();
    if (dc != null) {
        directoryDeployed = Boolean.valueOf(dc.getAppProps().getProperty(ServerTags.DIRECTORY_DEPLOYED));
    }
    if (webBundleDescriptor != null) {
        showArchivedRealPathEnabled = webBundleDescriptor.isShowArchivedRealPathEnabled();
        servletReloadCheckSecs = webBundleDescriptor.getServletReloadCheckSecs();
        String reqEncoding = webBundleDescriptor.getRequestCharacterEncoding();
        if (reqEncoding != null) {
            setRequestCharacterEncoding(reqEncoding);
        }
        String resEncoding = webBundleDescriptor.getResponseCharacterEncoding();
        if (resEncoding != null) {
            setResponseCharacterEncoding(resEncoding);
        }
    }
    // Start and register Tomcat mbeans
    super.start();
    // Configure catalina listeners and valves. This can only happen
    // after this web module has been started, in order to be able to
    // load the specified listener and valve classes.
    configureValves();
    configureCatalinaProperties();
    webModuleStartedEvent();
    if (directoryListing) {
        setDirectoryListing(directoryListing);
    }
    hasStarted = true;
}
Also used : ServletContainerInitializer(javax.servlet.ServletContainerInitializer) DeploymentContext(org.glassfish.api.deployment.DeploymentContext) WebBundleDescriptorImpl(org.glassfish.web.deployment.descriptor.WebBundleDescriptorImpl) AbsoluteOrderingDescriptor(org.glassfish.web.deployment.descriptor.AbsoluteOrderingDescriptor)

Example 5 with WebBundleDescriptorImpl

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

the class ErrorCode method check.

/**
 * Error code element contains an HTTP error code within web application test.
 *  i.e. 404
 *
 * @param descriptor the Web deployment descriptor
 *
 * @return <code>Result</code> the results for this assertion
 */
public Result check(WebBundleDescriptor descriptor) {
    Result result = getInitializedResult();
    ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
    if (((WebBundleDescriptorImpl) descriptor).getErrorPageDescriptors().hasMoreElements()) {
        boolean oneFailed = false;
        boolean foundIt = false;
        int oneErrorCode = 0;
        int oneNA = 0;
        // get the errorpage's in this .war
        for (Enumeration e = ((WebBundleDescriptorImpl) descriptor).getErrorPageDescriptors(); e.hasMoreElements(); ) {
            foundIt = false;
            oneErrorCode++;
            ErrorPageDescriptor errorpage = (ErrorPageDescriptor) e.nextElement();
            String exceptionType = errorpage.getExceptionType();
            if (!((exceptionType != null) && (exceptionType.length() > 0))) {
                Integer errorCode = new Integer(errorpage.getErrorCode());
                if (isValidErrorCode(errorCode)) {
                    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", "Error code [ {0} ] contains valid HTTP error code within web application [ {1} ]", new Object[] { errorCode.toString(), 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: error-code [ {0} ] does not contain valid HTTP error code within web application [ {1} ]", new Object[] { errorCode.toString(), descriptor.getName() }));
                }
            } else {
                // maybe ErrorCode is not used 'cause we are using Exception
                // if that is the case, then test is N/A,
                result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                result.addNaDetails(smh.getLocalString(getClass().getName() + ".notApplicable1", "Not Applicable: Error-code is [ {0} ], using [ {1} ] instead within web application [ {2} ]", new Object[] { new Integer(errorpage.getErrorCode()), exceptionType, descriptor.getName() }));
                oneNA++;
            }
        }
        if (oneFailed) {
            result.setStatus(Result.FAILED);
        } else if (oneNA == oneErrorCode) {
            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 error-code 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)

Aggregations

WebBundleDescriptorImpl (org.glassfish.web.deployment.descriptor.WebBundleDescriptorImpl)15 File (java.io.File)5 ErrorPageDescriptor (org.glassfish.web.deployment.descriptor.ErrorPageDescriptor)4 DeployCommandParameters (org.glassfish.api.deployment.DeployCommandParameters)3 WebappClassLoader (org.glassfish.web.loader.WebappClassLoader)3 FileArchive (com.sun.enterprise.deploy.shared.FileArchive)2 ConfigBeansUtilities (com.sun.enterprise.config.serverbeans.ConfigBeansUtilities)1 SecurityService (com.sun.enterprise.config.serverbeans.SecurityService)1 Application (com.sun.enterprise.deployment.Application)1 TagLibDescriptor (com.sun.enterprise.tools.verifier.TagLibDescriptor)1 JwtAuthCdiExtension (fish.payara.microprofile.jwtauth.cdi.JwtAuthCdiExtension)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 Supplier (java.util.function.Supplier)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 ReadableArchive (org.glassfish.api.deployment.archive.ReadableArchive)1