Search in sources :

Example 1 with Cache

use of org.glassfish.web.deployment.runtime.Cache in project Payara by payara.

the class ASCacheHelperClass method check.

public Result check(WebBundleDescriptor descriptor) {
    Result result = getInitializedResult();
    ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
    boolean oneFailed = false;
    boolean notApp = false;
    boolean oneWarning = false;
    boolean presentHelper = false;
    try {
        Cache cache = ((SunWebAppImpl) descriptor.getSunDescriptor()).getCache();
        CacheHelper[] helperClasses = null;
        CacheHelper helperClass = null;
        WebProperty[] webProps;
        String name = null;
        String classname = null;
        String[] names = null;
        // to-do vkv# check for class-name attribute.
        if (cache != null)
            helperClasses = cache.getCacheHelper();
        if (cache != null && helperClasses != null && helperClasses.length > 0) {
            names = new String[helperClasses.length];
            for (int rep = 0; rep < helperClasses.length; rep++) {
                helperClass = helperClasses[rep];
                if (helperClass == null)
                    continue;
                int i = rep + 1;
                name = getXPathValue("sun-web-app/cache/cache-helper[" + i + "]/@name");
                classname = getXPathValue("sun-web-app/cache/cache-helper[" + i + "]/@class-name");
                Class hClass = null;
                names[rep] = name;
                if (name != null && name.length() != 0) {
                    // check if the name already exist
                    boolean isDuplicate = false;
                    for (int rep1 = 0; rep1 < rep; rep1++) {
                        if (name.equals(names[rep1])) {
                            isDuplicate = true;
                            break;
                        }
                    }
                    if (isDuplicate) {
                        oneFailed = true;
                        addErrorDetails(result, compName);
                        result.failed(smh.getLocalString(getClass().getName() + ".failed", "FAILED [AS-WEB cache-helper] name attribute [ {0} ], must be unique in the entire list of cache-helper.", new Object[] { name }));
                    } else {
                        if (classname != null && classname.length() != 0) {
                            hClass = loadClass(result, classname);
                        }
                        if (hClass != null)
                            presentHelper = true;
                        else
                            presentHelper = false;
                        if (!presentHelper) {
                            addWarningDetails(result, compName);
                            result.warning(smh.getLocalString(getClass().getName() + ".error", "WARNING [AS-WEB cache-helper] " + "name [ {0} ], class not present in the war file.", new Object[] { name }));
                            oneWarning = true;
                        } else {
                            addGoodDetails(result, compName);
                            result.passed(smh.getLocalString(getClass().getName() + ".passed", "PASSED [AS-WEB cache-helper] name  [ {0} ], helper class is valid.", new Object[] { name }));
                        }
                    }
                } else {
                    addErrorDetails(result, compName);
                    result.failed(smh.getLocalString(getClass().getName() + ".failed1", "FAILED [AS-WEB cache-helper] name [ {0} ], either empty or null.", new Object[] { name }));
                    oneFailed = true;
                }
                webProps = helperClass.getWebProperty();
                if (ASWebProperty.checkWebProperties(webProps, result, descriptor, this)) {
                    oneFailed = true;
                    addErrorDetails(result, compName);
                    result.failed(smh.getLocalString(getClass().getName() + ".failed2", "FAILED [AS-WEB cache-helper] Atleast one name/value pair is not valid in helper-class of [ {0} ].", new Object[] { descriptor.getName() }));
                }
            }
        // end of for
        } else {
            notApp = true;
            addNaDetails(result, compName);
            result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable", "NOT APPLICABLE [AS-WEB cache-helper] There is no cache-helper element for the web application", new Object[] { descriptor.getName() }));
        }
        if (oneFailed) {
            result.setStatus(Result.FAILED);
        } else if (oneWarning) {
            result.setStatus(Result.WARNING);
        } else if (notApp) {
            result.setStatus(Result.NOT_APPLICABLE);
        } else {
            result.setStatus(Result.PASSED);
        }
    } catch (Exception ex) {
        oneFailed = true;
        addErrorDetails(result, compName);
        result.failed(smh.getLocalString(getClass().getName() + ".failed3", "FAILED [AS-WEB cache-helper] could not create the cache object"));
    }
    return result;
}
Also used : SunWebAppImpl(org.glassfish.web.deployment.runtime.SunWebAppImpl) CacheHelper(org.glassfish.web.deployment.runtime.CacheHelper) WebProperty(org.glassfish.web.deployment.runtime.WebProperty) Result(com.sun.enterprise.tools.verifier.Result) ComponentNameConstructor(com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor) Cache(org.glassfish.web.deployment.runtime.Cache)

