Commit 07b5ea58 authored by Bert Leunis's avatar Bert Leunis

ESSENTIALS-1046 Reintegrate feature/ESSENTIALS-1046

parents 4681c95a 6bfd9352
/*
* Copyright 2017 Hippo B.V. (http://www.onehippo.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onehippo.cms7.essentials.filters;
import org.onehippo.cms7.essentials.dashboard.utils.ProjectUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.servlet.*;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
/**
* Check if essentials can run properly,
* e.g if all required settings like project.basedir are set properly.
*/
public class RequirementsCheckFilter implements Filter {
private static final Logger log = LoggerFactory.getLogger(RequirementsCheckFilter.class);
@Override
public void init(final FilterConfig filterConfig) throws ServletException {
}
@Override
public void doFilter(final ServletRequest req, final ServletResponse res, final FilterChain chain) throws IOException, ServletException {
try {
/*
* IllegalStateException exception will be thrown
* if there is no project directory set
*/
final String directory = ProjectUtils.getBaseProjectDirectory();
final File file = new File(directory);
if (!file.exists()) {
sendRedirect(req, res, "Directory: " + directory + " does not exist or is not accessible by java process");
return;
}
if (!file.isDirectory()) {
sendRedirect(req, res, "File: " + directory + " must be a directory");
return;
}
} catch (IllegalStateException e) {
if (log.isDebugEnabled()) {
log.error("Error processing request:", e);
}
sendRedirect(req, res, e.getMessage());
return;
}
chain.doFilter(req, res);
}
private void sendRedirect(final ServletRequest req, final ServletResponse resp, final String error) throws IOException {
final HttpServletResponse response = (HttpServletResponse) resp;
log.error(error);
req.setAttribute("error", error);
response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE, error);
}
@Override
public void destroy() {
}
}
<%@ page language="java" contentType="text/html; charset=UTF-8" session="false" pageEncoding="UTF-8" %>
<%--
Copyright 2016 Hippo B.V. (http://www.onehippo.com)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
--%>
<!doctype html>
<html>
<head>
</head>
<body>
<h1>Service unavailable:</h1>
<p style="color:#ef7357; font-size: 16px;">${error}</p>
</body>
</html>
<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
Copyright 2014 Hippo B.V. (http://www.onehippo.com)
Copyright 2016 Hippo B.V. (http://www.onehippo.com)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
......@@ -20,6 +20,14 @@
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="essentials-webapp" metadata-complete="true" version="3.0">
<display-name>essentials-webapp</display-name>
<filter>
<filter-name>RequirementsCheckFilter</filter-name>
<filter-class>org.onehippo.cms7.essentials.filters.RequirementsCheckFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>RequirementsCheckFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter>
<filter-name>NoCacheFilter</filter-name>
<filter-class>org.onehippo.cms7.essentials.filters.NoCacheFilter</filter-class>
......@@ -56,7 +64,10 @@
<error-code>500</error-code>
<location>/WEB-INF/jsp/errors/500.jsp</location>
</error-page>
<error-page>
<error-code>503</error-code>
<location>/WEB-INF/jsp/errors/503.jsp</location>
</error-page>
<welcome-file-list>
<welcome-file>/WEB-INF/jsp/index.jsp</welcome-file>
</welcome-file-list>
......
/*
* Copyright 2014-2016 Hippo B.V. (http://www.onehippo.com)
* Copyright 2014-2017 Hippo B.V. (http://www.onehippo.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -116,7 +116,7 @@ public final class ProjectUtils {
if (System.getProperty(EssentialConst.PROJECT_BASEDIR_PROPERTY) != null && !System.getProperty(EssentialConst.PROJECT_BASEDIR_PROPERTY).isEmpty()) {
return System.getProperty(EssentialConst.PROJECT_BASEDIR_PROPERTY);
}
throw new IllegalStateException("System property 'project.basedir' was not null or empty. Please start your application with -D=project.basedir=/project/path");
throw new IllegalStateException("System property 'project.basedir' was null or empty. Please start your application with -D=project.basedir=/project/path");
}
public static String getEssentialsModuleName() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment