diff --git a/bundle/src/main/java/com/adobe/acs/commons/httpcache/config/impl/AbstractKeyValueExtension.java b/bundle/src/main/java/com/adobe/acs/commons/httpcache/config/impl/AbstractKeyValueExtension.java index 66c31a4470..1445208b5f 100644 --- a/bundle/src/main/java/com/adobe/acs/commons/httpcache/config/impl/AbstractKeyValueExtension.java +++ b/bundle/src/main/java/com/adobe/acs/commons/httpcache/config/impl/AbstractKeyValueExtension.java @@ -29,13 +29,7 @@ import java.util.Map; public abstract class AbstractKeyValueExtension implements HttpCacheConfigExtension, CacheKeyFactory { - - abstract public Map getAllowedKeyValues(); - - abstract public boolean accepts(SlingHttpServletRequest request, HttpCacheConfig cacheConfig, Map allowedKeyValues); - - abstract public String getCacheKeyId(); - + @Override public boolean accepts(SlingHttpServletRequest request, HttpCacheConfig cacheConfig) { return accepts(request, cacheConfig, getAllowedKeyValues()); @@ -61,4 +55,9 @@ public boolean doesKeyMatchConfig(CacheKey key, HttpCacheConfig cacheConfig) { return new KeyValueCacheKey(key.getUri(), cacheConfig, getCacheKeyId(), getAllowedKeyValues()).equals(key); } + abstract public Map getAllowedKeyValues(); + + abstract public boolean accepts(SlingHttpServletRequest request, HttpCacheConfig cacheConfig, Map allowedKeyValues); + + abstract public String getCacheKeyId(); } diff --git a/bundle/src/main/java/com/adobe/acs/commons/httpcache/config/impl/RequestHeaderHttpCacheConfigExtension.java b/bundle/src/main/java/com/adobe/acs/commons/httpcache/config/impl/RequestHeaderHttpCacheConfigExtension.java index 638d99dee0..0571791c05 100644 --- a/bundle/src/main/java/com/adobe/acs/commons/httpcache/config/impl/RequestHeaderHttpCacheConfigExtension.java +++ b/bundle/src/main/java/com/adobe/acs/commons/httpcache/config/impl/RequestHeaderHttpCacheConfigExtension.java @@ -37,6 +37,9 @@ import java.util.Map; import java.util.UUID; +import static org.apache.commons.lang3.ArrayUtils.contains; +import static org.apache.commons.lang3.ArrayUtils.isEmpty; + /** * RequestHeaderHttpCacheConfigExtension *

@@ -95,12 +98,9 @@ public boolean accepts(SlingHttpServletRequest request, HttpCacheConfig cacheCon final String header = request.getHeader(entry.getKey()); if (header != null) { - if (ArrayUtils.isEmpty(entry.getValue())) { + if (isEmpty(entry.getValue()) || contains(entry.getValue(), header)) { // If no values were specified, then assume ANY and ALL values are acceptable, and were are merely looking for the existence of the request header return true; - } else if (ArrayUtils.contains(entry.getValue(), header)) { - // The request header value matched one of the allowed values - return true; } // No matches found for this row; continue looking through the allowed list } diff --git a/bundle/src/main/java/com/adobe/acs/commons/httpcache/config/impl/RequestParameterHttpCacheConfigExtension.java b/bundle/src/main/java/com/adobe/acs/commons/httpcache/config/impl/RequestParameterHttpCacheConfigExtension.java index b6febc3036..861edc6a92 100644 --- a/bundle/src/main/java/com/adobe/acs/commons/httpcache/config/impl/RequestParameterHttpCacheConfigExtension.java +++ b/bundle/src/main/java/com/adobe/acs/commons/httpcache/config/impl/RequestParameterHttpCacheConfigExtension.java @@ -39,6 +39,9 @@ import java.util.Map; import java.util.UUID; +import static org.apache.commons.collections.CollectionUtils.containsAny; +import static org.apache.commons.lang3.ArrayUtils.isEmpty; + /** * RequestParameterHttpCacheConfigExtension *

@@ -98,12 +101,9 @@ public boolean accepts(SlingHttpServletRequest request, HttpCacheConfig cacheCon if (request.getParameterMap().keySet().contains(entry.getKey())) { final String[] parameterValues = request.getParameterMap().get(entry.getKey()); - if (ArrayUtils.isEmpty(entry.getValue())) { + if (isEmpty(entry.getValue()) || containsAny(Arrays.asList(entry.getValue()), Arrays.asList(parameterValues))) { // If no values were specified, then assume ANY and ALL values are acceptable, and were are merely looking for the existence of the request parameter return true; - } else if (CollectionUtils.containsAny(Arrays.asList(entry.getValue()), Arrays.asList(parameterValues))) { - // The request parameter value matched one of the allowed values - return true; } // No matches found for this row; continue looking through the allowed list } diff --git a/bundle/src/main/java/com/adobe/acs/commons/httpcache/config/impl/ResourcePropertiesHttpCacheConfigExtension.java b/bundle/src/main/java/com/adobe/acs/commons/httpcache/config/impl/ResourcePropertiesHttpCacheConfigExtension.java index ae5585a79d..6166c0da59 100644 --- a/bundle/src/main/java/com/adobe/acs/commons/httpcache/config/impl/ResourcePropertiesHttpCacheConfigExtension.java +++ b/bundle/src/main/java/com/adobe/acs/commons/httpcache/config/impl/ResourcePropertiesHttpCacheConfigExtension.java @@ -35,7 +35,14 @@ import org.osgi.service.metatype.annotations.Designate; import org.osgi.service.metatype.annotations.ObjectClassDefinition; -import java.util.*; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +import static org.apache.commons.collections.CollectionUtils.containsAny; +import static org.apache.commons.lang3.ArrayUtils.isEmpty; + /** * ResourcePropertiesHttpCacheConfigExtension @@ -97,12 +104,9 @@ public boolean accepts(SlingHttpServletRequest request, HttpCacheConfig cacheCon if (properties.containsKey(entry.getKey())) { final String[] propertyValues = properties.get(entry.getKey(), String[].class); - if (ArrayUtils.isEmpty(propertyValues)) { + if (isEmpty(propertyValues) || containsAny(Arrays.asList(entry.getValue()), Arrays.asList(propertyValues))) { // If no values were specified, then assume ANY and ALL values are acceptable, and were are merely looking for the existence of the property return true; - } else if (CollectionUtils.containsAny(Arrays.asList(entry.getValue()), Arrays.asList(propertyValues))) { - // The resource property value matched one of the allowed values - return true; } // No matches found for this row; continue looking through the allowed list } diff --git a/bundle/src/main/java/com/adobe/acs/commons/httpcache/engine/impl/HttpCacheEngineImpl.java b/bundle/src/main/java/com/adobe/acs/commons/httpcache/engine/impl/HttpCacheEngineImpl.java index f12e7efbdc..e258c5e7ef 100644 --- a/bundle/src/main/java/com/adobe/acs/commons/httpcache/engine/impl/HttpCacheEngineImpl.java +++ b/bundle/src/main/java/com/adobe/acs/commons/httpcache/engine/impl/HttpCacheEngineImpl.java @@ -35,7 +35,19 @@ import com.adobe.granite.jmx.annotation.AnnotatedStandardMBean; import org.apache.commons.io.IOUtils; import org.apache.commons.lang.StringUtils; -import org.apache.felix.scr.annotations.*; +import org.apache.felix.scr.annotations.Component; +import org.apache.felix.scr.annotations.PropertyUnbounded; +import org.apache.felix.scr.annotations.Properties; +import org.apache.felix.scr.annotations.Property; +import org.apache.felix.scr.annotations.Activate; +import org.apache.felix.scr.annotations.Deactivate; +import org.apache.felix.scr.annotations.Service; +import org.apache.felix.scr.annotations.Reference; +import org.apache.felix.scr.annotations.References; +import org.apache.felix.scr.annotations.ReferencePolicy; +import org.apache.felix.scr.annotations.ReferencePolicyOption; +import org.apache.felix.scr.annotations.ReferenceCardinality; + import org.apache.sling.api.SlingHttpServletRequest; import org.apache.sling.api.SlingHttpServletResponse; import org.apache.sling.commons.osgi.PropertiesUtil; diff --git a/bundle/src/main/java/com/adobe/acs/commons/httpcache/store/caffeine/impl/CaffeineCacheMBean.java b/bundle/src/main/java/com/adobe/acs/commons/httpcache/store/caffeine/impl/CaffeineCacheMBean.java index f0585b81e4..2252e10286 100644 --- a/bundle/src/main/java/com/adobe/acs/commons/httpcache/store/caffeine/impl/CaffeineCacheMBean.java +++ b/bundle/src/main/java/com/adobe/acs/commons/httpcache/store/caffeine/impl/CaffeineCacheMBean.java @@ -1,3 +1,22 @@ +/* + * #%L + * ACS AEM Commons Bundle + * %% + * Copyright (C) 2013 Adobe + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * #L% + */ package com.adobe.acs.commons.httpcache.store.caffeine.impl; import com.adobe.acs.commons.util.impl.CacheMBean; diff --git a/bundle/src/main/java/com/adobe/acs/commons/httpcache/store/caffeine/impl/CaffeineMemHttpCacheStoreImpl.java b/bundle/src/main/java/com/adobe/acs/commons/httpcache/store/caffeine/impl/CaffeineMemHttpCacheStoreImpl.java index e75a78b433..6969d51ca5 100644 --- a/bundle/src/main/java/com/adobe/acs/commons/httpcache/store/caffeine/impl/CaffeineMemHttpCacheStoreImpl.java +++ b/bundle/src/main/java/com/adobe/acs/commons/httpcache/store/caffeine/impl/CaffeineMemHttpCacheStoreImpl.java @@ -33,7 +33,14 @@ import com.github.benmanes.caffeine.cache.*; import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; -import org.apache.felix.scr.annotations.*; + +import org.apache.felix.scr.annotations.Component; +import org.apache.felix.scr.annotations.ConfigurationPolicy; +import org.apache.felix.scr.annotations.Properties; +import org.apache.felix.scr.annotations.Property; +import org.apache.felix.scr.annotations.Activate; +import org.apache.felix.scr.annotations.Deactivate; +import org.apache.felix.scr.annotations.Service; import org.apache.sling.commons.osgi.PropertiesUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/bundle/src/test/java/com/adobe/acs/commons/httpcache/store/caffeine/impl/CaffeineMemHttpCacheStoreImplTest.java b/bundle/src/test/java/com/adobe/acs/commons/httpcache/store/caffeine/impl/CaffeineMemHttpCacheStoreImplTest.java index a0f02aa6f9..0e18b6b785 100644 --- a/bundle/src/test/java/com/adobe/acs/commons/httpcache/store/caffeine/impl/CaffeineMemHttpCacheStoreImplTest.java +++ b/bundle/src/test/java/com/adobe/acs/commons/httpcache/store/caffeine/impl/CaffeineMemHttpCacheStoreImplTest.java @@ -63,8 +63,8 @@ public void setUp() throws Exception { final Map config = new HashMap<>(); - config.put("httpcache.cachestore.caffeine.ttl", 60l); - config.put("httpcache.cachestore.caffeine.maxsize", 10l); + config.put("httpcache.cachestore.caffeine.ttl", 60L); + config.put("httpcache.cachestore.caffeine.maxsize", 10L); caffeine.activate(config); }