This is an automated email from the ASF dual-hosted git repository.
radu pushed a commit to branch master
in repository
https://gitbox.apache.org/repos/asf/sling-org-apache-sling-starter-startup.git
The following commit(s) were added to refs/heads/master by this push:
new 60bc335 SLING-7258 -
org.apache.sling.starter.startup.impl.StartupFilter should return 503 when
Sling is starting
60bc335 is described below
commit 60bc335afd6f4f076c5b05f61dba7c8560e1ee67
Author: Radu Cotescu <[email protected]>
AuthorDate: Tue Nov 21 16:33:58 2017 +0100
SLING-7258 - org.apache.sling.starter.startup.impl.StartupFilter should
return 503 when Sling is starting
* StartupFilter sends now a 503
* added a similar page to the regular index.html file to be presented to
the user; the difference between them is that there are no links
pointing to the instance, but only to external resources
---
pom.xml | 6 +
.../sling/starter/startup/impl/Activator.java | 4 +-
.../starter/startup/impl/HttpStartupSetup.java | 6 +-
.../sling/starter/startup/impl/StartupFilter.java | 43 ++--
src/main/resources/index.html | 277 +++++++++++++++++++++
5 files changed, 310 insertions(+), 26 deletions(-)
diff --git a/pom.xml b/pom.xml
index f7d2993..abae456 100644
--- a/pom.xml
+++ b/pom.xml
@@ -80,6 +80,12 @@
<version>1.0.0</version>
</dependency>
<dependency>
+ <groupId>commons-io</groupId>
+ <artifactId>commons-io</artifactId>
+ <version>2.5</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.installer.api</artifactId>
<version>1.0.0</version>
diff --git a/src/main/java/org/apache/sling/starter/startup/impl/Activator.java
b/src/main/java/org/apache/sling/starter/startup/impl/Activator.java
index a1e6631..eb968da 100644
--- a/src/main/java/org/apache/sling/starter/startup/impl/Activator.java
+++ b/src/main/java/org/apache/sling/starter/startup/impl/Activator.java
@@ -44,7 +44,7 @@ public class Activator implements BundleActivator {
private final AtomicBoolean stopped = new AtomicBoolean(false);
@Override
- public void start(final BundleContext context) throws Exception {
+ public void start(final BundleContext context) {
this.httpSetup = new HttpStartupSetup(context);
this.httpSetup.start();
@@ -52,7 +52,7 @@ public class Activator implements BundleActivator {
}
@Override
- public void stop(final BundleContext context) throws Exception {
+ public void stop(final BundleContext context) {
stopped.set(true);
this.stopInfoProviderTracker();
diff --git
a/src/main/java/org/apache/sling/starter/startup/impl/HttpStartupSetup.java
b/src/main/java/org/apache/sling/starter/startup/impl/HttpStartupSetup.java
index efa3b65..82083da 100644
--- a/src/main/java/org/apache/sling/starter/startup/impl/HttpStartupSetup.java
+++ b/src/main/java/org/apache/sling/starter/startup/impl/HttpStartupSetup.java
@@ -41,7 +41,7 @@ public class HttpStartupSetup {
private final BundleContext context;
- public HttpStartupSetup(final BundleContext context) {
+ HttpStartupSetup(final BundleContext context) {
this.context = context;
}
@@ -56,8 +56,7 @@ public class HttpStartupSetup {
}
/**
- * Register the http context
- * @param context The bundle context
+ * Register the http context.
*/
private void registerHttpContext() {
final Dictionary<String, Object> properties = new Hashtable<>();
@@ -97,7 +96,6 @@ public class HttpStartupSetup {
/**
* Register the startup filter
- * @param context The bundle context
*/
private void registerStartupFilter() {
final Dictionary<String, Object> properties = new Hashtable<>();
diff --git
a/src/main/java/org/apache/sling/starter/startup/impl/StartupFilter.java
b/src/main/java/org/apache/sling/starter/startup/impl/StartupFilter.java
index d638753..9b361f8 100644
--- a/src/main/java/org/apache/sling/starter/startup/impl/StartupFilter.java
+++ b/src/main/java/org/apache/sling/starter/startup/impl/StartupFilter.java
@@ -17,42 +17,45 @@
package org.apache.sling.starter.startup.impl;
import java.io.IOException;
+import java.io.InputStream;
import java.io.PrintWriter;
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.HttpServletResponse;
+import org.apache.commons.io.IOUtils;
+
public class StartupFilter implements Filter {
+ private String content;
+
@Override
- public void init(final FilterConfig filterConfig) throws ServletException {
+ public void init(final FilterConfig filterConfig) {
// nothing to do
}
@Override
- public void doFilter(final ServletRequest request,
- final ServletResponse response,
- final FilterChain chain)
- throws IOException, ServletException {
- response.setContentType("text/html");
- response.setCharacterEncoding("utf-8");
- ((HttpServletResponse)response).setHeader("Cache-Control", "no-store");
- final PrintWriter pw = response.getWriter();
-
- pw.println("<html><head>");
- pw.println("<META HTTP-EQUIV=\"refresh\" CONTENT=\"5\">");
- pw.println("<title>Apache Sling...</title></head>");
- pw.println("<body>");
- pw.println("<h1>Apache Sling is starting up....</h1>");
- pw.println("</body>");
- pw.println("</html>");
-
- pw.flush();
+ public void doFilter(final ServletRequest request, final ServletResponse
response, final FilterChain chain) throws IOException {
+ InputStream is;
+ if (content == null) {
+ is =
StartupFilter.class.getClassLoader().getResourceAsStream("index.html");
+ content = IOUtils.toString(is, "UTF-8");
+ IOUtils.closeQuietly(is);
+ }
+ HttpServletResponse httpResponse = (HttpServletResponse) response;
+ httpResponse.setContentType("text/html");
+ httpResponse.setCharacterEncoding("utf-8");
+ httpResponse.setHeader("Cache-Control", "no-store");
+ httpResponse.setStatus(HttpServletResponse.SC_SERVICE_UNAVAILABLE);
+ if (!"".equals(content) && content != null) {
+ final PrintWriter pw = response.getWriter();
+ pw.append(content);
+ pw.flush();
+ }
}
@Override
diff --git a/src/main/resources/index.html b/src/main/resources/index.html
new file mode 100644
index 0000000..0985faf
--- /dev/null
+++ b/src/main/resources/index.html
@@ -0,0 +1,277 @@
+<!--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ~ 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.
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
+<html>
+<head>
+ <meta charset="utf-8">
+ <meta http-equiv="X-UA-Compatible" content="IE=edge">
+ <meta name="viewport" content="width=device-width, initial-scale=1">
+ <title>If you start me up</title>
+ <style rel="stylesheet">
+ body, h1 {
+ font-weight: 300
+ }
+
+ .Home-Grid ul, h2, p {
+ line-height: 1.8em
+ }
+
+ .Grid {
+ display: flex;
+ flex-wrap: wrap;
+ justify-content: center
+ }
+
+ body, h2 {
+ margin: 0
+ }
+
+ .Grid.Gutter > .Cell {
+ padding: 0 1rem
+ }
+
+ .Grid.Align-Center {
+ align-items: center
+ }
+
+ .Grid .Cell {
+ -webkit-box-flex: 0;
+ -webkit-flex: 0 0 100%;
+ -ms-flex: 0 0 100%;
+ flex: 0 0 100%
+ }
+
+ .Grid .Cell.Align-Center {
+ align-self: center
+ }
+
+ .Grid.Fit-Mobile > .Cell {
+ -webkit-box-flex: 1;
+ -webkit-flex: 1;
+ -ms-flex: 1;
+ flex: 1
+ }
+
+ @media (min-width: 34em) {
+ .Grid.Fit-Small > .Cell {
+ -webkit-box-flex: 1;
+ -webkit-flex: 1;
+ -ms-flex: 1;
+ flex: 1
+ }
+
+ }
+
+ @media (min-width: 48em) {
+ .Grid.Fit-Medium > .Cell {
+ -webkit-box-flex: 1;
+ -webkit-flex: 1;
+ -ms-flex: 1;
+ flex: 1
+ }
+
+ }
+
+ @media (min-width: 62em) {
+ .Grid .Cell.Large-15 {
+ flex: 0 0 15%
+ }
+
+ .Grid .Cell.Large-25 {
+ flex: 0 0 25%
+ }
+
+ .Grid .Cell.Large-35 {
+ flex: 0 0 35%
+ }
+
+ .Grid .Cell.Large-50 {
+ flex: 0 0 50%
+ }
+
+ .Grid.Fit-Large > .Cell {
+ -webkit-box-flex: 1;
+ -webkit-flex: 1;
+ -ms-flex: 1;
+ flex: 1
+ }
+ }
+
+ @media (min-width: 75em) {
+
+ .Grid.Fit-Extra > .Cell {
+ -webkit-box-flex: 1;
+ -webkit-flex: 1;
+ -ms-flex: 1;
+ flex: 1
+ }
+ }
+
+ * {
+ box-sizing: border-box
+ }
+
+ body {
+ font-family: 'Open Sans', Helvetica, Arial;
+ color: gray;
+ position: relative
+ }
+
+ h1 {
+ font-size: 2.4em;
+ color: #606060
+ }
+
+ h2 {
+ font-weight: 400;
+ font-size: 1em
+ }
+
+ a {
+ color: #00678c;
+ text-decoration: none
+ }
+
+ a:hover {
+ text-decoration: underline
+ }
+
+ a img {
+ border: none
+ }
+
+ .Home-Grid {
+ min-height: 100%
+ }
+
+ .Home-Grid .Gradient {
+ flex: 0 0 100%;
+ height: 16px;
+ background:
url(data:image/jpeg;base64,/9j/4QPFRXhpZgAATU0AKgAAAAgABwESAAMAAAABAAEAAAEaAAUAAAABAAAAYgEbAAUAAAABAAAAagEoAAMAAAABAAIAAAExAAIAAAAkAAAAcgEyAAIAAAAUAAAAlodpAAQAAAABAAAArAAAANgACvyAAAAnEAAK/IAAACcQQWRvYmUgUGhvdG9zaG9wIENDIDIwMTcgKE1hY2ludG9zaCkAMjAxNzowNTowMyAxMDozMToyMAAAAAADoAEAAwAAAAEAAQAAoAIABAAAAAEAAAAyoAMABAAAAAEAAAQ4AAAAAAAAAAYBAwADAAAAAQAGAAABGgAFAAAAAQAAASYBGwAFAAAAAQAAAS4BKAADAAAAAQACAAACAQAEAAAAAQAAATYCAgAEAAAAAQAAAocAAAAAAAAASAAAAAEAAABIAAAAAf/Y/+0ADEFkb
[...]
+ background-size: cover;
+ }
+
+ .Home-Grid .Logos {
+ padding: 10% 20% 2%
+ }
+
+ .Home-Grid #sling-logo {
+ display: block;
+ margin-bottom: 32px;
+ margin-right: -8%
+ }
+
+ @media (min-width: 48em) {
+ .Home-Grid .Gradient {
+ flex: 0 0 16px;
+ height: auto
+ }
+
+ .Home-Grid .Logos {
+ padding: 6%
+ }
+
+ .Home-Grid #sling-logo {
+ margin-bottom: 180px
+ }
+ }
+
+ .Home-Grid #asf-logo {
+ display: block
+ }
+
+ .Home-Grid .Main-Content {
+ padding: 0 16px
+ }
+
+ @media (min-width: 48em) {
+ .Home-Grid .Main-Content {
+ padding: 0 16px 0 0
+ }
+ }
+
+ @media (min-width: 62em) {
+ .Home-Grid .Main-Content {
+ padding: 0
+ }
+ }
+
+ .Home-Grid ul {
+ margin: 0 0 1em;
+ padding: 0;
+ list-style: none
+ }
+ </style>
+ <meta http-equiv="refresh" content="5">
+</head>
+<body>
+<div class="Grid Fit-Medium Home-Grid">
+ <div class="Gradient"></div>
+ <header class="Cell Medium-35 Large-25 Align-Center Logos">
+ <a href="https://sling.apache.org" target="_blank" id="sling-logo"
title="Visit the Apache Sling website">
+ <img
src="data:image/svg+xml;base64,PCEtLQogIExpY2Vuc2VkIHRvIHRoZSBBcGFjaGUgU29mdHdhcmUgRm91bmRhdGlvbiAoQVNGKSB1bmRlciBvbmUKICBvciBtb3JlIGNvbnRyaWJ1dG9yIGxpY2Vuc2UgYWdyZWVtZW50cy4gIFNlZSB0aGUgTk9USUNFIGZpbGUKICBkaXN0cmlidXRlZCB3aXRoIHRoaXMgd29yayBmb3IgYWRkaXRpb25hbCBpbmZvcm1hdGlvbgogIHJlZ2FyZGluZyBjb3B5cmlnaHQgb3duZXJzaGlwLiAgVGhlIEFTRiBsaWNlbnNlcyB0aGlzIGZpbGUKICB0byB5b3UgdW5kZXIgdGhlIEFwYWNoZSBMaWNlbnNlLCBWZXJzaW9uIDIuMCAodGhlCiAgIkxpY2Vuc2UiKTsgeW91IG1heSBub3QgdXNlIHRoaXMg
[...]
+ alt="Apache Sling Logo">
+ </a>
+ <a href="https://apache.org" target="_blank" id="asf-logo"
title="Visit the Apache Software Foundation website">
+ <img
src="data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4KPCEtLQogICAgTGljZW5zZWQgdG8gdGhlIEFwYWNoZSBTb2Z0d2FyZSBGb3VuZGF0aW9uIChBU0YpIHVuZGVyIG9uZQogICAgb3IgbW9yZSBjb250cmlidXRvciBsaWNlbnNlIGFncmVlbWVudHMuICBTZWUgdGhlIE5PVElDRSBmaWxlCiAgICBkaXN0cmlidXRlZCB3aXRoIHRoaXMgd29yayBmb3IgYWRkaXRpb25hbCBpbmZvcm1hdGlvbgogICAgcmVnYXJkaW5nIGNvcHlyaWdodCBvd25lcnNoaXAuICBUaGUgQVNGIGxpY2Vuc2VzIHRoaXMgZmlsZQogICAgdG8geW91IHVuZGVyIHRoZSBBcGFjaGUgTGljZW5zZSwgVmVy
[...]
+ alt="Apache Software Foundation Logo">
+ </a>
+ </header>
+ <div class="Cell Align-Center Main-Content">
+ <div class="Grid">
+ <section class="Cell Large-50">
+ <h1>Almost there, the instance is starting up</h1>
+ <p>Apache Sling is a web framework that uses a Java Content
Repository, such as <a
+ href="https://jackrabbit.apache.org/jcr/index.html"
target="_blank" title="Visit the Apache Jackrabbit website">Apache
+ Jackrabbit</a>,
+ to store and manage content. Sling applications use either
scripts or Java servlets, selected
+ based on simple name conventions, to process HTTP requests
in a RESTful way. The embedded
+ <a href="https://felix.apache.org/" target="_blank"
title="Visit the Apache Felix website">Apache Felix</a> OSGi
+ framework and console provide a dynamic runtime
environment, where code and
+ content bundles can be loaded, unloaded and reconfigured
at runtime.</p>
+ <p>The Sling Launchpad is a ready-to-run Sling configuration,
providing an embedded JCR content
+ repository and web server, a selection of Sling
components, documentation and examples.
+ The Launchpad makes it easy to get started with Sling and
to develop script-based applications.</p>
+ <h1>Getting Started</h1>
+ <p>To get started with Sling, see our <a
href="https://sling.apache.org/" target="_blank"
+ title="Visit the
Apache Sling website">website</a>
+ or the <a
href="https://sling.apache.org/site/discover-sling-in-15-minutes.html"
target="_blank">Sling in 15 minutes</a>
+ tutorial.</p>
+ <p>You can mount the repository via WebDAV to explore or
modify content, simply use the root URL
+ as the WebDAV server URL.</p>
+ </section>
+ <div class="Cell Large-15"><!--/* Give the columns a bit of space
between them. */--></div>
+ <section class="Cell Large-35">
+ <h1>Resources</h1>
+ <h2>Reference</h2>
+ <ul>
+ <li><a
href="https://sling.apache.org/apidocs/sling9/index.html" target="_blank"
title="Vist the Apache Sling Javadocs">API
+ Documentation</a></li>
+ <li><a
href="https://sling.apache.org/project-information.html#mailing-lists"
target="_blank"
+ title="View available Apache Sling mailing
lists">Mailing Lists</a></li>
+ <li><a
href="https://sling.apache.org/documentation/tutorials-how-tos.html"
target="_blank"
+ title="View Apache Sling Developer
Tutorials">Tutorials</a></li>
+ <li><a
href="https://github.com/apache?utf8=%E2%9C%93&q=sling-&type=source"
target="_blank"
+ title="View the Apache Sling source code on
Github">Source Code</a></li>
+ <li><a href="https://github.com/apache/sling-samples"
target="_blank"
+ title="View Apache Sling sample applications on
Github">Sample Applications</a></li>
+ </ul>
+ </section>
+ </div>
+ </div>
+</div>
+</body>
+</html>
--
To stop receiving notification emails like this one, please contact
['"[email protected]" <[email protected]>'].