Search in sources :

Example 1 with WebComponentDescriptor

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

the class WebBundleDescriptorImpl method addWebComponentDescriptor.

/**
 * Adds a new Web Component Descriptor to me.
 * @param webComponentDescriptor
 */
@Override
public void addWebComponentDescriptor(WebComponentDescriptor webComponentDescriptor) {
    String name = webComponentDescriptor.getCanonicalName();
    webComponentDescriptor.setWebBundleDescriptor(this);
    WebComponentDescriptor resultDesc = combineWebComponentDescriptor(webComponentDescriptor);
    // sync up urlPattern2ServletName map
    for (String up : resultDesc.getUrlPatternsSet()) {
        String oldName = getUrlPatternToServletNameMap().put(up, name);
        if (oldName != null && (!oldName.equals(name))) {
            throw new IllegalArgumentException(localStrings.getLocalString("web.deployment.exceptionsameurlpattern", "Servlet [{0}] and Servlet [{1}] have the same url pattern: [{2}]", new Object[] { oldName, name, up }));
        }
    }
}
Also used : WebComponentDescriptor(com.sun.enterprise.deployment.WebComponentDescriptor)

Example 2 with WebComponentDescriptor

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

the class ASCacheMapping method validServletName.

boolean validServletName(String servletName, WebBundleDescriptor descriptor) {
    boolean valid = false;
    if (servletName != null && servletName.length() != 0) {
        Set servlets = descriptor.getServletDescriptors();
        Iterator itr = servlets.iterator();
        // test the servlets in this .war
        while (itr.hasNext()) {
            String thisServletName = ((WebComponentDescriptor) itr.next()).getCanonicalName();
            if (servletName.equals(thisServletName)) {
                valid = true;
                break;
            }
        }
    }
    return valid;
}
Also used : WebComponentDescriptor(com.sun.enterprise.deployment.WebComponentDescriptor) Set(java.util.Set) Iterator(java.util.Iterator)

Example 3 with WebComponentDescriptor

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

the class FilterMapping method hasValidMapping.

private void hasValidMapping(WebBundleDescriptor descriptor, String filterName) {
    Enumeration filtermapperEnum = descriptor.getServletFilterMappingDescriptors().elements();
    if (filtermapperEnum.hasMoreElements()) {
        ServletFilterMappingDescriptor filterMapper = null;
        boolean mappingFound = false;
        do {
            filterMapper = (ServletFilterMappingDescriptor) filtermapperEnum.nextElement();
            String filterMapping = filterMapper.getName();
            mappingFound = filterName.equals(filterMapping);
        } while (!mappingFound && filtermapperEnum.hasMoreElements());
        if (mappingFound) {
            List<String> urlPatterns = filterMapper.getUrlPatterns();
            for (String url : urlPatterns) {
                if (!((url.startsWith("/")) || ((url.startsWith("/")) && (url.endsWith("/*"))) || (url.startsWith("*.")))) {
                    addErrorDetails(result, compName);
                    result.failed(smh.getLocalString(getClass().getName() + ".failed", "Filter Mapping for [ {0} ] has invalid " + "url-mapping [ {1} ] ", new Object[] { filterName, url }));
                }
            }
            List<String> servletsInFilter = filterMapper.getServletNames();
            // Section SRV.18.0.2 Filter All Dispatches of Servlet 2.5 spec allows "*"
            // to be specified as Servlet name to allow filtering of requests for all servlets.
            final String ALL_SERVLETS_NAME = "*";
            servletsInFilter.remove(ALL_SERVLETS_NAME);
            List<String> servletsInWAR = new ArrayList<String>();
            if (servletsInFilter.size() > 0) {
                Set servletDescriptor = descriptor.getServletDescriptors();
                Iterator itr = servletDescriptor.iterator();
                // test the servlets in this .war
                while (itr.hasNext()) {
                    WebComponentDescriptor servlet = (WebComponentDescriptor) itr.next();
                    servletsInWAR.add(servlet.getCanonicalName());
                }
                if (!(servletsInWAR != null && servletsInWAR.containsAll(servletsInFilter))) {
                    addErrorDetails(result, compName);
                    result.failed(smh.getLocalString(getClass().getName() + ".failed1", "Filter Mapping for [ {0} ] has invalid servlet-name", new Object[] { filterName }));
                }
            }
        }
    }
}
Also used : WebComponentDescriptor(com.sun.enterprise.deployment.WebComponentDescriptor) Enumeration(java.util.Enumeration) Set(java.util.Set) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) ServletFilterMappingDescriptor(org.glassfish.web.deployment.descriptor.ServletFilterMappingDescriptor)

Example 4 with WebComponentDescriptor

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

the class ServletParamName method check.

/**
 *  Servlet Param Name exists test.
 *
 * @param descriptor the Web deployment descriptor
 *
 * @return <code>Result</code> the results for this assertion
 */
public Result check(WebBundleDescriptor descriptor) {
    Set servlets;
    Iterator servItr;
    String epName = null;
    Result result = getInitializedResult();
    ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
    WebComponentDescriptor servlet = null;
    Enumeration en;
    EnvironmentProperty ep = null;
    boolean oneFailed = false;
    boolean duplicate = false;
    if (!descriptor.getServletDescriptors().isEmpty()) {
        // get the servlets in this .war
        servlets = descriptor.getServletDescriptors();
        servItr = servlets.iterator();
        // test the servlets in this .war
        while (servItr.hasNext()) {
            servlet = (WebComponentDescriptor) servItr.next();
            HashSet<String> envSet = new HashSet<String>();
            for (en = servlet.getInitializationParameters(); en.hasMoreElements(); ) {
                ep = (EnvironmentProperty) en.nextElement();
                epName = ep.getName();
                if (epName.length() != 0) {
                    // Do duplicate name test.
                    duplicate = checkDuplicate(epName, envSet);
                } else {
                    oneFailed = true;
                    result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                    result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed", "Error: Param name/value entry should of finite length."));
                }
                if (!duplicate) {
                    envSet.add(epName);
                } else {
                    oneFailed = true;
                    result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                    result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed", "Error: Duplicate param names are not allowed."));
                }
            }
        }
        result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
        result.addGoodDetails(smh.getLocalString(getClass().getName() + ".passed", "Param named/value exists for in the servlet [ {0} ].", new Object[] { servlet.getName() }));
    } else {
        result.setStatus(Result.NOT_APPLICABLE);
        result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
        result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable", "There are no initialization parameters for the servlet within the web archive [ {0} ]", new Object[] { descriptor.getName() }));
        return result;
    }
    if (oneFailed) {
        result.setStatus(Result.FAILED);
    } else {
        result.setStatus(Result.PASSED);
    }
    return result;
}
Also used : WebComponentDescriptor(com.sun.enterprise.deployment.WebComponentDescriptor)

Example 5 with WebComponentDescriptor

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

the class WebBundleRuntimeNode method writeDescriptor.

/**
 * write the descriptor class to a DOM tree and return it
 *
 * @param parent node for the DOM tree
 * @param bundleDescriptor the descriptor to write
 * @return the DOM tree top node
 */
@Override
public Node writeDescriptor(Node parent, WebBundleDescriptorImpl bundleDescriptor) {
    Element web = (Element) super.writeDescriptor(parent, bundleDescriptor);
    SunWebAppImpl sunWebApp = (SunWebAppImpl) bundleDescriptor.getSunDescriptor();
    // context-root?
    appendTextChild(web, RuntimeTagNames.CONTEXT_ROOT, bundleDescriptor.getContextRoot());
    // security-role-mapping
    SecurityRoleMapping[] roleMappings = sunWebApp.getSecurityRoleMapping();
    if (roleMappings != null && roleMappings.length > 0) {
        SecurityRoleMappingNode srmn = new SecurityRoleMappingNode();
        for (SecurityRoleMapping roleMapping : roleMappings) {
            srmn.writeDescriptor(web, RuntimeTagNames.SECURITY_ROLE_MAPPING, roleMapping);
        }
    }
    // servlet
    Set servlets = bundleDescriptor.getServletDescriptors();
    org.glassfish.web.deployment.node.runtime.gf.ServletNode servletNode = new org.glassfish.web.deployment.node.runtime.gf.ServletNode();
    for (Iterator itr = servlets.iterator(); itr.hasNext(); ) {
        WebComponentDescriptor servlet = (WebComponentDescriptor) itr.next();
        servletNode.writeDescriptor(web, RuntimeTagNames.SERVLET, servlet);
    }
    // idempotent-url-pattern
    IdempotentUrlPattern[] patterns = sunWebApp.getIdempotentUrlPatterns();
    if (patterns != null && patterns.length > 0) {
        IdempotentUrlPatternNode node = new IdempotentUrlPatternNode();
        for (IdempotentUrlPattern pattern : patterns) {
            node.writeDescriptor(web, RuntimeTagNames.IDEMPOTENT_URL_PATTERN, pattern);
        }
    }
    // session-config?
    if (sunWebApp.getSessionConfig() != null) {
        SessionConfigNode scn = new SessionConfigNode();
        scn.writeDescriptor(web, RuntimeTagNames.SESSION_CONFIG, sunWebApp.getSessionConfig());
    }
    // ejb-ref*
    Set<EjbReference> ejbRefs = bundleDescriptor.getEjbReferenceDescriptors();
    if (ejbRefs.size() > 0) {
        EjbRefNode node = new EjbRefNode();
        for (EjbReference ejbRef : ejbRefs) {
            node.writeDescriptor(web, RuntimeTagNames.EJB_REF, ejbRef);
        }
    }
    // resource-ref*
    Set<ResourceReferenceDescriptor> resourceRefs = bundleDescriptor.getResourceReferenceDescriptors();
    if (resourceRefs.size() > 0) {
        ResourceRefNode node = new ResourceRefNode();
        for (ResourceReferenceDescriptor resourceRef : resourceRefs) {
            node.writeDescriptor(web, RuntimeTagNames.RESOURCE_REF, resourceRef);
        }
    }
    // resource-env-ref*
    Set<ResourceEnvReferenceDescriptor> resourceEnvRefs = bundleDescriptor.getResourceEnvReferenceDescriptors();
    if (resourceEnvRefs.size() > 0) {
        ResourceEnvRefNode node = new ResourceEnvRefNode();
        for (ResourceEnvReferenceDescriptor resourceEnvRef : resourceEnvRefs) {
            node.writeDescriptor(web, RuntimeTagNames.RESOURCE_ENV_REF, resourceEnvRef);
        }
    }
    // service-ref*
    if (bundleDescriptor.hasServiceReferenceDescriptors()) {
        ServiceRefNode serviceNode = new ServiceRefNode();
        for (ServiceReferenceDescriptor next : bundleDescriptor.getServiceReferenceDescriptors()) {
            serviceNode.writeDescriptor(web, WebServicesTagNames.SERVICE_REF, next);
        }
    }
    // message-destination-ref*
    MessageDestinationRefNode.writeMessageDestinationReferences(web, bundleDescriptor);
    // cache?
    Cache cache = sunWebApp.getCache();
    if (cache != null) {
        CacheNode cn = new CacheNode();
        cn.writeDescriptor(web, RuntimeTagNames.CACHE, cache);
    }
    // class-loader?
    ClassLoader classLoader = sunWebApp.getClassLoader();
    if (classLoader != null) {
        ClassLoaderNode cln = new ClassLoaderNode();
        cln.writeDescriptor(web, RuntimeTagNames.CLASS_LOADER, classLoader);
    }
    // jsp-config?
    if (sunWebApp.getJspConfig() != null) {
        WebPropertyNode propertyNode = new WebPropertyNode();
        Node jspConfig = appendChild(web, RuntimeTagNames.JSP_CONFIG);
        propertyNode.writeDescriptor(jspConfig, RuntimeTagNames.PROPERTY, sunWebApp.getJspConfig().getWebProperty());
    }
    // locale-charset-info?
    if (sunWebApp.getLocaleCharsetInfo() != null) {
        LocaleCharsetInfoNode localeNode = new LocaleCharsetInfoNode();
        localeNode.writeDescriptor(web, RuntimeTagNames.LOCALE_CHARSET_INFO, sunWebApp.getLocaleCharsetInfo());
    }
    // parameter-encoding?
    if (sunWebApp.isParameterEncoding()) {
        Element parameter = appendChild(web, RuntimeTagNames.PARAMETER_ENCODING);
        if (sunWebApp.getAttributeValue(SunWebApp.PARAMETER_ENCODING, SunWebApp.FORM_HINT_FIELD) != null) {
            setAttribute(parameter, RuntimeTagNames.FORM_HINT_FIELD, sunWebApp.getAttributeValue(SunWebApp.PARAMETER_ENCODING, SunWebApp.FORM_HINT_FIELD));
        }
        if (sunWebApp.getAttributeValue(SunWebApp.PARAMETER_ENCODING, SunWebApp.DEFAULT_CHARSET) != null) {
            setAttribute(parameter, RuntimeTagNames.DEFAULT_CHARSET, sunWebApp.getAttributeValue(SunWebApp.PARAMETER_ENCODING, SunWebApp.DEFAULT_CHARSET));
        }
    }
    // property*
    WebPropertyNode props = new WebPropertyNode();
    props.writeDescriptor(web, RuntimeTagNames.PROPERTY, sunWebApp.getWebProperty());
    // valve*
    if (sunWebApp.getValve() != null) {
        ValveNode valve = new ValveNode();
        valve.writeDescriptor(web, RuntimeTagNames.VALVE, sunWebApp.getValve());
    }
    // message-destination*
    RuntimeDescriptorNode.writeMessageDestinationInfo(web, bundleDescriptor);
    // webservice-description*
    WebServiceRuntimeNode webServiceNode = new WebServiceRuntimeNode();
    webServiceNode.writeWebServiceRuntimeInfo(web, bundleDescriptor);
    // error-url
    if (sunWebApp.getAttributeValue(SunWebApp.ERROR_URL) != null) {
        setAttribute(web, RuntimeTagNames.ERROR_URL, sunWebApp.getAttributeValue(SunWebApp.ERROR_URL));
    }
    // httpservlet-security-provider
    if (sunWebApp.getAttributeValue(SunWebApp.HTTPSERVLET_SECURITY_PROVIDER) != null) {
        setAttribute(web, RuntimeTagNames.HTTPSERVLET_SECURITY_PROVIDER, sunWebApp.getAttributeValue(SunWebApp.HTTPSERVLET_SECURITY_PROVIDER));
    }
    // keep-state
    appendTextChild(web, RuntimeTagNames.KEEP_STATE, String.valueOf(bundleDescriptor.getKeepState()));
    return web;
}
Also used : SunWebAppImpl(org.glassfish.web.deployment.runtime.SunWebAppImpl) Set(java.util.Set) XMLElement(com.sun.enterprise.deployment.node.XMLElement) Element(org.w3c.dom.Element) IdempotentUrlPattern(com.sun.enterprise.deployment.runtime.web.IdempotentUrlPattern) ServiceRefNode(com.sun.enterprise.deployment.node.runtime.ServiceRefNode) ResourceEnvRefNode(com.sun.enterprise.deployment.node.runtime.ResourceEnvRefNode) EjbRefNode(com.sun.enterprise.deployment.node.runtime.EjbRefNode) ServiceRefNode(com.sun.enterprise.deployment.node.runtime.ServiceRefNode) ResourceRefNode(com.sun.enterprise.deployment.node.runtime.ResourceRefNode) SecurityRoleMappingNode(com.sun.enterprise.deployment.node.runtime.common.SecurityRoleMappingNode) Node(org.w3c.dom.Node) RuntimeBundleNode(com.sun.enterprise.deployment.node.runtime.RuntimeBundleNode) RuntimeDescriptorNode(com.sun.enterprise.deployment.node.runtime.RuntimeDescriptorNode) MessageDestinationRefNode(com.sun.enterprise.deployment.node.runtime.MessageDestinationRefNode) MessageDestinationRuntimeNode(com.sun.enterprise.deployment.node.runtime.MessageDestinationRuntimeNode) WebServiceRuntimeNode(com.sun.enterprise.deployment.node.runtime.WebServiceRuntimeNode) WebBundleNode(org.glassfish.web.deployment.node.WebBundleNode) WebServiceRuntimeNode(com.sun.enterprise.deployment.node.runtime.WebServiceRuntimeNode) EjbRefNode(com.sun.enterprise.deployment.node.runtime.EjbRefNode) Iterator(java.util.Iterator) ClassLoader(org.glassfish.web.deployment.runtime.ClassLoader) ResourceReferenceDescriptor(com.sun.enterprise.deployment.ResourceReferenceDescriptor) SecurityRoleMapping(com.sun.enterprise.deployment.runtime.common.SecurityRoleMapping) ResourceRefNode(com.sun.enterprise.deployment.node.runtime.ResourceRefNode) ServiceReferenceDescriptor(com.sun.enterprise.deployment.ServiceReferenceDescriptor) SecurityRoleMappingNode(com.sun.enterprise.deployment.node.runtime.common.SecurityRoleMappingNode) EjbReference(com.sun.enterprise.deployment.types.EjbReference) WebComponentDescriptor(com.sun.enterprise.deployment.WebComponentDescriptor) ResourceEnvRefNode(com.sun.enterprise.deployment.node.runtime.ResourceEnvRefNode) ResourceEnvReferenceDescriptor(com.sun.enterprise.deployment.ResourceEnvReferenceDescriptor) Cache(org.glassfish.web.deployment.runtime.Cache)