Example 2 with Cache

use of org.glassfish.web.deployment.runtime.Cache 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)

Example 3 with Cache

use of org.glassfish.web.deployment.runtime.Cache in project Payara by payara.

the class WebBundleRuntimeNode method addDescriptor.

/**
 * Adds a new DOL descriptor instance to the descriptor instance associated with this XMLNode
 *
 * @param newDescriptor the new descriptor
 */
@Override
public void addDescriptor(Object newDescriptor) {
    SunWebAppImpl sunWebApp = (SunWebAppImpl) descriptor.getSunDescriptor();
    if (newDescriptor instanceof WebComponentDescriptor) {
        WebComponentDescriptor servlet = (WebComponentDescriptor) newDescriptor;
        // for backward compatibility with s1as schema2beans generated desc
        Servlet s1descriptor = new Servlet();
        s1descriptor.setServletName(servlet.getCanonicalName());
        if (servlet.getRunAsIdentity() != null) {
            s1descriptor.setPrincipalName(servlet.getRunAsIdentity().getPrincipal());
        }
        sunWebApp.addServlet(s1descriptor);
    } else if (newDescriptor instanceof ServiceReferenceDescriptor) {
        descriptor.addServiceReferenceDescriptor((ServiceReferenceDescriptor) newDescriptor);
    } else if (newDescriptor instanceof SecurityRoleMapping) {
        SecurityRoleMapping srm = (SecurityRoleMapping) newDescriptor;
        sunWebApp.addSecurityRoleMapping(srm);
        // store it in the application using pure DOL descriptors...
        Application app = descriptor.getApplication();
        if (app != null) {
            Role role = new Role(srm.getRoleName());
            SecurityRoleMapper rm = app.getRoleMapper();
            if (rm != null) {
                List<PrincipalNameDescriptor> principals = srm.getPrincipalNames();
                for (int i = 0; i < principals.size(); i++) {
                    rm.assignRole(principals.get(i).getPrincipal(), role, descriptor);
                }
                List<String> groups = srm.getGroupNames();
                for (int i = 0; i < groups.size(); i++) {
                    rm.assignRole(new Group(groups.get(i)), role, descriptor);
                }
            }
        }
    } else if (newDescriptor instanceof IdempotentUrlPattern) {
        sunWebApp.addIdempotentUrlPattern((IdempotentUrlPattern) newDescriptor);
    } else if (newDescriptor instanceof SessionConfig) {
        sunWebApp.setSessionConfig((SessionConfig) newDescriptor);
    } else if (newDescriptor instanceof Cache) {
        sunWebApp.setCache((Cache) newDescriptor);
    } else if (newDescriptor instanceof ClassLoader) {
        sunWebApp.setClassLoader((ClassLoader) newDescriptor);
    } else if (newDescriptor instanceof JspConfig) {
        sunWebApp.setJspConfig((JspConfig) newDescriptor);
    } else if (newDescriptor instanceof LocaleCharsetInfo) {
        sunWebApp.setLocaleCharsetInfo((LocaleCharsetInfo) newDescriptor);
    } else if (newDescriptor instanceof WebProperty) {
        sunWebApp.addWebProperty((WebProperty) newDescriptor);
    } else if (newDescriptor instanceof Valve) {
        sunWebApp.addValve((Valve) newDescriptor);
    } else
        super.addDescriptor(descriptor);
}
Also used : SunWebAppImpl(org.glassfish.web.deployment.runtime.SunWebAppImpl) Group(org.glassfish.security.common.Group) JspConfig(org.glassfish.web.deployment.runtime.JspConfig) WebProperty(org.glassfish.web.deployment.runtime.WebProperty) SecurityRoleMapping(com.sun.enterprise.deployment.runtime.common.SecurityRoleMapping) SecurityRoleMapper(org.glassfish.deployment.common.SecurityRoleMapper) IdempotentUrlPattern(com.sun.enterprise.deployment.runtime.web.IdempotentUrlPattern) PrincipalNameDescriptor(com.sun.enterprise.deployment.runtime.common.PrincipalNameDescriptor) SessionConfig(org.glassfish.web.deployment.runtime.SessionConfig) ServiceReferenceDescriptor(com.sun.enterprise.deployment.ServiceReferenceDescriptor) Role(org.glassfish.security.common.Role) WebComponentDescriptor(com.sun.enterprise.deployment.WebComponentDescriptor) Servlet(org.glassfish.web.deployment.runtime.Servlet) ClassLoader(org.glassfish.web.deployment.runtime.ClassLoader) Valve(org.glassfish.web.deployment.runtime.Valve) Application(com.sun.enterprise.deployment.Application) LocaleCharsetInfo(org.glassfish.web.deployment.runtime.LocaleCharsetInfo) Cache(org.glassfish.web.deployment.runtime.Cache)

Example 4 with Cache

use of org.glassfish.web.deployment.runtime.Cache in project Payara by payara.

the class ASCacheMapping method check.

public Result check(WebBundleDescriptor descriptor) {
    Result result = getInitializedResult();
    ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
    boolean notApp = false;
    // Cache cache = getCache(descriptor);
    try {
        Cache cache = ((SunWebAppImpl) descriptor.getSunDescriptor()).getCache();
        CacheMapping[] cacheMapp = null;
        String servletName = null;
        String urlPattern = null;
        String timeout = null;
        String[] httpMethods;
        // boolean[] keyFields;
        String cacheHelperRef;
        if (cache != null) {
            cacheMapp = cache.getCacheMapping();
        }
        if (cache != null && cacheMapp != null && cacheMapp.length != 0) {
            for (int rep = 0; rep < cacheMapp.length; rep++) {
                servletName = cacheMapp[rep].getServletName();
                urlPattern = cacheMapp[rep].getURLPattern();
                timeout = cacheMapp[rep].getTimeout();
                httpMethods = cacheMapp[rep].getHttpMethod();
                cacheHelperRef = cacheMapp[rep].getCacheHelperRef();
                if (servletName != null) {
                    if (validServletName(servletName, descriptor)) {
                        addGoodDetails(result, compName);
                        result.passed(smh.getLocalString(getClass().getName() + ".passed", "PASSED [AS-WEB cache-mapping] servlet-name  [ {0} ] properly defined.", new Object[] { servletName }));
                    } else {
                        addErrorDetails(result, compName);
                        result.failed(smh.getLocalString(getClass().getName() + ".failed", "FAILED [AS-WEB cache-mapping] servlet-name [ {0} ], does not exist in the web application.", new Object[] { servletName }));
                        oneFailed = true;
                    }
                } else if (urlPattern != null) {
                    if (validURL(urlPattern)) {
                        addGoodDetails(result, compName);
                        result.passed(smh.getLocalString(getClass().getName() + ".passed1", "PASSED [AS-WEB cache-mapping] url-pattern [ {0} ] properly defined.", new Object[] { urlPattern }));
                    } else {
                        addErrorDetails(result, compName);
                        result.failed(smh.getLocalString(getClass().getName() + ".failed1", "FAILED [AS-WEB cache-mapping] url-pattern [ {0} ], does not exist in  the web application.", new Object[] { urlPattern }));
                        oneFailed = true;
                    }
                }
                if (cacheHelperRef != null) {
                    // test cache-helper-ref
                    if (validCacheHelperRef(cacheHelperRef, cache)) {
                        addGoodDetails(result, compName);
                        result.passed(smh.getLocalString(getClass().getName() + ".passed2", "PASSED [AS-WEB cache-mapping] cache-helper-ref element [ {0} ]  defined properly.", new Object[] { cacheHelperRef }));
                    } else {
                        oneFailed = true;
                        addErrorDetails(result, compName);
                        result.failed(smh.getLocalString(getClass().getName() + ".failed2", "FAILED [AS-WEB cache-mapping] cache-helper-ref [ {0} ] not valid, either empty or  cache-helper not defined for it.", new Object[] { cacheHelperRef }));
                    }
                } else {
                    if (timeout != null) {
                        int i = rep + 1;
                        String timeoutName = getXPathValue("sun-web-app/cache/cache-mapping[" + i + "]/timeout/@name");
                        if (validTimeout(timeout, timeoutName)) {
                            addGoodDetails(result, compName);
                            result.passed(smh.getLocalString(getClass().getName() + ".passed3", "PASSED [AS-WEB cache-mapping] timeout element [ {0} ] properly defined.", new Object[] { new Integer(timeout) }));
                        } else {
                            oneFailed = true;
                            addErrorDetails(result, compName);
                            result.failed(smh.getLocalString(getClass().getName() + ".failed3", "FAILED [AS-WEB cache-mapping] timeout element [{0}] must be a Long ( Not less than -1 and not more that MAX_LONG) and its name attribute [{1}] can not be empty/null.", new Object[] { timeout, timeoutName }));
                        }
                    }
                    // <addition author="irfan@sun.com" [bug/rfe]-id="4706026" >
                    int j = rep + 1;
                    int count = getCountNodeSet("sun-web-app/cache/cache-mapping[" + j + "]/refresh-field");
                    if (// refresh field element present
                    count > 0) {
                        String cacheMapName = null;
                        if (cacheMapp[rep].getServletName() != null)
                            cacheMapName = cacheMapp[rep].getServletName();
                        else
                            cacheMapName = cacheMapp[rep].getURLPattern();
                        String name = getXPathValue("sun-web-app/cache/cache-mapping[" + j + "]/refresh-field/@name");
                        if (name != null && name.length() != 0) {
                            addGoodDetails(result, compName);
                            result.passed(smh.getLocalString(getClass().getName() + ".passed3a", "PASSED [AS-WEB cache-mapping] for {0}, refresh-field name [{1}] has been furnished", new Object[] { cacheMapName, name }));
                        } else {
                            addErrorDetails(result, compName);
                            result.failed(smh.getLocalString(getClass().getName() + ".failed3a", "FAILED [AS-WEB cache-mapping] for {0}, refresh-field name [{1}] cannot be empty/null string", new Object[] { cacheMapName, name }));
                            oneFailed = true;
                        }
                    }
                    // </addition>
                    if (checkHTTPMethodList(httpMethods, result, compName, descriptor)) {
                    } else {
                        oneFailed = true;
                        addErrorDetails(result, compName);
                        result.failed(smh.getLocalString(getClass().getName() + ".failed4", "FAILED [AS-WEB cache-mapping] http-method - List of HTTP methods is not proper, " + " atleast one of the method name in the list is empty/null "));
                    }
                    // <addition author="irfan@sun.com" [bug/rfe]-id="4706026" >
                    if ((getCountNodeSet("sun-web-app/cache/cache-mapping[" + j + "]/key-field")) > 0)
                        testForKeyFields(cache, j, result, compName);
                // </addition>
                }
            }
        } else {
            notApp = true;
            addNaDetails(result, compName);
            result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable", "NOT APPLICABLE [AS-WEB cache-mapping] element not defined", new Object[] { descriptor.getName() }));
        }
        if (oneFailed) {
            result.setStatus(Result.FAILED);
        } else if (oneWarning) {
            result.setStatus(Result.WARNING);
        } else if (notApp) {
            result.setStatus(Result.NOT_APPLICABLE);
        } else {
            result.setStatus(Result.PASSED);
        }
    } catch (Exception ex) {
        oneFailed = true;
        addErrorDetails(result, compName);
        result.failed(smh.getLocalString(getClass().getName() + ".failed7", "FAILED [AS-WEB cache-mapping] could not create the cache object"));
    }
    return result;
}
Also used : SunWebAppImpl(org.glassfish.web.deployment.runtime.SunWebAppImpl) Result(com.sun.enterprise.tools.verifier.Result) CacheMapping(org.glassfish.web.deployment.runtime.CacheMapping) ComponentNameConstructor(com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor) Cache(org.glassfish.web.deployment.runtime.Cache)

