use of com.sun.appserv.web.cache.mapping.ValueConstraint 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() });
}
}
}
Aggregations