SLING-2601 - more robust mechanism for disabling StartupFilter, based on the presence of a disabling service
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1387008 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/src/main/java/org/apache/sling/startupfilter/StartupFilterDisabler.java b/src/main/java/org/apache/sling/startupfilter/StartupFilterDisabler.java
new file mode 100644
index 0000000..6cfd0f7
--- /dev/null
+++ b/src/main/java/org/apache/sling/startupfilter/StartupFilterDisabler.java
@@ -0,0 +1,24 @@
+/*
+ * 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.
+ */
+package org.apache.sling.startupfilter;
+
+public interface StartupFilterDisabler {
+ /** Indicate why the StartupFilter should be disabled */
+ String getReason();
+}
diff --git a/src/main/java/org/apache/sling/startupfilter/impl/StartupFilterImpl.java b/src/main/java/org/apache/sling/startupfilter/impl/StartupFilterImpl.java
index a26395f..d1ed6dd 100644
--- a/src/main/java/org/apache/sling/startupfilter/impl/StartupFilterImpl.java
+++ b/src/main/java/org/apache/sling/startupfilter/impl/StartupFilterImpl.java
@@ -35,8 +35,12 @@
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Property;
+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.startupfilter.StartupFilter;
+import org.apache.sling.startupfilter.StartupFilterDisabler;
import org.apache.sling.startupfilter.StartupInfoProvider;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
@@ -71,8 +75,21 @@
public static final String DEFAULT_MESSAGE_PROP = "default.message";
private String defaultMessage;
+ @Reference(cardinality=ReferenceCardinality.OPTIONAL_UNARY, policy=ReferencePolicy.DYNAMIC)
+ private StartupFilterDisabler startupFilterDisabler;
+
/** @inheritDoc */
public void doFilter(ServletRequest request, ServletResponse sr, FilterChain chain) throws IOException, ServletException {
+
+ // Disable if a StartupFilterDisabler is present
+ if(startupFilterDisabler!= null) {
+ log.info("StartupFilterDisabler service present, disabling StartupFilter ({})",
+ startupFilterDisabler.getReason());
+ disable();
+ chain.doFilter(request, sr);
+ return;
+ }
+
updateProviders();
final StringBuilder sb = new StringBuilder();