Example 5 with Cache

use of org.glassfish.web.deployment.runtime.Cache in project Payara by payara.

the class ASCacheMappingFieldConstraint method check.

public Result check(WebBundleDescriptor descriptor) {
    Result result = getInitializedResult();
    ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
    boolean oneFailed = false;
    boolean notApp = false;
    boolean doneAtleastOnce = false;
    try {
        Cache cache = ((SunWebAppImpl) descriptor.getSunDescriptor()).getCache();
        CacheMapping[] cacheMapp = null;
        String servletName;
        String urlPattern;
        ConstraintField[] fieldConstraints = null;
        String mappingFor = null;
        if (cache != null) {
            cacheMapp = cache.getCacheMapping();
        }
        if (cache != null && cacheMapp != null && cacheMapp.length != 0) {
            for (int rep = 0; rep < cacheMapp.length; rep++) {
                servletName = cacheMapp[rep].getServletName();
                urlPattern = cacheMapp[rep].getURLPattern();
                if (servletName != null)
                    mappingFor = servletName;
                else
                    mappingFor = urlPattern;
                fieldConstraints = cacheMapp[rep].getConstraintField();
                if (fieldConstraints != null && fieldConstraints.length != 0) {
                    for (int rep1 = 0; rep1 < fieldConstraints.length; rep1++) {
                        if (fieldConstraints[rep1] != null) {
                            doneAtleastOnce = true;
                            if (checkFieldConstraint(fieldConstraints[rep1], result, mappingFor, descriptor, compName)) {
                            // nothing more required
                            } else {
                                oneFailed = true;
                                addErrorDetails(result, compName);
                                result.failed(smh.getLocalString(getClass().getName() + ".failed", "FAILED [AS-WEB cache-mapping] List of field-constraint in cache-mapping for [ {0} ] is not proper,  within the web archive/(gf/)sun-web.xml of [ {1} ].", new Object[] { mappingFor, descriptor.getName() }));
                            }
                        }
                    }
                // end of for(int rep1=0;rep1 < fieldConstraints.length;rep1++)
                }
            }
        // end of for(int rep=0;rep < cacheMapp.length;rep++)
        } else {
            notApp = true;
        }
        if (oneFailed) {
            result.setStatus(Result.FAILED);
        } else if (notApp || !doneAtleastOnce) {
            result.setStatus(Result.NOT_APPLICABLE);
            addNaDetails(result, compName);
            result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable", "NOT APPLICABLE [AS-WEB cache-mapping ] constraint-field not defined in [ {0} ].", new Object[] { descriptor.getName() }));
        } else {
            result.setStatus(Result.PASSED);
        }
    } catch (Exception ex) {
        oneFailed = true;
        addErrorDetails(result, compName);
        result.failed(smh.getLocalString(getClass().getName() + ".failed", "FAILED [AS-WEB cache-mapping] could not create the cache object"));
    }
    return result;
}
Also used : SunWebAppImpl(org.glassfish.web.deployment.runtime.SunWebAppImpl) ConstraintField(org.glassfish.web.deployment.runtime.ConstraintField) CacheMapping(org.glassfish.web.deployment.runtime.CacheMapping) Cache(org.glassfish.web.deployment.runtime.Cache)

