You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by gh...@apache.org on 2019/05/22 22:17:55 UTC
[sling-org-apache-sling-startupfilter] branch master updated:
SLING-8418 marked module as obsolete
This is an automated email from the ASF dual-hosted git repository.
ghenzler pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-startupfilter.git
The following commit(s) were added to refs/heads/master by this push:
new 1b33ce5 SLING-8418 marked module as obsolete
1b33ce5 is described below
commit 1b33ce56edc879de4d2bc87bd9bf174aa84a6836
Author: georg.henzler <ge...@netcentric.biz>
AuthorDate: Thu May 23 00:17:46 2019 +0200
SLING-8418 marked module as obsolete
---
CODE_OF_CONDUCT.md | 22 --
CONTRIBUTING.md | 24 --
Jenkinsfile | 20 --
README.md | 6 +-
pom.xml | 92 -------
.../apache/sling/startupfilter/StartupFilter.java | 48 ----
.../sling/startupfilter/StartupFilterDisabler.java | 27 --
.../sling/startupfilter/StartupInfoProvider.java | 29 ---
.../startupfilter/impl/StartupFilterImpl.java | 229 -----------------
.../apache/sling/startupfilter/package-info.java | 24 --
.../startupfilter/impl/StartupFilterImplTest.java | 286 ---------------------
11 files changed, 1 insertion(+), 806 deletions(-)
diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md
deleted file mode 100644
index 0fa18e5..0000000
--- a/CODE_OF_CONDUCT.md
+++ /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.
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/-->
-Apache Software Foundation Code of Conduct
-====
-
-Being an Apache project, Apache Sling adheres to the Apache Software Foundation's [Code of Conduct](https://www.apache.org/foundation/policies/conduct.html).
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
deleted file mode 100644
index ac82a1a..0000000
--- a/CONTRIBUTING.md
+++ /dev/null
@@ -1,24 +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.
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/-->
-Contributing
-====
-
-Thanks for choosing to contribute!
-
-You will find all the necessary details about how you can do this at https://sling.apache.org/contributing.html.
diff --git a/Jenkinsfile b/Jenkinsfile
deleted file mode 100644
index f582519..0000000
--- a/Jenkinsfile
+++ /dev/null
@@ -1,20 +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.
- */
-
-slingOsgiBundleBuild()
diff --git a/README.md b/README.md
index 27d22ad..57aa80a 100644
--- a/README.md
+++ b/README.md
@@ -1,9 +1,5 @@
[<img src="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-startupfilter/master)](https://builds.apache.org/job/Sling/job/sling-org-apache-sling-startupfilter/job/master) [![Test Status](https://img.shields.io/jenkins/t/https/builds.apache.org/job/Sling/job/sling-org-apache-sling-startupfilter/job/master.svg)](https://builds.apache.org/job/Sling/job/sling-org-apache-sling-startupfilter/job/master/test_results_analyzer/) [![License](https://img.shields.i [...]
-
# Apache Sling Startup Filter
-This module is part of the [Apache Sling](https://sling.apache.org) project.
-
-Servlet Filter that blocks access to Sling while starting up.
+This module is **obsolete** - use Felix HC [Service Unavailable Filter](https://github.com/apache/felix/blob/trunk/healthcheck/README.md#service-unavailable-filter) as e.g. configured in [Sling Starter](https://github.com/apache/sling-org-apache-sling-starter/blob/a16fb43f1d0333f74b066844e0377d93ca1e1e08/src/main/provisioning/healthcheck.txt#L86) instead.
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
deleted file mode 100644
index 2fa3f1c..0000000
--- a/pom.xml
+++ /dev/null
@@ -1,92 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
- <!--
- 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.
- -->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
-
- <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.apache.sling</groupId>
- <artifactId>sling</artifactId>
- <version>32</version>
- <relativePath/>
- </parent>
-
- <artifactId>org.apache.sling.startupfilter</artifactId>
- <version>0.0.1-SNAPSHOT</version>
- <packaging>bundle</packaging>
-
- <name>Apache Sling Startup Filter</name>
- <description>
- Servlet Filter that blocks access to Sling while starting up.
- </description>
-
- <scm>
- <connection>scm:git:https://gitbox.apache.org/repos/asf/sling-org-apache-sling-startupfilter.git</connection>
- <developerConnection>scm:git:https://gitbox.apache.org/repos/asf/sling-org-apache-sling-startupfilter.git</developerConnection>
- <url>https://gitbox.apache.org/repos/asf?p=sling-org-apache-sling-startupfilter.git</url>
- </scm>
-
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.felix</groupId>
- <artifactId>maven-bundle-plugin</artifactId>
- <extensions>true</extensions>
- <configuration>
- <instructions>
- <Require-Capability>
- osgi.implementation;filter:="(&(osgi.implementation=osgi.http)(version>=1.0)(!(version>=2.0)))"
- </Require-Capability>
- </instructions>
- </configuration>
- </plugin>
- </plugins>
- </build>
-
- <dependencies>
- <dependency>
- <groupId>org.osgi</groupId>
- <artifactId>osgi.core</artifactId>
- </dependency>
- <dependency>
- <groupId>org.osgi</groupId>
- <artifactId>org.osgi.service.http.whiteboard</artifactId>
- <version>1.0.0</version>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>javax.servlet</groupId>
- <artifactId>javax.servlet-api</artifactId>
- </dependency>
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-api</artifactId>
- </dependency>
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-simple</artifactId>
- </dependency>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- </dependency>
- <dependency>
- <groupId>org.jmock</groupId>
- <artifactId>jmock-junit4</artifactId>
- </dependency>
- </dependencies>
-</project>
diff --git a/src/main/java/org/apache/sling/startupfilter/StartupFilter.java b/src/main/java/org/apache/sling/startupfilter/StartupFilter.java
deleted file mode 100644
index 93c5e3d..0000000
--- a/src/main/java/org/apache/sling/startupfilter/StartupFilter.java
+++ /dev/null
@@ -1,48 +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.
- */
-package org.apache.sling.startupfilter;
-
-import org.osgi.annotation.versioning.ProviderType;
-
-/** Servlet Filter that blocks access to the Sling main
- * servlet during startup, by returning an HTTP 503
- * or other suitable status code.
- *
- * A typical use case is to start this filter before
- * the Sling main servlet (by setting a lower start level
- * on its bundle than on the Sling engine bundle), and
- * deactivating once startup is finished.
- */
-@ProviderType
-public interface StartupFilter {
-
- /** Enable the status filter, which outputs a default status message
- * and a concatenation of all status messages returned
- * by {@link StartupInfoProvider} services.
- *
- * The filter is initially enabled.
- */
- void enable();
-
- /** Disable the status filter */
- void disable();
-
- /** True if currently enabled */
- boolean isEnabled();
-}
\ No newline at end of file
diff --git a/src/main/java/org/apache/sling/startupfilter/StartupFilterDisabler.java b/src/main/java/org/apache/sling/startupfilter/StartupFilterDisabler.java
deleted file mode 100644
index f44c90a..0000000
--- a/src/main/java/org/apache/sling/startupfilter/StartupFilterDisabler.java
+++ /dev/null
@@ -1,27 +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.
- */
-package org.apache.sling.startupfilter;
-
-import org.osgi.annotation.versioning.ConsumerType;
-
-@ConsumerType
-public interface StartupFilterDisabler {
- /** Indicate why the StartupFilter should be disabled */
- String getReason();
-}
diff --git a/src/main/java/org/apache/sling/startupfilter/StartupInfoProvider.java b/src/main/java/org/apache/sling/startupfilter/StartupInfoProvider.java
deleted file mode 100644
index c1279e1..0000000
--- a/src/main/java/org/apache/sling/startupfilter/StartupInfoProvider.java
+++ /dev/null
@@ -1,29 +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.
- */
-package org.apache.sling.startupfilter;
-
-import org.osgi.annotation.versioning.ConsumerType;
-
-@ConsumerType
-public interface StartupInfoProvider {
- /** Return startup progress information, which the startup
- * filter adds to its HTTP 503 response.
- */
- String getProgressInfo();
-}
diff --git a/src/main/java/org/apache/sling/startupfilter/impl/StartupFilterImpl.java b/src/main/java/org/apache/sling/startupfilter/impl/StartupFilterImpl.java
deleted file mode 100644
index 1aa7f42..0000000
--- a/src/main/java/org/apache/sling/startupfilter/impl/StartupFilterImpl.java
+++ /dev/null
@@ -1,229 +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.
- */
-package org.apache.sling.startupfilter.impl;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Hashtable;
-import java.util.List;
-
-import javax.servlet.Filter;
-import javax.servlet.FilterChain;
-import javax.servlet.FilterConfig;
-import javax.servlet.ServletException;
-import javax.servlet.ServletRequest;
-import javax.servlet.ServletResponse;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-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.Constants;
-import org.osgi.framework.ServiceReference;
-import org.osgi.framework.ServiceRegistration;
-import org.osgi.service.component.annotations.Activate;
-import org.osgi.service.component.annotations.Component;
-import org.osgi.service.component.annotations.Deactivate;
-import org.osgi.service.component.annotations.Reference;
-import org.osgi.service.component.annotations.ReferenceCardinality;
-import org.osgi.service.component.annotations.ReferencePolicy;
-import org.osgi.service.http.whiteboard.HttpWhiteboardConstants;
-import org.osgi.service.metatype.annotations.AttributeDefinition;
-import org.osgi.service.metatype.annotations.Designate;
-import org.osgi.service.metatype.annotations.ObjectClassDefinition;
-import org.osgi.util.tracker.ServiceTracker;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/** StartupFilter implementation. Initially registered
- * as a StartupFilter only, the Filter registration
- * is dynamic, on-demand. */
-@Component(service = {StartupFilter.class}, immediate=true)
-@Designate(ocd = StartupFilterImpl.Config.class)
-public class StartupFilterImpl implements StartupFilter, Filter {
-
- @ObjectClassDefinition(name = "Apache Sling Startup Filter",
- description="Rejects Sling requests with a 503 error code during startup.")
- public static @interface Config {
-
- @AttributeDefinition(name = "Active by default?",
- description = "If true, the filter is active as soon as the service starts.")
- boolean active_by_default() default true;
-
- @AttributeDefinition(name = "Default message",
- description = "The default message is returned in the HHTTP response of the filter, " +
- "followed by any messages supplied by StartupInfoProvider services.")
- String default_message() default StartupFilterImpl.DEFAULT_MESSAGE;
- }
-
- private final Logger log = LoggerFactory.getLogger(getClass());
- private ServiceRegistration<Filter> filterServiceRegistration;
- private BundleContext bundleContext;
- private ServiceTracker<StartupInfoProvider, StartupInfoProvider> providersTracker;
- private int providersTrackerCount = -1;
-
- private final List<StartupInfoProvider> providers = new ArrayList<>();
-
- public static final String DEFAULT_MESSAGE = "Startup in progress";
-
- @Reference(policy=ReferencePolicy.DYNAMIC, cardinality=ReferenceCardinality.OPTIONAL)
- private volatile StartupFilterDisabler startupFilterDisabler;
-
- private static final String FRAMEWORK_PROP_MANAGER_ROOT = "felix.webconsole.manager.root";
- static final String DEFAULT_MANAGER_ROOT = "/system/console";
- private String managerRoot;
-
- private Config config;
-
- /** @inheritDoc */
- @Override
- 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;
- }
-
- // Bypass for the managerRoot path
- if(request instanceof HttpServletRequest) {
- final HttpServletRequest req = (HttpServletRequest)request;
- final String path = req.getServletPath() + (req.getPathInfo() == null ? "" : req.getPathInfo());
- if (managerRoot != null && managerRoot.length() > 0 && path.startsWith(managerRoot)) {
- log.debug("Bypassing filter for path {} which starts with {}", path, managerRoot);
- chain.doFilter(request, sr);
- return;
- }
- }
-
- updateProviders();
-
- final StringBuilder sb = new StringBuilder();
- sb.append(config.default_message());
- for(StartupInfoProvider p : providers) {
- sb.append('\n');
- sb.append(p.getProgressInfo());
- }
-
- // Do not use setError to avoid triggering the container's error page,
- // as that might cascade other errors during startup
- final HttpServletResponse response = (HttpServletResponse)sr;
- response.setStatus(HttpServletResponse.SC_SERVICE_UNAVAILABLE);
- response.setContentType("text/plain");
- response.setCharacterEncoding("UTF-8");
- response.getWriter().write(sb.toString());
- response.getWriter().flush();
- }
-
- @Override
- public String toString() {
- return getClass().getSimpleName() + ": " + (isEnabled() ? "enabled" : "disabled");
- }
-
- /** @inheritDoc */
- @Override
- public void destroy() {
- }
-
- /** @inheritDoc */
- @Override
- public void init(FilterConfig cfg) throws ServletException {
- }
-
- /** If needed, update our list of providers */
- private void updateProviders() {
- if(providersTracker.getTrackingCount() != providersTrackerCount) {
- synchronized(this) {
- if(providersTracker.getTrackingCount() != providersTrackerCount) {
- providers.clear();
- final ServiceReference<StartupInfoProvider> [] refs = providersTracker.getServiceReferences();
- if(refs != null) {
- for(ServiceReference<StartupInfoProvider> ref : refs) {
- providers.add(bundleContext.getService(ref));
- }
- }
- }
- providersTrackerCount = providersTracker.getTrackingCount();
- log.info("Reloaded list of StartupInfoProvider: {}", providers);
- }
- }
- }
-
- @Activate
- protected void activate(final BundleContext ctx,
- final Config config) throws InterruptedException {
- bundleContext = ctx;
-
- providersTracker = new ServiceTracker(bundleContext, StartupInfoProvider.class, null);
- providersTracker.open();
-
- this.config = config;
-
- final String prop = bundleContext.getProperty(FRAMEWORK_PROP_MANAGER_ROOT);
- managerRoot = prop == null ? DEFAULT_MANAGER_ROOT : prop.toString();
-
- if(config.active_by_default()) {
- enable();
- }
- log.info("Activated, enabled={}, managerRoot={}", isEnabled(), managerRoot);
- }
-
- @Deactivate
- protected void deactivate() throws InterruptedException {
- disable();
- providersTracker.close();
- providersTracker = null;
- bundleContext = null;
- }
-
-
- @Override
- public synchronized void enable() {
- if (filterServiceRegistration == null) {
- final String pattern = "/";
- final Hashtable<String, Object> params = new Hashtable<>();
- params.put(Constants.SERVICE_RANKING, 0x9000); // run before RequestLoggerFilter (0x8000)
- params.put("sling.filter.scope", "REQUEST");
- params.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_SELECT,
- "(" + HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_NAME + "=*)");
- params.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_FILTER_PATTERN, pattern);
- filterServiceRegistration = bundleContext.registerService(Filter.class, this, params);
- log.info("Registered {} as a servlet filter service with pattern {}", this, pattern);
- }
- }
-
- @Override
- public synchronized void disable() {
- if (filterServiceRegistration != null) {
- filterServiceRegistration.unregister();
- filterServiceRegistration = null;
- log.info("Filter service disabled");
- }
- }
-
- @Override
- public synchronized boolean isEnabled() {
- return filterServiceRegistration != null;
- }
-}
diff --git a/src/main/java/org/apache/sling/startupfilter/package-info.java b/src/main/java/org/apache/sling/startupfilter/package-info.java
deleted file mode 100644
index 2177642..0000000
--- a/src/main/java/org/apache/sling/startupfilter/package-info.java
+++ /dev/null
@@ -1,24 +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("1.0.0")
-package org.apache.sling.startupfilter;
-
-import org.osgi.annotation.versioning.Version;
-
diff --git a/src/test/java/org/apache/sling/startupfilter/impl/StartupFilterImplTest.java b/src/test/java/org/apache/sling/startupfilter/impl/StartupFilterImplTest.java
deleted file mode 100644
index 4b0db14..0000000
--- a/src/test/java/org/apache/sling/startupfilter/impl/StartupFilterImplTest.java
+++ /dev/null
@@ -1,286 +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.
- */
-package org.apache.sling.startupfilter.impl;
-
-import static org.junit.Assert.assertEquals;
-
-import java.io.PrintWriter;
-import java.io.StringWriter;
-import java.util.Dictionary;
-import java.util.concurrent.atomic.AtomicInteger;
-
-import javax.servlet.Filter;
-import javax.servlet.FilterChain;
-import javax.servlet.ServletRequest;
-import javax.servlet.ServletResponse;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.apache.sling.startupfilter.StartupInfoProvider;
-import org.apache.sling.startupfilter.impl.StartupFilterImpl.Config;
-import org.hamcrest.Description;
-import org.jmock.Expectations;
-import org.jmock.Mockery;
-import org.jmock.api.Action;
-import org.jmock.api.Invocation;
-import org.jmock.lib.action.DoAllAction;
-import org.junit.Before;
-import org.junit.Test;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceListener;
-import org.osgi.framework.ServiceReference;
-import org.osgi.framework.ServiceRegistration;
-
-/** Test the StartupFilterImpl */
-public class StartupFilterImplTest {
- static private class TestProvider implements StartupInfoProvider, ServiceReference {
- private final String info;
-
- TestProvider(String s) {
- info = s;
- }
-
- @Override
- public String getProgressInfo() {
- return info;
- }
-
- @Override
- public Object getProperty(String key) {
- return null;
- }
-
- @Override
- public String[] getPropertyKeys() {
- return null;
- }
-
- @Override
- public Bundle getBundle() {
- return null;
- }
-
- @Override
- public Bundle[] getUsingBundles() {
- return null;
- }
-
- @Override
- public boolean isAssignableTo(Bundle bundle, String className) {
- return false;
- }
-
- @Override
- public int compareTo(Object reference) {
- return 0;
- }
- }
- static private class TestFilterImpl extends StartupFilterImpl {
- void setup(BundleContext ctx, StartupFilterImpl.Config config) throws Exception {
- activate(ctx, config);
- }
- };
-
- static private class ChangeInteger implements Action {
- private final boolean increment;
- private final AtomicInteger value;
-
- ChangeInteger(AtomicInteger value, boolean increment) {
- this.increment = increment;
- this.value = value;
- }
- @Override
- public void describeTo(Description d) {
- d.appendText(increment ? "increment" : "decrement");
- d.appendText(" an integer");
- }
- @Override
- public Object invoke(Invocation invocation) throws Throwable {
- if(increment) {
- value.incrementAndGet();
- } else {
- value.decrementAndGet();
- }
- return null;
- }
- };
-
- private TestFilterImpl filter;
- private Mockery mockery;
- private HttpServletRequest request;
- private HttpServletResponse response;
- private FilterChain chain;
- private int lastReturnedStatus;
- private StringWriter messageWriter;
- private AtomicInteger activeFilterCount;
- private ServiceRegistration serviceRegistration;
- private String requestPath;
- private String pathInfo;
- private static final String CONSOLE_ROOT = "/test/system/console";
-
- @Before
- public void setup() {
- activeFilterCount = new AtomicInteger();
- mockery = new Mockery();
- request = mockery.mock(HttpServletRequest.class);
- response = mockery.mock(HttpServletResponse.class);
- chain = mockery.mock(FilterChain.class);
- serviceRegistration = mockery.mock(ServiceRegistration.class);
- filter = new TestFilterImpl();
- requestPath = "/NO_PATH_YET";
- }
-
- private void setProvider(final TestProvider provider) throws Exception {
- final BundleContext bundleContext = mockery.mock(BundleContext.class);
-
- final Action storeStatus = new Action() {
- @Override
- public void describeTo(Description d) {
- d.appendText("Store HTTP response values");
- }
-
- @Override
- public Object invoke(Invocation invocation) throws Throwable {
- lastReturnedStatus = (Integer)invocation.getParameter(0);
- return null;
- }
- };
-
- messageWriter = new StringWriter();
- final PrintWriter responseWriter = new PrintWriter(messageWriter);
-
- final Config cfg = mockery.mock(StartupFilterImpl.Config.class);
- final ServiceReference [] providerRefs = provider == null ? null : new ServiceReference[] { provider };
- mockery.checking(new Expectations() {{
- allowing(cfg).active_by_default();
- will(returnValue(true));
- allowing(cfg).default_message();
- will(returnValue(StartupFilterImpl.DEFAULT_MESSAGE));
- allowing(bundleContext).createFilter(with(any(String.class)));
- allowing(bundleContext).addServiceListener(with(any(ServiceListener.class)));
- allowing(bundleContext).addServiceListener(with(any(ServiceListener.class)), with(any(String.class)));
-
- allowing(bundleContext).getServiceReferences(StartupInfoProvider.class.getName(), null);
- will(returnValue(providerRefs));
- allowing(bundleContext).getService(with(any(ServiceReference.class)));
- will(returnValue(provider));
-
- allowing(bundleContext).getProperty(with("felix.webconsole.manager.root"));
- will(returnValue(CONSOLE_ROOT));
-
- allowing(bundleContext).registerService(with(equal(Filter.class)), with(any(Filter.class)), with(any(Dictionary.class)));
- will(new DoAllAction(
- new ChangeInteger(activeFilterCount, true),
- returnValue(serviceRegistration)
- ));
-
- allowing(response).setStatus((with(any(Integer.class))));
- will(storeStatus);
-
- allowing(response).setContentType("text/plain");
-
- allowing(response).getWriter();
- will(returnValue(responseWriter));
- allowing(response).setCharacterEncoding(with(any(String.class)));
-
- allowing(serviceRegistration).unregister();
- will(new ChangeInteger(activeFilterCount, false));
-
- allowing(request).getServletPath();
- will(returnValue(""));
-
- allowing(request).getPathInfo();
- will(returnValue(getPathInfo()));
-
- allowing(chain).doFilter(with(any(ServletRequest.class)), with(any(ServletResponse.class)));
- }});
-
- filter.setup(bundleContext, cfg);
- }
-
- private String getPathInfo() {
- return pathInfo;
- }
-
- private void assertRequest(final int expectedStatus, final String expectedMessage) throws Exception {
- lastReturnedStatus = -1;
-
- filter.doFilter(request, response, chain);
-
- final String responseText = messageWriter.toString();
-
- // status 0 means we expect the request to go through
- assertEquals("Expecting status to match",
- expectedStatus, lastReturnedStatus);
- assertEquals("Expecting message to match",
- expectedMessage, responseText);
- }
-
- @Test
- public void testInitialState() throws Exception {
- setProvider(null);
- assertEquals("Initially expecting the default status message", 1, activeFilterCount.get());
- assertRequest(503, StartupFilterImpl.DEFAULT_MESSAGE);
- }
-
- @Test
- public void testBypassRoot() throws Exception {
- requestPath = pathInfo = CONSOLE_ROOT;
- setProvider(null);
- assertRequest(-1, "");
- }
-
- @Test
- public void testNullPathInfo() throws Exception {
- requestPath = pathInfo = CONSOLE_ROOT;
- pathInfo = null;
- setProvider(null);
- assertRequest(503, "Startup in progress");
- }
-
- @Test
- public void testBypassSubpath() throws Exception {
- requestPath = pathInfo = CONSOLE_ROOT + "/something";
- setProvider(null);
- assertRequest(-1, "");
- }
-
- @Test
- public void testDisabling() throws Exception {
- setProvider(null);
- assertEquals("Initially expecting one filter service", 1, activeFilterCount.get());
- filter.disable();
- assertEquals("Expecting filter service to be gone", 0, activeFilterCount.get());
- }
-
- @Test
- public void testProviders() throws Exception {
- final TestProvider p = new TestProvider("TEST");
-
- setProvider(p);
- assertEquals("Initially expecting one filter service", 1, activeFilterCount.get());
-
- final String expectedMessage = StartupFilterImpl.DEFAULT_MESSAGE + "\nTEST";
- assertRequest(503, expectedMessage);
-
- filter.disable();
- assertEquals("Expecting filter service to be gone", 0, activeFilterCount.get());
- }
-}
\ No newline at end of file