Merge pull request #9 from paul-bjorkstrand/fix-docs-remove-multiviews
Fix documentation for httpd config
diff --git a/README.md b/README.md
index fd428e8..272f873 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,6 @@
-[<img src="https://sling.apache.org/res/logos/sling.png"/>](https://sling.apache.org)
+[![Apache Sling](https://sling.apache.org/res/logos/sling.png)](https://sling.apache.org)
- [![Build Status](https://builds.apache.org/buildStatus/icon?job=Sling/sling-org-apache-sling-dynamic-include/master)](https://builds.apache.org/job/Sling/job/sling-org-apache-sling-dynamic-include/job/master) [![Test Status](https://img.shields.io/jenkins/t/https/builds.apache.org/job/Sling/job/sling-org-apache-sling-dynamic-include/job/master.svg)](https://builds.apache.org/job/Sling/job/sling-org-apache-sling-dynamic-include/job/master/test_results_analyzer/) [![Maven Central](https://maven-badges.herokuapp.com/maven-central/org.apache.sling/org.apache.sling.dynamic-include/badge.svg)](https://search.maven.org/#search%7Cga%7C1%7Cg%3A%22org.apache.sling%22%20a%3A%22org.apache.sling.dynamic-include%22) [![JavaDocs](https://www.javadoc.io/badge/org.apache.sling/org.apache.sling.dynamic-include.svg)](https://www.javadoc.io/doc/org.apache.sling/org.apache.sling.dynamic-include) [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://www.apache.org/licenses/LICENSE-2.0)
+ [![Build Status](https://ci-builds.apache.org/job/Sling/job/modules/job/sling-org-apache-sling-dynamic-include/job/master/badge/icon)](https://ci-builds.apache.org/job/Sling/job/modules/job/sling-org-apache-sling-dynamic-include/job/master/) [![Test Status](https://img.shields.io/jenkins/tests.svg?jobUrl=https://ci-builds.apache.org/job/Sling/job/modules/job/sling-org-apache-sling-dynamic-include/job/master/)](https://ci-builds.apache.org/job/Sling/job/modules/job/sling-org-apache-sling-dynamic-include/job/master/test/?width=800&height=600) [![Coverage](https://sonarcloud.io/api/project_badges/measure?project=apache_sling-org-apache-sling-dynamic-include&metric=coverage)](https://sonarcloud.io/dashboard?id=apache_sling-org-apache-sling-dynamic-include) [![Sonarcloud Status](https://sonarcloud.io/api/project_badges/measure?project=apache_sling-org-apache-sling-dynamic-include&metric=alert_status)](https://sonarcloud.io/dashboard?id=apache_sling-org-apache-sling-dynamic-include) [![JavaDoc](https://www.javadoc.io/badge/org.apache.sling/org.apache.sling.dynamic-include.svg)](https://www.javadoc.io/doc/org.apache.sling/org-apache-sling-dynamic-include) [![Maven Central](https://maven-badges.herokuapp.com/maven-central/org.apache.sling/org.apache.sling.dynamic-include/badge.svg)](https://search.maven.org/#search%7Cga%7C1%7Cg%3A%22org.apache.sling%22%20a%3A%22org.apache.sling.dynamic-include%22) [![Contrib](https://sling.apache.org/badges/status-contrib.svg)](https://github.com/apache/sling-aggregator/blob/master/docs/status/contrib.md) [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://www.apache.org/licenses/LICENSE-2.0)
# Apache Sling Dynamic Include
@@ -41,6 +41,7 @@
* **Filter selector** - selector used to get actual content
* **Component TTL** - time to live in seconds, set for rendered component (require Dispatcher 4.1.11+)
* **Required header** - SDI will be enabled only if the configured header is present in the request. By default it's `Server-Agent=Communique-Dispatcher` header, added by the AEM dispatcher. You may enter just the header name only or the name and the value split with `=`.
+* **Disable Ignore URL params check** - SDI will process all requests and discard ignore URL params check including requests with GET params.
* **Ignore URL params** - SDI normally skips all requests containing any GET parameters. This option allows to set a list of parameters that should be ignored in the test. See the [Ignoring URL parameters](https://docs.adobe.com/docs/en/dispatcher/disp-config.html#Ignoring%20URL%20Parameters) section in the dispatcher documentation.
* **Include path rewriting** -- enable rewriting link (according to sling mappings) that is used for dynamic content including.
* **Append suffix** -- ensures that the suffix of the parent request is included with the dynamic include.
diff --git a/pom.xml b/pom.xml
index 44a0300..092484f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -23,14 +23,13 @@
<parent>
<groupId>org.apache.sling</groupId>
- <artifactId>sling</artifactId>
- <version>26</version>
+ <artifactId>sling-bundle-parent</artifactId>
+ <version>35</version>
<relativePath />
</parent>
<artifactId>org.apache.sling.dynamic-include</artifactId>
- <version>3.1.3-SNAPSHOT</version>
- <packaging>bundle</packaging>
+ <version>3.2.1-SNAPSHOT</version>
<name>Apache Sling Dynamic Include</name>
<description>Dynamic Include filter for Apache Sling</description>
@@ -55,50 +54,32 @@
</developer>
</developers>
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.felix</groupId>
- <artifactId>maven-scr-plugin</artifactId>
- <executions>
- <execution>
- <id>generate-scr-scrdescriptor</id>
- <goals>
- <goal>scr</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
- <plugin>
- <groupId>org.apache.felix</groupId>
- <artifactId>maven-bundle-plugin</artifactId>
- <extensions>true</extensions>
- </plugin>
- </plugins>
- </build>
-
<dependencies>
<!-- osgi -->
<dependency>
<groupId>org.osgi</groupId>
- <artifactId>org.osgi.core</artifactId>
+ <artifactId>osgi.core</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
- <artifactId>org.osgi.compendium</artifactId>
+ <artifactId>osgi.cmpn</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
- <groupId>org.apache.felix</groupId>
- <artifactId>org.apache.felix.scr.annotations</artifactId>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.service.component.annotations</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.servlets.annotations</artifactId>
<scope>provided</scope>
</dependency>
<!-- javax -->
<dependency>
<groupId>javax.servlet</groupId>
- <artifactId>servlet-api</artifactId>
+ <artifactId>javax.servlet-api</artifactId>
<scope>provided</scope>
</dependency>
@@ -126,22 +107,21 @@
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
- <version>1.7.0</version>
<scope>provided</scope>
</dependency>
<!-- commons -->
<dependency>
- <groupId>commons-lang</groupId>
- <artifactId>commons-lang</artifactId>
- <version>2.4</version>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-lang3</artifactId>
+ <version>3.0</version>
<scope>provided</scope>
</dependency>
+ <!-- testing -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
- <version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
@@ -150,6 +130,12 @@
<version>2.18.3</version>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.testing.osgi-mock.junit4</artifactId>
+ <version>2.4.10</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
</project>
diff --git a/src/main/java/org/apache/sling/dynamicinclude/CacheControlFilter.java b/src/main/java/org/apache/sling/dynamicinclude/CacheControlFilter.java
index 984d0c8..3591b3f 100644
--- a/src/main/java/org/apache/sling/dynamicinclude/CacheControlFilter.java
+++ b/src/main/java/org/apache/sling/dynamicinclude/CacheControlFilter.java
@@ -28,15 +28,21 @@
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
-import org.apache.felix.scr.annotations.Reference;
-import org.apache.felix.scr.annotations.sling.SlingFilter;
-import org.apache.felix.scr.annotations.sling.SlingFilterScope;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.SlingHttpServletResponse;
+import org.apache.sling.servlets.annotations.SlingServletFilter;
+import org.apache.sling.servlets.annotations.SlingServletFilterScope;
+import org.osgi.framework.Constants;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Reference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-@SlingFilter(scope = SlingFilterScope.REQUEST, order = 0)
+
+@SlingServletFilter(scope = { SlingServletFilterScope.REQUEST, SlingServletFilterScope.FORWARD } )
+@Component(property = {
+ Constants.SERVICE_RANKING + ":Integer=0"
+})
public class CacheControlFilter implements Filter {
private static final String HEADER_DATE = "Date";
diff --git a/src/main/java/org/apache/sling/dynamicinclude/Configuration.java b/src/main/java/org/apache/sling/dynamicinclude/Configuration.java
index 72579f6..0fa523a 100755
--- a/src/main/java/org/apache/sling/dynamicinclude/Configuration.java
+++ b/src/main/java/org/apache/sling/dynamicinclude/Configuration.java
@@ -20,101 +20,89 @@
package org.apache.sling.dynamicinclude;
import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashSet;
import java.util.List;
-import java.util.Map;
-import java.util.regex.Pattern;
-import org.apache.commons.lang.ArrayUtils;
-import org.apache.commons.lang.StringUtils;
-import org.apache.felix.scr.annotations.Activate;
-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.PropertyOption;
-import org.apache.felix.scr.annotations.Service;
+
+import org.apache.commons.lang3.ArrayUtils;
+import org.apache.commons.lang3.StringUtils;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.commons.osgi.PropertiesUtil;
import org.apache.sling.dynamicinclude.pathmatcher.PathMatcher;
import org.apache.sling.dynamicinclude.pathmatcher.PrefixPathMatcher;
import org.apache.sling.dynamicinclude.pathmatcher.RegexPathMatcher;
import org.osgi.framework.Constants;
-import org.osgi.service.component.ComponentContext;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.ConfigurationPolicy;
+import org.osgi.service.metatype.annotations.AttributeDefinition;
+import org.osgi.service.metatype.annotations.Designate;
+import org.osgi.service.metatype.annotations.ObjectClassDefinition;
+import org.osgi.service.metatype.annotations.Option;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Include filter configuration.
*/
-@Component(metatype = true, configurationFactory = true, label = "Apache Sling Dynamic Include - Configuration", immediate = true, policy = ConfigurationPolicy.REQUIRE)
-@Service(Configuration.class)
-@Properties({
- @Property(name = Constants.SERVICE_VENDOR, value = "The Apache Software Foundation"),
- @Property(name = Configuration.PROPERTY_FILTER_ENABLED, boolValue = Configuration.DEFAULT_FILTER_ENABLED, label = "Enabled", description = "Check to enable the filter"),
- @Property(name = Configuration.PROPERTY_FILTER_PATH, value = Configuration.DEFAULT_FILTER_PATH, label = "Base path regular expression", description = "This SDI configuration will work only for paths matching this value. If value starts with \"^\" sign, regex matching will be performed. Otherwise it will check for path prefix."),
- @Property(name = Configuration.PROPERTY_FILTER_RESOURCE_TYPES, cardinality = Integer.MAX_VALUE, label = "Resource types", description = "Filter will replace components with selected resource types"),
- @Property(name = Configuration.PROPERTY_INCLUDE_TYPE, value = Configuration.DEFAULT_INCLUDE_TYPE, label = "Include type", description = "Type of generated include tags", options = {
- @PropertyOption(name = "SSI", value = "Apache SSI"), @PropertyOption(name = "ESI", value = "ESI"),
- @PropertyOption(name = "JSI", value = "Javascript")}),
- @Property(name = Configuration.PROPERTY_ADD_COMMENT, boolValue = Configuration.DEFAULT_ADD_COMMENT, label = "Add comment", description = "Add comment to included components"),
- @Property(name = Configuration.PROPERTY_FILTER_SELECTOR, value = Configuration.DEFAULT_FILTER_SELECTOR, label = "Filter selector", description = "Selector used to mark included resources"),
- @Property(name = Configuration.PROPERTY_EXTENSION, value = Configuration.DEFAULT_EXTENSION, label = "Extension", description = "Extension to append to virtual resources to make caching possible"),
- @Property(name = Configuration.PROPERTY_COMPONENT_TTL, label = "Component TTL", description = "\"Time to live\" cache header for rendered component (in seconds)"),
- @Property(name = Configuration.PROPERTY_REQUIRED_HEADER, value = Configuration.DEFAULT_REQUIRED_HEADER, label = "Required header", description = "SDI will work only for requests with given header"),
- @Property(name = Configuration.PROPERTY_IGNORE_URL_PARAMS, cardinality = Integer.MAX_VALUE, label = "Ignore URL params", description = "SDI will process the request even if it contains configured GET parameters"),
- @Property(name = Configuration.PROPERTY_REWRITE_PATH, boolValue = Configuration.DEFAULT_REWRITE_DISABLED, label = "Include path rewriting", description = "Check to enable include path rewriting"),
- @Property(name = Configuration.PROPERTY_APPEND_SUFFIX, boolValue = Configuration.DEFAULT_APPEND_SUFFIX, label = "Append suffix to dynamic includes", description = "Check to append the suffix of the parent request to the dynamic include."),
- @Property(name= Configuration.NAME_HINT_PROPERTY_NAME, value=Configuration.NAME_HINT_VALUE)})
+@Component(service = Configuration.class,
+ immediate = true,
+ configurationPolicy = ConfigurationPolicy.REQUIRE,
+ property = {
+ Constants.SERVICE_VENDOR + "=The Apache Software Foundation",
+ "webconsole.configurationFactory.nameHint={include-filter.config.include-type} for [{include-filter.config.resource-types}] at path: {include-filter.config.path}"
+ })
+@Designate(ocd = Configuration.Config.class, factory = true)
public class Configuration {
+
+ @ObjectClassDefinition(name = "Apache Sling Dynamic Include - Configuration")
+ public @interface Config {
+ @AttributeDefinition(name="Enabled", description="Check to enable the filter")
+ boolean include$_$filter_config_enabled() default false;
+
+ @AttributeDefinition(name="Base path regular expression", description="This SDI configuration will work only for paths matching this value. If value starts with \\\"^\\\" sign, regex matching will be performed. Otherwise it will check for path prefix.")
+ String include$_$filter_config_path() default "/content";
+
+ @AttributeDefinition(name="Resource types", description="Filter will replace components with selected resource types", cardinality = Integer.MAX_VALUE)
+ String include$_$filter_config_resource$_$types() default "";
+
+ @AttributeDefinition(name = "Include type", description = "Type of generated include tags", options = {
+ @Option(label = "Apache SSI", value = "SSI"),
+ @Option(label = "ESI", value = "ESI"),
+ @Option(label = "Javascript", value = "JSI")
+ })
+ String include$_$filter_config_include$_$type() default "SSI";
+
+ @AttributeDefinition(name="Add comment", description = "Add comment to included components")
+ boolean include$_$filter_config_add__comment() default false;
+
+ @AttributeDefinition(name = "Filter selector", description = "Selector used to mark included resources")
+ String include$_$filter_config_selector() default "nocache";
+
+ @AttributeDefinition(name = "Extension", description = "Extension to append to virtual resources to make caching possible")
+ String include$_$filter_config_extension() default "";
+
+ @AttributeDefinition(name = "Component TTL", description = "\"Time to live\" cache header for rendered component (in seconds)")
+ String include$_$filter_config_ttl() default "";
+
+ @AttributeDefinition(name = "Required header", description = "SDI will work only for requests with given header")
+ String include$_$filter_config_required__header() default "Server-Agent=Communique-Dispatcher";
+
+ @AttributeDefinition(name = "Ignore URL params", description = "SDI will process the request even if it contains configured GET parameters", cardinality = Integer.MAX_VALUE)
+ String include$_$filter_config_ignoreUrlParams() default "";
+
+ @AttributeDefinition(name = "Include path rewriting", description = "Check to enable include path rewriting")
+ boolean include$_$filter_config_rewrite() default false;
+
+ @AttributeDefinition(name = "Append suffix to dynamic includes", description = "Check to append the suffix of the parent request to the dynamic include.")
+ boolean include$_$filter_config_appendSuffix() default true;
+
+ @AttributeDefinition(name = "Disable ignore URL params check", description = "Disable the check in the Ignore URL Params setting.")
+ boolean include$_$filter_config_disableIgnoreUrlParams() default false;
+ }
private static final Logger LOG = LoggerFactory.getLogger(Configuration.class);
- static final String PROPERTY_FILTER_PATH = "include-filter.config.path";
-
- static final String DEFAULT_FILTER_PATH = "/content";
-
- static final String PROPERTY_FILTER_ENABLED = "include-filter.config.enabled";
-
- static final boolean DEFAULT_FILTER_ENABLED = false;
-
- static final String PROPERTY_FILTER_RESOURCE_TYPES = "include-filter.config.resource-types";
-
- static final String PROPERTY_FILTER_SELECTOR = "include-filter.config.selector";
-
- static final String DEFAULT_FILTER_SELECTOR = "nocache";
-
- static final String PROPERTY_EXTENSION = "include-filter.config.extension";
-
- static final String DEFAULT_EXTENSION = "";
-
- static final String PROPERTY_COMPONENT_TTL = "include-filter.config.ttl";
-
- static final String PROPERTY_INCLUDE_TYPE = "include-filter.config.include-type";
-
- static final String DEFAULT_INCLUDE_TYPE = "SSI";
-
- static final String PROPERTY_ADD_COMMENT = "include-filter.config.add_comment";
-
- static final boolean DEFAULT_ADD_COMMENT = false;
-
- static final String PROPERTY_REQUIRED_HEADER = "include-filter.config.required_header";
-
- static final String DEFAULT_REQUIRED_HEADER = "Server-Agent=Communique-Dispatcher";
-
- static final String PROPERTY_IGNORE_URL_PARAMS = "include-filter.config.ignoreUrlParams";
-
- static final String PROPERTY_REWRITE_PATH = "include-filter.config.rewrite";
-
- static final String NAME_HINT_PROPERTY_NAME = "webconsole.configurationFactory.nameHint";
-
- static final String NAME_HINT_VALUE = "{" + PROPERTY_INCLUDE_TYPE + "} for [{"
- + PROPERTY_FILTER_RESOURCE_TYPES + "}] at path: {" + PROPERTY_FILTER_PATH + "}";
-
- static final boolean DEFAULT_REWRITE_DISABLED = false;
-
- static final String PROPERTY_APPEND_SUFFIX = "include-filter.config.appendSuffix";
-
- static final boolean DEFAULT_APPEND_SUFFIX = true;
-
private PathMatcher pathMatcher;
private boolean isEnabled;
@@ -133,19 +121,21 @@
private String requiredHeader;
- private List<String> ignoreUrlParams;
+ private boolean disableIgnoreUrlParams;
+
+ private Collection<String> ignoreUrlParams;
private boolean rewritePath;
private boolean appendSuffix;
@Activate
- public void activate(ComponentContext context, Map<String, ?> properties) {
- isEnabled = PropertiesUtil.toBoolean(properties.get(PROPERTY_FILTER_ENABLED), DEFAULT_FILTER_ENABLED);
- String pathPattern = PropertiesUtil.toString(properties.get(PROPERTY_FILTER_PATH), DEFAULT_FILTER_PATH);
+ public void activate(Config cfg) {
+ isEnabled = cfg.include$_$filter_config_enabled();
+ String pathPattern = cfg.include$_$filter_config_path();
pathMatcher = choosePathMatcher(pathPattern);
String[] resourceTypeList;
- resourceTypeList = PropertiesUtil.toStringArray(properties.get(PROPERTY_FILTER_RESOURCE_TYPES), new String[0]);
+ resourceTypeList = PropertiesUtil.toStringArray(cfg.include$_$filter_config_resource$_$types(), new String[0]);
for (int i = 0; i < resourceTypeList.length; i++) {
String[] s = resourceTypeList[i].split(";");
String name = s[0].trim();
@@ -153,16 +143,18 @@
}
this.resourceTypes = Arrays.asList(resourceTypeList);
- includeSelector = PropertiesUtil.toString(properties.get(PROPERTY_FILTER_SELECTOR), DEFAULT_FILTER_SELECTOR);
- extension = PropertiesUtil.toString(properties.get(PROPERTY_EXTENSION), DEFAULT_EXTENSION);
- ttl = PropertiesUtil.toInteger(properties.get(PROPERTY_COMPONENT_TTL), -1);
- addComment = PropertiesUtil.toBoolean(properties.get(PROPERTY_ADD_COMMENT), DEFAULT_ADD_COMMENT);
- includeTypeName = PropertiesUtil.toString(properties.get(PROPERTY_INCLUDE_TYPE), DEFAULT_INCLUDE_TYPE);
- requiredHeader = PropertiesUtil.toString(properties.get(PROPERTY_REQUIRED_HEADER), DEFAULT_REQUIRED_HEADER);
- ignoreUrlParams = Arrays.asList(PropertiesUtil.toStringArray(properties.get(PROPERTY_IGNORE_URL_PARAMS),
- new String[0]));
- rewritePath = PropertiesUtil.toBoolean(properties.get(PROPERTY_REWRITE_PATH), DEFAULT_REWRITE_DISABLED);
- appendSuffix = PropertiesUtil.toBoolean(properties.get(PROPERTY_APPEND_SUFFIX), DEFAULT_APPEND_SUFFIX);
+ includeSelector = cfg.include$_$filter_config_selector();
+ extension = cfg.include$_$filter_config_extension();
+ ttl = PropertiesUtil.toInteger(cfg.include$_$filter_config_ttl(), -1);
+ addComment = cfg.include$_$filter_config_add__comment();
+ includeTypeName = cfg.include$_$filter_config_include$_$type();
+ requiredHeader = cfg.include$_$filter_config_required__header();
+ ignoreUrlParams = new HashSet<>(
+ Arrays.asList(PropertiesUtil.toStringArray(cfg.include$_$filter_config_ignoreUrlParams(), new String[0]))
+ );
+ rewritePath = cfg.include$_$filter_config_rewrite();
+ appendSuffix = cfg.include$_$filter_config_appendSuffix();
+ disableIgnoreUrlParams = cfg.include$_$filter_config_disableIgnoreUrlParams();
}
private PathMatcher choosePathMatcher(String pathPattern) {
@@ -230,10 +222,14 @@
return requiredHeader;
}
- public List<String> getIgnoreUrlParams() {
+ public Collection<String> getIgnoreUrlParams() {
return ignoreUrlParams;
}
+ public boolean isDisableIgnoreUrlParams() {
+ return disableIgnoreUrlParams;
+ }
+
public boolean isRewritePath() {
return rewritePath;
}
diff --git a/src/main/java/org/apache/sling/dynamicinclude/ConfigurationWhiteboard.java b/src/main/java/org/apache/sling/dynamicinclude/ConfigurationWhiteboard.java
index 377fbe7..5755dcf 100644
--- a/src/main/java/org/apache/sling/dynamicinclude/ConfigurationWhiteboard.java
+++ b/src/main/java/org/apache/sling/dynamicinclude/ConfigurationWhiteboard.java
@@ -19,23 +19,23 @@
package org.apache.sling.dynamicinclude;
-import java.util.Set;
+import static org.osgi.service.component.annotations.FieldOption.UPDATE;
+import static org.osgi.service.component.annotations.ReferenceCardinality.MULTIPLE;
+import static org.osgi.service.component.annotations.ReferencePolicy.DYNAMIC;
+
+import java.util.Collection;
import java.util.concurrent.CopyOnWriteArraySet;
-import java.util.regex.Matcher;
-import org.apache.felix.scr.annotations.Component;
-import org.apache.felix.scr.annotations.Reference;
-import org.apache.felix.scr.annotations.ReferenceCardinality;
-import org.apache.felix.scr.annotations.ReferencePolicy;
-import org.apache.felix.scr.annotations.Service;
import org.apache.sling.api.SlingHttpServletRequest;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Reference;
-@Component
-@Service(ConfigurationWhiteboard.class)
+@Component(service = ConfigurationWhiteboard.class)
public class ConfigurationWhiteboard {
- @Reference(referenceInterface = Configuration.class, cardinality = ReferenceCardinality.OPTIONAL_MULTIPLE, policy = ReferencePolicy.DYNAMIC)
- private Set<Configuration> configs = new CopyOnWriteArraySet<Configuration>();
+ @Reference(service = Configuration.class, cardinality = MULTIPLE, policy = DYNAMIC, fieldOption = UPDATE)
+ // declared Collection due to SLING-8986
+ private volatile Collection<Configuration> configs = new CopyOnWriteArraySet<Configuration>();
public Configuration getConfiguration(SlingHttpServletRequest request, String resourceType) {
for (Configuration c : configs) {
@@ -50,12 +50,9 @@
final String requestPath = request.getRequestPathInfo().getResourcePath();
return config.isEnabled() && config.getPathMatcher().match(requestPath);
}
-
- protected void bindConfigs(final Configuration config) {
+
+ // visible for testing
+ void bindConfigs(final Configuration config) {
configs.add(config);
}
-
- protected void unbindConfigs(final Configuration config) {
- configs.remove(config);
- }
}
diff --git a/src/main/java/org/apache/sling/dynamicinclude/IncludeTagFilter.java b/src/main/java/org/apache/sling/dynamicinclude/IncludeTagFilter.java
index ccbf2bd..b43568a 100644
--- a/src/main/java/org/apache/sling/dynamicinclude/IncludeTagFilter.java
+++ b/src/main/java/org/apache/sling/dynamicinclude/IncludeTagFilter.java
@@ -23,6 +23,7 @@
import java.io.PrintWriter;
import java.net.URI;
import java.net.URISyntaxException;
+import java.util.Collection;
import java.util.Enumeration;
import java.util.List;
@@ -33,21 +34,24 @@
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
-import org.apache.commons.lang.StringEscapeUtils;
-import org.apache.commons.lang.StringUtils;
-import org.apache.felix.scr.annotations.Reference;
-import org.apache.felix.scr.annotations.sling.SlingFilter;
-import org.apache.felix.scr.annotations.sling.SlingFilterScope;
+import org.apache.commons.lang3.StringEscapeUtils;
+import org.apache.commons.lang3.StringUtils;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceUtil;
import org.apache.sling.dynamicinclude.generator.IncludeGenerator;
import org.apache.sling.dynamicinclude.generator.IncludeGeneratorWhiteboard;
import org.apache.sling.dynamicinclude.impl.UrlBuilder;
+import org.apache.sling.servlets.annotations.SlingServletFilter;
+import org.apache.sling.servlets.annotations.SlingServletFilterScope;
+import org.osgi.framework.Constants;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Reference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-@SlingFilter(scope = SlingFilterScope.INCLUDE, order = -500)
+@SlingServletFilter(scope = SlingServletFilterScope.INCLUDE)
+@Component(property = { Constants.SERVICE_RANKING + ":Integer=-500"} )
public class IncludeTagFilter implements Filter {
private static final Logger LOG = LoggerFactory.getLogger(IncludeTagFilter.class);
@@ -87,7 +91,7 @@
}
if (config.getAddComment()) {
- writer.append(String.format(COMMENT, StringEscapeUtils.escapeHtml(url), resourceType));
+ writer.append(String.format(COMMENT, StringEscapeUtils.escapeHtml4(url), resourceType));
}
// Only write the includes markup if the required, configurable request
@@ -102,14 +106,15 @@
}
private boolean shouldWriteIncludes(Configuration config, SlingHttpServletRequest request) {
- if (requestHasParameters(config.getIgnoreUrlParams(), request)) {
+ // Do not skip GET requests when DisableIgnoreUrlParams set to true.
+ if (!config.isDisableIgnoreUrlParams() && requestHasParameters(config.getIgnoreUrlParams(), request)) {
return false;
}
final String requiredHeader = config.getRequiredHeader();
return StringUtils.isBlank(requiredHeader) || containsHeader(requiredHeader, request);
}
- private boolean requestHasParameters(List<String> ignoreUrlParams, SlingHttpServletRequest request) {
+ private boolean requestHasParameters(Collection<String> ignoreUrlParams, SlingHttpServletRequest request) {
final Enumeration<?> paramNames = request.getParameterNames();
while (paramNames.hasMoreElements()) {
final String paramName = (String) paramNames.nextElement();
diff --git a/src/main/java/org/apache/sling/dynamicinclude/SyntheticResourceFilter.java b/src/main/java/org/apache/sling/dynamicinclude/SyntheticResourceFilter.java
index 0f2ac1b..5073fec 100644
--- a/src/main/java/org/apache/sling/dynamicinclude/SyntheticResourceFilter.java
+++ b/src/main/java/org/apache/sling/dynamicinclude/SyntheticResourceFilter.java
@@ -29,25 +29,22 @@
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
-import org.apache.commons.lang.StringUtils;
-import org.apache.felix.scr.annotations.Component;
-import org.apache.felix.scr.annotations.Properties;
-import org.apache.felix.scr.annotations.Property;
-import org.apache.felix.scr.annotations.Reference;
-import org.apache.felix.scr.annotations.Service;
+import org.apache.commons.lang3.StringUtils;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.request.RequestDispatcherOptions;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceUtil;
-import org.apache.sling.engine.EngineConstants;
+import org.apache.sling.servlets.annotations.SlingServletFilter;
+import org.apache.sling.servlets.annotations.SlingServletFilterScope;
import org.osgi.framework.Constants;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Reference;
-@Component(metatype = true, label = "Apache Sling Dynamic Include - Synthetic Resource Filter")
-@Service
-@Properties({
- @Property(name = Constants.SERVICE_VENDOR, value = "The Apache Software Foundation"),
- @Property(name = EngineConstants.SLING_FILTER_SCOPE, value = EngineConstants.FILTER_SCOPE_REQUEST, propertyPrivate = true),
- @Property(name = Constants.SERVICE_RANKING, intValue = Integer.MIN_VALUE, propertyPrivate = false), })
+@SlingServletFilter(scope = SlingServletFilterScope.REQUEST)
+@Component(property = {
+ Constants.SERVICE_RANKING + ":Integer=" + Integer.MIN_VALUE,
+ Constants.SERVICE_VENDOR +"=The Apache Software Foundation"
+})
public class SyntheticResourceFilter implements Filter {
@Reference
diff --git a/src/main/java/org/apache/sling/dynamicinclude/generator/IncludeGeneratorWhiteboard.java b/src/main/java/org/apache/sling/dynamicinclude/generator/IncludeGeneratorWhiteboard.java
index aaaaf1a..8294744 100755
--- a/src/main/java/org/apache/sling/dynamicinclude/generator/IncludeGeneratorWhiteboard.java
+++ b/src/main/java/org/apache/sling/dynamicinclude/generator/IncludeGeneratorWhiteboard.java
@@ -19,24 +19,24 @@
package org.apache.sling.dynamicinclude.generator;
+import static org.osgi.service.component.annotations.FieldOption.UPDATE;
+import static org.osgi.service.component.annotations.ReferenceCardinality.MULTIPLE;
+import static org.osgi.service.component.annotations.ReferencePolicy.DYNAMIC;
+
import java.util.Set;
import java.util.concurrent.CopyOnWriteArraySet;
-import org.apache.felix.scr.annotations.Component;
-import org.apache.felix.scr.annotations.Reference;
-import org.apache.felix.scr.annotations.ReferenceCardinality;
-import org.apache.felix.scr.annotations.ReferencePolicy;
-import org.apache.felix.scr.annotations.Service;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Reference;
/**
* Service that provides include generator of given type.
*/
-@Component
-@Service(IncludeGeneratorWhiteboard.class)
+@Component(service = IncludeGeneratorWhiteboard.class)
public class IncludeGeneratorWhiteboard {
- @Reference(referenceInterface = IncludeGenerator.class, cardinality = ReferenceCardinality.MANDATORY_MULTIPLE, policy = ReferencePolicy.DYNAMIC)
+ @Reference(service = IncludeGenerator.class, cardinality = MULTIPLE, policy = DYNAMIC, fieldOption = UPDATE)
private Set<IncludeGenerator> generators = new CopyOnWriteArraySet<IncludeGenerator>();
public IncludeGenerator getGenerator(String type) {
@@ -47,13 +47,4 @@
}
return null;
}
-
- void bindGenerators(IncludeGenerator generator) {
- generators.add(generator);
- }
-
- void unbindGenerators(IncludeGenerator generator) {
- generators.remove(generator);
- }
-
}
diff --git a/src/main/java/org/apache/sling/dynamicinclude/generator/package-info.java b/src/main/java/org/apache/sling/dynamicinclude/generator/package-info.java
deleted file mode 100644
index 91d2fc9..0000000
--- a/src/main/java/org/apache/sling/dynamicinclude/generator/package-info.java
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- */
-@Version("3.0.0")
-package org.apache.sling.dynamicinclude.generator;
-import aQute.bnd.annotation.Version;
-
diff --git a/src/main/java/org/apache/sling/dynamicinclude/generator/types/EsiGenerator.java b/src/main/java/org/apache/sling/dynamicinclude/generator/types/EsiGenerator.java
index 81f8b10..0d47fcd 100755
--- a/src/main/java/org/apache/sling/dynamicinclude/generator/types/EsiGenerator.java
+++ b/src/main/java/org/apache/sling/dynamicinclude/generator/types/EsiGenerator.java
@@ -19,16 +19,14 @@
package org.apache.sling.dynamicinclude.generator.types;
-import org.apache.commons.lang.StringEscapeUtils;
-import org.apache.felix.scr.annotations.Component;
-import org.apache.felix.scr.annotations.Service;
+import org.apache.commons.lang3.StringEscapeUtils;
import org.apache.sling.dynamicinclude.generator.IncludeGenerator;
+import org.osgi.service.component.annotations.Component;
/**
* ESI include generator
*/
@Component
-@Service
public class EsiGenerator implements IncludeGenerator {
private static final String GENERATOR_NAME = "ESI";
@@ -41,7 +39,7 @@
public String getInclude(String url) {
StringBuffer buf = new StringBuffer();
buf.append("<esi:include src=\"");
- buf.append(StringEscapeUtils.escapeHtml(url));
+ buf.append(StringEscapeUtils.escapeHtml4(url));
buf.append("\"/>");
return buf.toString();
}
diff --git a/src/main/java/org/apache/sling/dynamicinclude/generator/types/JsiGenerator.java b/src/main/java/org/apache/sling/dynamicinclude/generator/types/JsiGenerator.java
index 695ec30..a796022 100755
--- a/src/main/java/org/apache/sling/dynamicinclude/generator/types/JsiGenerator.java
+++ b/src/main/java/org/apache/sling/dynamicinclude/generator/types/JsiGenerator.java
@@ -26,12 +26,11 @@
import java.io.UnsupportedEncodingException;
import java.net.URL;
-import org.apache.commons.lang.StringEscapeUtils;
-import org.apache.felix.scr.annotations.Activate;
-import org.apache.felix.scr.annotations.Component;
-import org.apache.felix.scr.annotations.Service;
+import org.apache.commons.lang3.StringEscapeUtils;
import org.apache.sling.dynamicinclude.generator.IncludeGenerator;
import org.osgi.service.component.ComponentContext;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -39,7 +38,6 @@
* Client side include generator - using Ajax/JQuery.
*/
@Component
-@Service
public class JsiGenerator implements IncludeGenerator {
private static final String TEMPLATE_FILENAME = "generators/jquery.html";
@@ -81,7 +79,7 @@
divName = "dynamic_include_filter_div_" + divId++;
}
- return template.replace(UUID_FIELD, divName).replace(URL_FIELD, StringEscapeUtils.escapeJavaScript(url));
+ return template.replace(UUID_FIELD, divName).replace(URL_FIELD, StringEscapeUtils.escapeEcmaScript(url));
}
private void readTemplateFromUrl(URL url) {
diff --git a/src/main/java/org/apache/sling/dynamicinclude/generator/types/SsiGenerator.java b/src/main/java/org/apache/sling/dynamicinclude/generator/types/SsiGenerator.java
index efa5712..718d506 100755
--- a/src/main/java/org/apache/sling/dynamicinclude/generator/types/SsiGenerator.java
+++ b/src/main/java/org/apache/sling/dynamicinclude/generator/types/SsiGenerator.java
@@ -19,15 +19,13 @@
package org.apache.sling.dynamicinclude.generator.types;
-import org.apache.felix.scr.annotations.Component;
-import org.apache.felix.scr.annotations.Service;
import org.apache.sling.dynamicinclude.generator.IncludeGenerator;
+import org.osgi.service.component.annotations.Component;
/**
* Apache SSI include generator
*/
@Component
-@Service
public class SsiGenerator implements IncludeGenerator {
private static final String GENERATOR_NAME = "SSI";
diff --git a/src/main/java/org/apache/sling/dynamicinclude/generator/types/package-info.java b/src/main/java/org/apache/sling/dynamicinclude/generator/types/package-info.java
deleted file mode 100644
index 2ffbf94..0000000
--- a/src/main/java/org/apache/sling/dynamicinclude/generator/types/package-info.java
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- */
-@Version("3.0.0")
-package org.apache.sling.dynamicinclude.generator.types;
-import aQute.bnd.annotation.Version;
-
diff --git a/src/main/java/org/apache/sling/dynamicinclude/impl/UrlBuilder.java b/src/main/java/org/apache/sling/dynamicinclude/impl/UrlBuilder.java
index 1905866..cc262ab 100644
--- a/src/main/java/org/apache/sling/dynamicinclude/impl/UrlBuilder.java
+++ b/src/main/java/org/apache/sling/dynamicinclude/impl/UrlBuilder.java
@@ -21,7 +21,7 @@
import java.util.Arrays;
-import org.apache.commons.lang.StringUtils;
+import org.apache.commons.lang3.StringUtils;
import org.apache.sling.api.request.RequestPathInfo;
import org.apache.sling.dynamicinclude.Configuration;
@@ -55,6 +55,9 @@
}
private static boolean includeSelectorNotAlreadyPresent(String[] currentSelectors, String includeSelector) {
+ if (includeSelector.isEmpty()) {
+ return false;
+ }
return !Arrays.asList(currentSelectors).contains(includeSelector);
}
}
diff --git a/src/main/java/org/apache/sling/dynamicinclude/package-info.java b/src/main/java/org/apache/sling/dynamicinclude/package-info.java
deleted file mode 100644
index 78fc7ba..0000000
--- a/src/main/java/org/apache/sling/dynamicinclude/package-info.java
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- */
-@Version("4.1.0")
-package org.apache.sling.dynamicinclude;
-import aQute.bnd.annotation.Version;
-
diff --git a/src/main/java/org/apache/sling/dynamicinclude/pathmatcher/PrefixPathMatcher.java b/src/main/java/org/apache/sling/dynamicinclude/pathmatcher/PrefixPathMatcher.java
index cdd1077..551b4c1 100644
--- a/src/main/java/org/apache/sling/dynamicinclude/pathmatcher/PrefixPathMatcher.java
+++ b/src/main/java/org/apache/sling/dynamicinclude/pathmatcher/PrefixPathMatcher.java
@@ -18,7 +18,7 @@
*/
package org.apache.sling.dynamicinclude.pathmatcher;
-import org.apache.commons.lang.StringUtils;
+import org.apache.commons.lang3.StringUtils;
public class PrefixPathMatcher implements PathMatcher {
diff --git a/src/main/java/org/apache/sling/dynamicinclude/pathmatcher/RegexPathMatcher.java b/src/main/java/org/apache/sling/dynamicinclude/pathmatcher/RegexPathMatcher.java
index e52008b..97ee623 100644
--- a/src/main/java/org/apache/sling/dynamicinclude/pathmatcher/RegexPathMatcher.java
+++ b/src/main/java/org/apache/sling/dynamicinclude/pathmatcher/RegexPathMatcher.java
@@ -19,7 +19,7 @@
package org.apache.sling.dynamicinclude.pathmatcher;
import java.util.regex.Pattern;
-import org.apache.commons.lang.StringUtils;
+import org.apache.commons.lang3.StringUtils;
public class RegexPathMatcher implements PathMatcher {
diff --git a/src/main/java/org/apache/sling/dynamicinclude/pathmatcher/package-info.java b/src/main/java/org/apache/sling/dynamicinclude/pathmatcher/package-info.java
deleted file mode 100644
index 1eb7026..0000000
--- a/src/main/java/org/apache/sling/dynamicinclude/pathmatcher/package-info.java
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- */
-@Version("3.0.0")
-package org.apache.sling.dynamicinclude.pathmatcher;
-import aQute.bnd.annotation.Version;
-
diff --git a/src/test/java/org/apache/sling/dynamicinclude/ConfigurationTest.java b/src/test/java/org/apache/sling/dynamicinclude/ConfigurationTest.java
index d430458..85cdf8a 100644
--- a/src/test/java/org/apache/sling/dynamicinclude/ConfigurationTest.java
+++ b/src/test/java/org/apache/sling/dynamicinclude/ConfigurationTest.java
@@ -24,40 +24,42 @@
import java.util.HashMap;
import java.util.Map;
-import java.util.regex.PatternSyntaxException;
import org.apache.sling.dynamicinclude.pathmatcher.PrefixPathMatcher;
+import org.apache.sling.testing.mock.osgi.junit.OsgiContext;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
public class ConfigurationTest {
private Configuration tested;
+
+ @Rule
+ public final OsgiContext context = new OsgiContext();
@Before
public void setUp() {
tested = new Configuration();
}
- @Test(expected = PatternSyntaxException.class)
+ @Test(expected = RuntimeException.class)
public void shouldThrowExceptionWhenRegexisInvalid() throws Exception {
- Map<String, Object> properties = new HashMap<String, Object>();
- properties.put(Configuration.PROPERTY_FILTER_PATH, "^(");
-
- tested.activate(null, properties);
+
+ context.registerInjectActivateService(tested, "include-filter.config.path", "^(");
}
@Test
public void shouldSetDefaultValuesWhenPropertiesAreEmpty() throws Exception {
Map<String, Object> properties = new HashMap<String, Object>();
- tested.activate(null, properties);
+ context.registerInjectActivateService(tested, properties);
assertThat(tested.getPathMatcher().getClass().isAssignableFrom(PrefixPathMatcher.class), is(true));
assertThat(tested.getAddComment(), is(false));
assertThat(tested.getIgnoreUrlParams().size(), is(0));
- assertThat(tested.getIncludeSelector(), is(Configuration.DEFAULT_FILTER_SELECTOR));
- assertThat(tested.getIncludeTypeName(), is(Configuration.DEFAULT_INCLUDE_TYPE));
- assertThat(tested.getRequiredHeader(), is(Configuration.DEFAULT_REQUIRED_HEADER));
+ assertThat(tested.getIncludeSelector(), is("nocache"));
+ assertThat(tested.getIncludeTypeName(), is("SSI"));
+ assertThat(tested.getRequiredHeader(), is("Server-Agent=Communique-Dispatcher"));
assertThat(tested.getTtl(), is(-1));
assertThat(tested.isEnabled(), is(false));
assertThat(tested.hasTtlSet(), is(false));
@@ -67,18 +69,18 @@
@Test
public void shouldSetConfigurationValues() throws Exception {
Map<String, Object> properties = new HashMap<String, Object>();
- properties.put(Configuration.PROPERTY_FILTER_PATH, "/content/test/path");
- properties.put(Configuration.PROPERTY_INCLUDE_TYPE, "ESI");
- properties.put(Configuration.PROPERTY_ADD_COMMENT, true);
- properties.put(Configuration.PROPERTY_COMPONENT_TTL, 60);
- properties.put(Configuration.PROPERTY_FILTER_ENABLED, true);
- properties.put(Configuration.PROPERTY_FILTER_RESOURCE_TYPES, new String[]{"test/resource/type"});
- properties.put(Configuration.PROPERTY_REQUIRED_HEADER, "CustomHeader: value");
- properties.put(Configuration.PROPERTY_FILTER_SELECTOR, "cache");
- properties.put(Configuration.PROPERTY_REWRITE_PATH, true);
- properties.put(Configuration.PROPERTY_IGNORE_URL_PARAMS, new String[] {"query"});
+ properties.put("include-filter.config.path", "/content/test/path");
+ properties.put("include-filter.config.include-type", "ESI");
+ properties.put("include-filter.config.add_comment", true);
+ properties.put("include-filter.config.ttl", 60);
+ properties.put("include-filter.config.enabled", true);
+ properties.put("include-filter.config.resource-types", new String[]{"test/resource/type"});
+ properties.put("include-filter.config.required_header", "CustomHeader: value");
+ properties.put("include-filter.config.selector", "cache");
+ properties.put("include-filter.config.rewrite", true);
+ properties.put("include-filter.config.ignoreUrlParams", new String[] {"query"});
- tested.activate(null, properties);
+ context.registerInjectActivateService(tested, properties);
assertThat(tested.getPathMatcher().getClass().isAssignableFrom(PrefixPathMatcher.class), is(true));
assertThat(tested.getAddComment(), is(true));
diff --git a/src/test/java/org/apache/sling/dynamicinclude/ConfigurationWhiteboardTest.java b/src/test/java/org/apache/sling/dynamicinclude/ConfigurationWhiteboardTest.java
index c32e4d9..b53326b 100644
--- a/src/test/java/org/apache/sling/dynamicinclude/ConfigurationWhiteboardTest.java
+++ b/src/test/java/org/apache/sling/dynamicinclude/ConfigurationWhiteboardTest.java
@@ -18,9 +18,6 @@
*/
package org.apache.sling.dynamicinclude;
-import static org.apache.sling.dynamicinclude.Configuration.PROPERTY_FILTER_ENABLED;
-import static org.apache.sling.dynamicinclude.Configuration.PROPERTY_FILTER_PATH;
-import static org.apache.sling.dynamicinclude.Configuration.PROPERTY_FILTER_RESOURCE_TYPES;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.MatcherAssert.assertThat;
@@ -28,9 +25,12 @@
import java.util.HashMap;
import java.util.Map;
+
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.request.RequestPathInfo;
+import org.apache.sling.testing.mock.osgi.junit.OsgiContext;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
@@ -38,9 +38,12 @@
@RunWith(MockitoJUnitRunner.class)
public class ConfigurationWhiteboardTest {
-
+
private static final String TEST_RESOURCE_PATH = "/content/test/engl/home/pageresource";
public static final String TEST_RESOURCE_TYPE = "test/component/resourceType";
+
+ @Rule
+ public final OsgiContext context = new OsgiContext();
private ConfigurationWhiteboard tested;
@@ -60,11 +63,11 @@
private Configuration buildConfiguration(boolean enabled, String pathRegex, String[] resourceTypes) {
Configuration configuration = new Configuration();
Map<String, Object> properties = new HashMap<String, Object>();
- properties.put(PROPERTY_FILTER_ENABLED, enabled);
- properties.put(PROPERTY_FILTER_PATH, pathRegex);
- properties.put(PROPERTY_FILTER_RESOURCE_TYPES, resourceTypes);
- configuration.activate(null, properties);
- return configuration;
+ properties.put("include-filter.config.enabled", enabled);
+ properties.put("include-filter.config.path", pathRegex);
+ properties.put("include-filter.config.resource-types", resourceTypes);
+
+ return context.registerInjectActivateService(configuration, properties);
}
@Test
@@ -74,25 +77,25 @@
@Test
public void shouldNotReturnConfigurationIfResourceTypeDoesNotMatch() throws Exception {
- Configuration testConfiguration = buildConfiguration(true, "^/content.*$", new String[]{"invalid/resourceType"});
- tested.bindConfigs(testConfiguration);
+ buildConfiguration(true, "^/content.*$", new String[]{"invalid/resourceType"});
+ context.registerInjectActivateService(tested);
assertThat(tested.getConfiguration(request, TEST_RESOURCE_TYPE), is(nullValue()));
}
@Test
public void shouldNotReturnConfigurationIfConfigurationIsDisabled() throws Exception {
- Configuration testConfiguration = buildConfiguration(false, "^/content.*$", new String[]{TEST_RESOURCE_TYPE});
- tested.bindConfigs(testConfiguration);
+ buildConfiguration(false, "^/content.*$", new String[]{TEST_RESOURCE_TYPE});
+ context.registerInjectActivateService(tested);
assertThat(tested.getConfiguration(request, TEST_RESOURCE_TYPE), is(nullValue()));
}
@Test
public void shouldNotReturnConfigurationIfPathDoesNotMatchRegex() throws Exception {
- Configuration testConfiguration = buildConfiguration(true, "^/content/notMatched/.*$",
+ buildConfiguration(true, "^/content/notMatched/.*$",
new String[]{TEST_RESOURCE_TYPE});
- tested.bindConfigs(testConfiguration);
+ context.registerInjectActivateService(tested);
assertThat(tested.getConfiguration(request, TEST_RESOURCE_TYPE), is(nullValue()));
}
@@ -100,7 +103,7 @@
@Test
public void shouldReturnValidConfiguration() throws Exception {
Configuration testConfiguration = buildConfiguration(true, "^/content.*$", new String[]{TEST_RESOURCE_TYPE});
- tested.bindConfigs(testConfiguration);
+ context.registerInjectActivateService(tested);
assertThat(tested.getConfiguration(request, TEST_RESOURCE_TYPE), is(testConfiguration));
}
diff --git a/src/test/java/org/apache/sling/dynamicinclude/impl/UrlBuilderTest.java b/src/test/java/org/apache/sling/dynamicinclude/impl/UrlBuilderTest.java
index c84e7b1..8257547 100644
--- a/src/test/java/org/apache/sling/dynamicinclude/impl/UrlBuilderTest.java
+++ b/src/test/java/org/apache/sling/dynamicinclude/impl/UrlBuilderTest.java
@@ -19,7 +19,7 @@
package org.apache.sling.dynamicinclude.impl;
-import org.apache.commons.lang.StringUtils;
+import org.apache.commons.lang3.StringUtils;
import org.apache.sling.api.request.RequestPathInfo;
import org.apache.sling.dynamicinclude.Configuration;
import org.junit.Before;
@@ -53,6 +53,39 @@
}
@Test
+ public void shouldNotAppendTheIncludeSelectorToUrlWhenNotSetAndAppendRequestPathInfoSelectorWhenNotSet() {
+ givenAnHtmlRequestForResource("/resource/path");
+ withSelectorString(null);
+ boolean isSyntheticResource = false;
+
+ String actualResult = UrlBuilder.buildUrl("", "apps/example/resource/type", isSyntheticResource, config, requestPathInfo);
+
+ assertThat(actualResult, is("/resource/path.html"));
+ }
+
+ @Test
+ public void shouldNotAppendTheIncludeSelectorToUrlWhenNotSetAndAppendRequestPathInfoSelectorWhenSet() {
+ givenAnHtmlRequestForResource("/resource/path");
+ withSelectorString("foo.bar.baz");
+ boolean isSyntheticResource = false;
+
+ String actualResult = UrlBuilder.buildUrl("", "apps/example/resource/type", isSyntheticResource, config, requestPathInfo);
+
+ assertThat(actualResult, is("/resource/path.foo.bar.baz.html"));
+ }
+
+ @Test
+ public void shouldAppendTheIncludeSelectorToUrlWhenSetAndNotAppendRequestPathInfoSelectorWhenNotSet() {
+ givenAnHtmlRequestForResource("/resource/path");
+ withSelectorString(null);
+ boolean isSyntheticResource = false;
+
+ String actualResult = UrlBuilder.buildUrl("include", "apps/example/resource/type", isSyntheticResource, config, requestPathInfo);
+
+ assertThat(actualResult, is("/resource/path.include.html"));
+ }
+
+ @Test
public void shouldAppendTheIncludeSelectorToUrlThatAlreadyContainsOtherSelectors() {
givenAnHtmlRequestForResource("/resource/path");
withSelectorString("foo.bar.baz");
@@ -135,7 +168,7 @@
verify(requestPathInfo,times(0)).getSuffix();
assertThat(actualResult, is("/resource/path.foo.include.html"));
}
-
+
@Test
public void shouldAppendExtensionForSyntheticResources() {
givenAnHtmlRequestForResource("/resource/path");