Aggregations

Cache (org.glassfish.web.deployment.runtime.Cache)5 SunWebAppImpl (org.glassfish.web.deployment.runtime.SunWebAppImpl)5 ServiceReferenceDescriptor (com.sun.enterprise.deployment.ServiceReferenceDescriptor)2 WebComponentDescriptor (com.sun.enterprise.deployment.WebComponentDescriptor)2 SecurityRoleMapping (com.sun.enterprise.deployment.runtime.common.SecurityRoleMapping)2 IdempotentUrlPattern (com.sun.enterprise.deployment.runtime.web.IdempotentUrlPattern)2 Result (com.sun.enterprise.tools.verifier.Result)2 ComponentNameConstructor (com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor)2 CacheMapping (org.glassfish.web.deployment.runtime.CacheMapping)2 ClassLoader (org.glassfish.web.deployment.runtime.ClassLoader)2 WebProperty (org.glassfish.web.deployment.runtime.WebProperty)2 Application (com.sun.enterprise.deployment.Application)1 ResourceEnvReferenceDescriptor (com.sun.enterprise.deployment.ResourceEnvReferenceDescriptor)1 ResourceReferenceDescriptor (com.sun.enterprise.deployment.ResourceReferenceDescriptor)1 XMLElement (com.sun.enterprise.deployment.node.XMLElement)1 EjbRefNode (com.sun.enterprise.deployment.node.runtime.EjbRefNode)1 MessageDestinationRefNode (com.sun.enterprise.deployment.node.runtime.MessageDestinationRefNode)1 MessageDestinationRuntimeNode (com.sun.enterprise.deployment.node.runtime.MessageDestinationRuntimeNode)1 ResourceEnvRefNode (com.sun.enterprise.deployment.node.runtime.ResourceEnvRefNode)1 ResourceRefNode (com.sun.enterprise.deployment.node.runtime.ResourceRefNode)1