Aggregations

WebComponentDescriptor (com.sun.enterprise.deployment.WebComponentDescriptor)31 WebBundleDescriptor (com.sun.enterprise.deployment.WebBundleDescriptor)9 WebServicesDescriptor (com.sun.enterprise.deployment.WebServicesDescriptor)5 Iterator (java.util.Iterator)5 Role (org.glassfish.security.common.Role)5 EjbBundleDescriptor (com.sun.enterprise.deployment.EjbBundleDescriptor)4 EjbDescriptor (com.sun.enterprise.deployment.EjbDescriptor)4 RunAsIdentityDescriptor (com.sun.enterprise.deployment.RunAsIdentityDescriptor)4 WebComponentContext (com.sun.enterprise.deployment.annotation.context.WebComponentContext)4 Set (java.util.Set)3 SunWebAppImpl (org.glassfish.web.deployment.runtime.SunWebAppImpl)3 ComponentEnvManager (com.sun.enterprise.container.common.spi.util.ComponentEnvManager)2 JndiNameEnvironment (com.sun.enterprise.deployment.JndiNameEnvironment)2 ServiceReferenceDescriptor (com.sun.enterprise.deployment.ServiceReferenceDescriptor)2 WebService (com.sun.enterprise.deployment.WebService)2 WebServiceEndpoint (com.sun.enterprise.deployment.WebServiceEndpoint)2 WebBundleContext (com.sun.enterprise.deployment.annotation.context.WebBundleContext)2 SecurityRoleMapping (com.sun.enterprise.deployment.runtime.common.SecurityRoleMapping)2 IdempotentUrlPattern (com.sun.enterprise.deployment.runtime.web.IdempotentUrlPattern)2 AnnotatedElement (java.lang.reflect.AnnotatedElement)2