Search in sources :

Example 1 with Field

use of com.sun.appserv.web.cache.mapping.Field in project Payara by payara.

the class DefaultCacheHelper method getCacheKey.

/**
 * getCacheKey: generate the key to be used to cache this request
 *  @param request incoming <code>HttpServletRequest</code>
 *  @return key string used to access the cache entry.
 *  Key is composed of: servletPath + a concatenation of the field values in
 *  the request; all key field names must be found in the appropriate scope.
 */
public String getCacheKey(HttpServletRequest request) {
    // cache mapping associated with the request
    CacheMapping mapping = lookupCacheMapping(request);
    if (isKeyGeneratorChecked == false && attrKeyGenerator != null) {
        try {
            keyGenerator = (CacheKeyGenerator) context.getAttribute(attrKeyGenerator);
        } catch (ClassCastException cce) {
            _logger.log(Level.WARNING, LogFacade.CACHE_DEFAULT_HELP_ILLEGAL_KET_GENERATOR, cce);
        }
        isKeyGeneratorChecked = true;
    }
    if (keyGenerator != null) {
        String key = keyGenerator.getCacheKey(context, request);
        if (key != null)
            return key;
    }
    StringBuilder sb = new StringBuilder(128);
    sb.append(request.getServletPath());
    // append the key fields
    Field[] keys = mapping.getKeyFields();
    for (int i = 0; i < keys.length; i++) {
        Object value = keys[i].getValue(context, request);
        // all defined key field must be present
        if (value == null) {
            if (_logger.isLoggable(Level.FINE)) {
                _logger.log(Level.FINE, LogFacade.REQUIRED_KEY_FIELDS_NOT_FOUND, request.getServletPath());
            }
            return null;
        }
        sb.append(";");
        sb.append(KEY_PREFIXES[keys[i].getScope()]);
        sb.append(keys[i].getName());
        sb.append("=");
        sb.append(value);
    }
    return sb.toString();
}
Also used : Field(com.sun.appserv.web.cache.mapping.Field) ConstraintField(com.sun.appserv.web.cache.mapping.ConstraintField) CacheMapping(com.sun.appserv.web.cache.mapping.CacheMapping)

Example 2 with Field

use of com.sun.appserv.web.cache.mapping.Field in project Payara by payara.

the class DefaultCacheHelper method isRefreshNeeded.

/**
 * isRefreshNeeded: is the response to given request be refreshed?
 *  @param request incoming <code>HttpServletRequest</code> object
 *  @return <code>true</code> if the response needs to be refreshed.
 *  or return <code>false</code> if the results of this request
 *  don't need to be refreshed.
 *
 *  XXX: 04/16/02 right now there is no configurability for this in
 *  ias-web.xml; should add a refresh-field element there:
 *  <refresh-field name="refresh" scope="request.parameter" />
 */
public boolean isRefreshNeeded(HttpServletRequest request) {
    boolean result = false;
    // cache mapping associated with the request
    CacheMapping mapping = lookupCacheMapping(request);
    Field field = mapping.getRefreshField();
    if (field != null) {
        Object value = field.getValue(context, request);
        // the field's string representation must be "true" or "false"
        if (value != null && "true".equals(value.toString())) {
            result = true;
        }
    }
    return result;
}
Also used : Field(com.sun.appserv.web.cache.mapping.Field) ConstraintField(com.sun.appserv.web.cache.mapping.ConstraintField) CacheMapping(com.sun.appserv.web.cache.mapping.CacheMapping)

Example 3 with Field

use of com.sun.appserv.web.cache.mapping.Field in project Payara by payara.

the class DefaultCacheHelper method getTimeout.

/**
 * get timeout for the cacheable data in this request
 *  @param request incoming <code>HttpServletRequest</code> object
 *  @return either the statically specified value or from the request
 *  fields. If not specified, get the timeout defined for the
 *  cache element.
 */
