Search in sources :

Example 1 with CacheMapping

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

the class CacheNode method writeDescriptor.

/**
 * write the descriptor class to a DOM tree and return it
 *
 * @param parent node for the DOM tree
 * @param nodeName node name
 * @param descriptor the descriptor to write
 * @return the DOM tree top node
 */
@Override
public Node writeDescriptor(Node parent, String nodeName, Cache descriptor) {
    Element cache = (Element) super.writeDescriptor(parent, nodeName, descriptor);
    // cache-helpers*
    CacheHelper[] cacheHelpers = descriptor.getCacheHelper();
    if (cacheHelpers != null && cacheHelpers.length > 0) {
        CacheHelperNode chn = new CacheHelperNode();
        for (int i = 0; i < cacheHelpers.length; i++) {
            chn.writeDescriptor(cache, RuntimeTagNames.CACHE_HELPER, cacheHelpers[i]);
        }
    }
    WebPropertyNode wpn = new WebPropertyNode();
    // default-helper?
    DefaultHelper dh = descriptor.getDefaultHelper();
    if (dh != null && dh.getWebProperty() != null) {
        Node dhn = appendChild(cache, RuntimeTagNames.DEFAULT_HELPER);
        wpn.writeDescriptor(dhn, RuntimeTagNames.PROPERTY, dh.getWebProperty());
    }
    // property*
    wpn.writeDescriptor(cache, RuntimeTagNames.PROPERTY, descriptor.getWebProperty());
    // cache-mapping
    CacheMapping[] mappings = descriptor.getCacheMapping();
    if (mappings != null && mappings.length > 0) {
        CacheMappingNode cmn = new CacheMappingNode();
        for (int i = 0; i < mappings.length; i++) {
            cmn.writeDescriptor(cache, RuntimeTagNames.CACHE_MAPPING, mappings[i]);
        }
    }
    // max-entries, timeout-in-seconds, enabled
    setAttribute(cache, RuntimeTagNames.MAX_ENTRIES, (String) descriptor.getAttributeValue(Cache.MAX_ENTRIES));
    setAttribute(cache, RuntimeTagNames.TIMEOUT_IN_SECONDS, (String) descriptor.getAttributeValue(Cache.TIMEOUT_IN_SECONDS));
    setAttribute(cache, RuntimeTagNames.ENABLED, (String) descriptor.getAttributeValue(Cache.ENABLED));
    return cache;
}
Also used : DefaultHelper(org.glassfish.web.deployment.runtime.DefaultHelper) CacheHelper(org.glassfish.web.deployment.runtime.CacheHelper) Element(org.w3c.dom.Element) XMLElement(com.sun.enterprise.deployment.node.XMLElement) Node(org.w3c.dom.Node) RuntimeDescriptorNode(com.sun.enterprise.deployment.node.runtime.RuntimeDescriptorNode) CacheMapping(org.glassfish.web.deployment.runtime.CacheMapping)

Example 2 with CacheMapping

use of org.glassfish.web.deployment.runtime.CacheMapping 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 3 with CacheMapping

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

CacheMapping (org.glassfish.web.deployment.runtime.CacheMapping)3 Cache (org.glassfish.web.deployment.runtime.Cache)2 SunWebAppImpl (org.glassfish.web.deployment.runtime.SunWebAppImpl)2 XMLElement (com.sun.enterprise.deployment.node.XMLElement)1 RuntimeDescriptorNode (com.sun.enterprise.deployment.node.runtime.RuntimeDescriptorNode)1 Result (com.sun.enterprise.tools.verifier.Result)1 ComponentNameConstructor (com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor)1 CacheHelper (org.glassfish.web.deployment.runtime.CacheHelper)1 ConstraintField (org.glassfish.web.deployment.runtime.ConstraintField)1 DefaultHelper (org.glassfish.web.deployment.runtime.DefaultHelper)1 Element (org.w3c.dom.Element)1 Node (org.w3c.dom.Node)1