public int getTimeout(HttpServletRequest request) {
    // cache mapping associated with the request
    CacheMapping mapping = lookupCacheMapping(request);
    // get the statically configured value, if any
    int result = mapping.getTimeout();
    // if the field is not defined, return the configured value
    Field field = mapping.getTimeoutField();
    if (field != null) {
        Object value = field.getValue(context, request);
        if (value != null) {
            try {
                // Integer type timeout object
                Integer timeoutAttr = Integer.valueOf(value.toString());
                result = timeoutAttr.intValue();
            } catch (NumberFormatException cce) {
            }
        }
    }
    // Note: this could be CacheHelper.TIMEOUT_NOT_SET
    return result;
}
Also used : Field(com.sun.appserv.web.cache.mapping.Field) ConstraintField(com.sun.appserv.web.cache.mapping.ConstraintField) CacheMapping(com.sun.appserv.web.cache.mapping.CacheMapping)

Example 4 with Field

use of com.sun.appserv.web.cache.mapping.Field in project Payara by payara.

the class CacheModule method configureCacheMapping.

/**
 * configure ias-web cache-mapping
 * @param Catalina context
 * @param bean ias-web app cache-mapping config bean
 * @throws Exception
 */
private static void configureCacheMapping(org.glassfish.web.deployment.runtime.CacheMapping mapConfig, CacheMapping mapping, Logger logger) throws Exception {
    String name, scope, value, expr;
    /**
     * <cache-mapping  ((servlet-name|url-pattern)..)
     */
    mapping.setServletName(trim(mapConfig.getServletName()));
    mapping.setURLPattern(trim(mapConfig.getURLPattern()));
    // resolve the helper for this mapping
    String helperRef = mapConfig.getCacheHelperRef();
    if (helperRef == null) {
        helperRef = "default";
    }
    mapping.setHelperNameRef(helperRef);
    /**
     * <timeout>600</timeout>
     * <timeout name="cacheTimeout" scope="request.attribute" />
     */
    value = mapConfig.getTimeout();
    if (value != null) {
        try {
            mapping.setTimeout(Integer.parseInt(value.trim()));
        } catch (NumberFormatException e) {
            throw new Exception("invalid timeout", e);
        }
    } else {
        // XXX: get the timeout as a field?
        name = mapConfig.getAttributeValue(org.glassfish.web.deployment.runtime.CacheMapping.TIMEOUT, org.glassfish.web.deployment.runtime.CacheMapping.NAME);
        scope = mapConfig.getAttributeValue(org.glassfish.web.deployment.runtime.CacheMapping.TIMEOUT, org.glassfish.web.deployment.runtime.CacheMapping.SCOPE);
        if (name != null && scope != null)
            mapping.setTimeoutField(new Field(name, scope));
    }
    /**
     * <refresh-field name="refreshNow" scope="request.attribute" />
     */
    name = mapConfig.getAttributeValue(org.glassfish.web.deployment.runtime.CacheMapping.REFRESH_FIELD, org.glassfish.web.deployment.runtime.CacheMapping.NAME);
    scope = mapConfig.getAttributeValue(org.glassfish.web.deployment.runtime.CacheMapping.REFRESH_FIELD, org.glassfish.web.deployment.runtime.CacheMapping.SCOPE);
    if (name != null && scope != null) {
        Field refreshField = new Field(name, scope);
        mapping.setRefreshField(refreshField);
    }
    /**
     * <http-method> GET </http-method>
     *  <http-method> POST </http-method>
     */
    if (mapConfig.sizeHttpMethod() > 0) {
        mapping.setMethods(mapConfig.getHttpMethod());
    }
    /**
     * <key-field name="foo" scope="request.parameter"/>
     */
    for (int i = 0; i < mapConfig.sizeKeyField(); i++) {
        name = mapConfig.getAttributeValue(org.glassfish.web.deployment.runtime.CacheMapping.KEY_FIELD, i, org.glassfish.web.deployment.runtime.CacheMapping.NAME);
        scope = mapConfig.getAttributeValue(org.glassfish.web.deployment.runtime.CacheMapping.KEY_FIELD, i, org.glassfish.web.deployment.runtime.CacheMapping.SCOPE);
        if (name != null && scope != null) {
            mapping.addKeyField(new Field(name, scope));
            if (logger.isLoggable(Level.FINE)) {
                logger.log(Level.FINE, LogFacade.KEY_FIELD_ADDED, new Object[] { name, scope });
            }
        }
    }
    /**
     * <constraint-field name="foo" scope="request.parameter">
     *   <value match-expr="equals"> 200 </value>
     */
    for (int i = 0; i < mapConfig.sizeConstraintField(); i++) {
        org.glassfish.web.deployment.runtime.ConstraintField fieldConfig = mapConfig.getConstraintField(i);
        name = fieldConfig.getAttributeValue(org.glassfish.web.deployment.runtime.ConstraintField.NAME);
        scope = fieldConfig.getAttributeValue(org.glassfish.web.deployment.runtime.ConstraintField.SCOPE);
        ConstraintField constraintField = new ConstraintField(name, scope);
        value = fieldConfig.getAttributeValue(org.glassfish.web.deployment.runtime.ConstraintField.CACHE_ON_MATCH);
        if (value != null)
            constraintField.setCacheOnMatch(ConfigBeansUtilities.toBoolean(value));
        value = fieldConfig.getAttributeValue(org.glassfish.web.deployment.runtime.ConstraintField.CACHE_ON_MATCH_FAILURE);
        if (value != null)
            constraintField.setCacheOnMatchFailure(ConfigBeansUtilities.toBoolean(value));
        // now set the value's and the match expressions
        for (int j = 0; j < fieldConfig.sizeValue(); j++) {
            value = fieldConfig.getValue(j).trim();
            expr = fieldConfig.getAttributeValue(org.glassfish.web.deployment.runtime.ConstraintField.VALUE, j, org.glassfish.web.deployment.runtime.ConstraintField.MATCH_EXPR);
            ValueConstraint constraint = new ValueConstraint(value, expr);
            value = fieldConfig.getAttributeValue(org.glassfish.web.deployment.runtime.ConstraintField.VALUE, j, org.glassfish.web.deployment.runtime.ConstraintField.CACHE_ON_MATCH);
            if (value != null) {
                constraint.setCacheOnMatch(ConfigBeansUtilities.toBoolean(value));
            }
            value = fieldConfig.getAttributeValue(org.glassfish.web.deployment.runtime.ConstraintField.VALUE, j, org.glassfish.web.deployment.runtime.ConstraintField.CACHE_ON_MATCH_FAILURE);
            if (value != null) {
                constraint.setCacheOnMatchFailure(ConfigBeansUtilities.toBoolean(value));
            }
            constraintField.addConstraint(constraint);
            if (logger.isLoggable(Level.FINE)) {
                logger.log(Level.FINE, LogFacade.CONSTRAINT_ADDED, constraint.toString());
            }
        }
        mapping.addConstraintField(constraintField);
        if (logger.isLoggable(Level.FINE)) {
            logger.log(Level.FINE, LogFacade.CONSTRAINT_FIELD_ADDED, new Object[] { name, scope, constraintField.getCacheOnMatch(), constraintField.getCacheOnMatchFailure() });
        }
    }
}
Also used : Field(com.sun.appserv.web.cache.mapping.Field) ConstraintField(com.sun.appserv.web.cache.mapping.ConstraintField) ConstraintField(com.sun.appserv.web.cache.mapping.ConstraintField) ValueConstraint(com.sun.appserv.web.cache.mapping.ValueConstraint) org.glassfish.web.deployment.runtime(org.glassfish.web.deployment.runtime) ValueConstraint(com.sun.appserv.web.cache.mapping.ValueConstraint)

Aggregations

ConstraintField (com.sun.appserv.web.cache.mapping.ConstraintField)4 Field (com.sun.appserv.web.cache.mapping.Field)4 CacheMapping (com.sun.appserv.web.cache.mapping.CacheMapping)3 ValueConstraint (com.sun.appserv.web.cache.mapping.ValueConstraint)1 org.glassfish.web.deployment.runtime (org.glassfish.web.deployment.runtime)1