From d33924e876b1f2757fa738b0f8a7ebde656164ac Mon Sep 17 00:00:00 2001 From: "Christian P. MOMON" Date: Sat, 27 Nov 2021 01:55:09 +0100 Subject: [PATCH] Step in work. --- src/fr/devinsy/kiss4web/Kiss4webLauncher.java | 109 +++++++++++++++++ src/fr/devinsy/kiss4web/Page.java | 73 +++++++++++ .../dispatcher/KissDispatcherCache.java | 105 ++++++++++++++++ ...ssCache.java => KissDispatcherCache2.java} | 6 +- .../dispatcher/WebsiteClasspaths.java | 113 ++++++++++++++++++ .../hooks/ApplicationInitFailedHook.java | 92 ++++++++++++++ .../dispatcher/hooks/ApplicationInitHook.java | 92 ++++++++++++++ .../kiss4web/dispatcher/hooks/ErrorHook.java | 99 +++++++++++++++ .../kiss4web/dispatcher/hooks/Fatal.xhtml | 12 ++ .../kiss4web/dispatcher/hooks/FatalHook.java | 103 ++++++++++++++++ .../kiss4web/dispatcher/hooks/Hooks.java | 37 ++++++ .../dispatcher/hooks/InitFailedHook.java | 88 ++++++++++++++ .../kiss4web/dispatcher/hooks/InitHook.java | 92 ++++++++++++++ .../dispatcher/hooks/MaintenanceHook.java | 100 ++++++++++++++++ .../dispatcher/hooks/applicationInit.xhtml | 13 ++ .../hooks/applicationInitFailed.xhtml | 12 ++ .../kiss4web/dispatcher/hooks/init.xhtml | 13 ++ .../dispatcher/hooks/initFailed.xhtml | 12 ++ .../dispatcher/hooks/maintenance.xhtml | 12 ++ 19 files changed, 1180 insertions(+), 3 deletions(-) create mode 100644 src/fr/devinsy/kiss4web/Kiss4webLauncher.java create mode 100644 src/fr/devinsy/kiss4web/Page.java create mode 100644 src/fr/devinsy/kiss4web/dispatcher/KissDispatcherCache.java rename src/fr/devinsy/kiss4web/dispatcher/{KissClassCache.java => KissDispatcherCache2.java} (82%) create mode 100644 src/fr/devinsy/kiss4web/dispatcher/WebsiteClasspaths.java create mode 100644 src/fr/devinsy/kiss4web/dispatcher/hooks/ApplicationInitFailedHook.java create mode 100644 src/fr/devinsy/kiss4web/dispatcher/hooks/ApplicationInitHook.java create mode 100644 src/fr/devinsy/kiss4web/dispatcher/hooks/ErrorHook.java create mode 100644 src/fr/devinsy/kiss4web/dispatcher/hooks/Fatal.xhtml create mode 100644 src/fr/devinsy/kiss4web/dispatcher/hooks/FatalHook.java create mode 100644 src/fr/devinsy/kiss4web/dispatcher/hooks/Hooks.java create mode 100644 src/fr/devinsy/kiss4web/dispatcher/hooks/InitFailedHook.java create mode 100644 src/fr/devinsy/kiss4web/dispatcher/hooks/InitHook.java create mode 100644 src/fr/devinsy/kiss4web/dispatcher/hooks/MaintenanceHook.java create mode 100644 src/fr/devinsy/kiss4web/dispatcher/hooks/applicationInit.xhtml create mode 100644 src/fr/devinsy/kiss4web/dispatcher/hooks/applicationInitFailed.xhtml create mode 100644 src/fr/devinsy/kiss4web/dispatcher/hooks/init.xhtml create mode 100644 src/fr/devinsy/kiss4web/dispatcher/hooks/initFailed.xhtml create mode 100644 src/fr/devinsy/kiss4web/dispatcher/hooks/maintenance.xhtml diff --git a/src/fr/devinsy/kiss4web/Kiss4webLauncher.java b/src/fr/devinsy/kiss4web/Kiss4webLauncher.java new file mode 100644 index 0000000..6e00eb4 --- /dev/null +++ b/src/fr/devinsy/kiss4web/Kiss4webLauncher.java @@ -0,0 +1,109 @@ +/* + * Copyright (C) 2021 Christian Pierre MOMON + * + * This file is part of Juga, simple key value database. + * + * Juga is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * Juga is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with Juga. If not, see . + */ +package fr.devinsy.kiss4web; + +import java.io.File; + +import javax.naming.ConfigurationException; +import javax.servlet.ServletContext; +import javax.servlet.ServletContextEvent; + +import org.apache.commons.lang3.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * The Class JugaWebLauncher. + */ +public class Kiss4webLauncher implements javax.servlet.ServletContextListener +{ + private static Logger logger = LoggerFactory.getLogger(Kiss4webLauncher.class); + + /* (non-Javadoc) + * @see javax.servlet.ServletContextListener#contextInitialized(javax.servlet.ServletContextEvent) + */ + @Override + public void contextInitialized(final ServletContextEvent event) + { + launch(event.getServletContext()); + } + + /** + * Inits the logger. + */ + public void initLogger(final String webappRoot) + { + // Set logger. + String logFilePathname; + try + { + logFilePathname = new EnvironmentInformation().getLog4jPath(); + } + catch (ConfigurationException exception) + { + System.err.println("Error reading the environment information."); + exception.printStackTrace(); + logFilePathname = null; + } + + if (StringUtils.isBlank(logFilePathname)) + { + org.apache.log4j.BasicConfigurator.configure(); + logger.warn("Log configuration undefined, use of the basic configurator."); + } + else + { + System.out.println("Log configuration defined (" + logFilePathname + "), will use it."); + + if (!logFilePathname.startsWith("/")) + { + logFilePathname = webappRoot + logFilePathname; + System.out.println("Log configuration redefined (" + logFilePathname + "), will use it."); + } + + if (new File(logFilePathname).exists()) + { + org.apache.log4j.PropertyConfigurator.configure(logFilePathname); + } + else + { + System.out.println("Log configuration FILE NOT FOUND (" + logFilePathname + "), use of the basic configurator."); + org.apache.log4j.BasicConfigurator.configure(); + } + + logger = LoggerFactory.getLogger(this.getClass()); + logger.info("Log initialization done."); + } + } + + /** + * Launch. + * + * @param context + * the context + */ + public void launch(final ServletContext context) + { + System.out.println("========= KISS4WEB WEBAPP LAUNCHING… =========="); + + initLogger(context.getRealPath("/")); + Kiss4web.instance(); + System.out.println("========= KISS4WEB WEBAPP LAUNCHED =========="); + } +} diff --git a/src/fr/devinsy/kiss4web/Page.java b/src/fr/devinsy/kiss4web/Page.java new file mode 100644 index 0000000..5b6aa6d --- /dev/null +++ b/src/fr/devinsy/kiss4web/Page.java @@ -0,0 +1,73 @@ +/** + * Copyright 2021 Christian Pierre MOMON, DEVINSY, UMR 7186 LESC. + * + * christian.momon@devinsy.fr + * + * This file is part of Kiwa. This software (Kiwa) is a computer program whose + * purpose is to be the Kinsources Web Application, an open interactive platform + * for archiving, sharing, analyzing and comparing kinship data used in + * scientific inquiry. + * + * This software is governed by the CeCILL license under French law and abiding + * by the rules of distribution of free software. You can use, modify and/ or + * redistribute the software under the terms of the CeCILL license as circulated + * by CEA, CNRS and INRIA at the following URL "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, modify + * and redistribute granted by the license, users are provided only with a + * limited warranty and the software's author, the holder of the economic + * rights, and the successive licensors have only limited liability. + * + * In this respect, the user's attention is drawn to the risks associated with + * loading, using, modifying and/or developing or reproducing the software by + * the user in light of its specific status of free software, that may mean that + * it is complicated to manipulate, and that also therefore means that it is + * reserved for developers and experienced professionals having in-depth + * computer knowledge. Users are therefore encouraged to load and test the + * software's suitability as regards their requirements in conditions enabling + * the security of their systems and/or data to be ensured and, more generally, + * to use and operate it in the same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. + */ +package fr.devinsy.kiss4web; + +import java.io.IOException; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +/** + * The Class Page. + */ +public abstract class Page +{ + private static final long serialVersionUID = 7583814104851219020L; + private static org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(Page.class); + + private HttpServletRequest request; + private HttpServletResponse response; + + public Page(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException + { + this.request = request; + this.response = response; + } + + public void doGet() + { + + } + + public void doPost() + { + + } + + public void redirect(final String urlPath) + { + Redirector.redirect(this.response, urlPath); + } +} \ No newline at end of file diff --git a/src/fr/devinsy/kiss4web/dispatcher/KissDispatcherCache.java b/src/fr/devinsy/kiss4web/dispatcher/KissDispatcherCache.java new file mode 100644 index 0000000..8ab582a --- /dev/null +++ b/src/fr/devinsy/kiss4web/dispatcher/KissDispatcherCache.java @@ -0,0 +1,105 @@ +/** + * Copyright (C) 2006-2021 Christian Pierre MOMON + * + * This file is part of Kiss4web. + * + * Kiss4web is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Kiss4web is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Kiss4web. If not, see + */ +package fr.devinsy.kiss4web.dispatcher; + +import java.util.HashMap; + +import javax.servlet.http.HttpServlet; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * The Class KissDispatcherCache. + */ +public class KissDispatcherCache extends HashMap +{ + private static final long serialVersionUID = -7727974577347443504L; + private static Logger logger = LoggerFactory.getLogger(KissDispatcherCache.class); + + /** + * Instantiates a new kiss dispatcher cache. + */ + public KissDispatcherCache() + { + super(); + } + + /** + * Gets the first servlet matching path in the cache. + * + * @param path + * the path + * @return the http servlet + */ + public HttpServlet get(final String... path) + { + HttpServlet result; + + boolean ended = false; + int index = 0; + result = null; + while (!ended) + { + if (index < path.length) + { + result = get(path); + if (result == null) + { + index += 1; + } + else + { + ended = true; + } + } + else + { + ended = true; + result = null; + } + } + + // + return result; + } + + /** + * Gets the first servlet matching path in the cache. + * + * @param firstPath + * the first path to try + * @param secondPath + * the second path to try + * @return the http servlet + */ + public HttpServlet get(final String firstPath, final String secondPath) + { + HttpServlet result; + + result = get(firstPath); + if (result == null) + { + result = get(secondPath); + } + + // + return result; + } +} diff --git a/src/fr/devinsy/kiss4web/dispatcher/KissClassCache.java b/src/fr/devinsy/kiss4web/dispatcher/KissDispatcherCache2.java similarity index 82% rename from src/fr/devinsy/kiss4web/dispatcher/KissClassCache.java rename to src/fr/devinsy/kiss4web/dispatcher/KissDispatcherCache2.java index 1d94337..e30f96e 100644 --- a/src/fr/devinsy/kiss4web/dispatcher/KissClassCache.java +++ b/src/fr/devinsy/kiss4web/dispatcher/KissDispatcherCache2.java @@ -26,15 +26,15 @@ import org.slf4j.LoggerFactory; /** * The Class KissClassCache. */ -public class KissClassCache extends HashMap +public class KissDispatcherCache2 extends HashMap { private static final long serialVersionUID = 2058060444094070931L; - private static Logger logger = LoggerFactory.getLogger(KissClassCache.class); + private static Logger logger = LoggerFactory.getLogger(KissDispatcherCache2.class); /** * Instantiates a new kiss class cache. */ - public KissClassCache() + public KissDispatcherCache2() { super(); } diff --git a/src/fr/devinsy/kiss4web/dispatcher/WebsiteClasspaths.java b/src/fr/devinsy/kiss4web/dispatcher/WebsiteClasspaths.java new file mode 100644 index 0000000..0e03f44 --- /dev/null +++ b/src/fr/devinsy/kiss4web/dispatcher/WebsiteClasspaths.java @@ -0,0 +1,113 @@ +/** + * Copyright (C) 2021 Christian Pierre MOMON + * + * This file is part of Kiss4web. + * + * Kiss4web is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Kiss4web is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Kiss4web. If not, see + */ +package fr.devinsy.kiss4web.dispatcher; + +import java.util.Iterator; + +import javax.servlet.http.HttpServlet; + +import org.apache.commons.lang3.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import fr.devinsy.strings.StringList; + +/** + * The Class WebsiteClasspaths. + */ +public class WebsiteClasspaths extends StringList +{ + private static final long serialVersionUID = 3403269660538375143L; + + private static Logger logger = LoggerFactory.getLogger(WebsiteClasspaths.class); + + /** + * Instantiates a new website classpaths. + */ + public WebsiteClasspaths() + { + super(); + } + + /* (non-Javadoc) + * @see java.util.ArrayList#add(java.lang.Object) + */ + @Override + public boolean add(final String classpath) + { + boolean result; + + if (StringUtils.isBlank(classpath)) + { + result = false; + } + else + { + if (classpath.endsWith(".")) + { + result = super.add(classpath); + } + else + { + result = super.add(classpath + "."); + } + } + + // + return result; + } + + /** + * Instanciate servlet. + * + * @param subClasspath + * the sub classpath + * @return the http servlet + */ + public HttpServlet instanciateServlet(final String className) + { + HttpServlet result; + + boolean ended = false; + result = null; + Iterator iterator = this.iterator(); + while (!ended) + { + if (iterator.hasNext()) + { + String classpath = iterator.next(); + String classPath = classpath + className; + logger.debug("Trying {}", classPath); + result = KissDispatcherUtils.instanciateServlet(classPath); + if (result != null) + { + ended = true; + } + } + else + { + ended = true; + result = null; + } + } + + // + return result; + } +} diff --git a/src/fr/devinsy/kiss4web/dispatcher/hooks/ApplicationInitFailedHook.java b/src/fr/devinsy/kiss4web/dispatcher/hooks/ApplicationInitFailedHook.java new file mode 100644 index 0000000..34b7db7 --- /dev/null +++ b/src/fr/devinsy/kiss4web/dispatcher/hooks/ApplicationInitFailedHook.java @@ -0,0 +1,92 @@ +/** + * Copyright (C) 2018-2021 Christian Pierre MOMON + * + * This file is part of Kiss4web. + * + * Kiss4web is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Kiss4web is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Kiss4web. If not, see + */ +package fr.devinsy.kiss4web.dispatcher.hooks; + +import java.io.IOException; + +import javax.servlet.ServletConfig; +import javax.servlet.ServletContext; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import fr.devinsy.xidyn.XidynException; +import fr.devinsy.xidyn.presenters.URLPresenter; + +/** + * The Class InitHook. + */ +public class ApplicationInitFailedHook extends HookCore +{ + private static Logger logger = LoggerFactory.getLogger(ApplicationInitFailedHook.class); + + /** + * Instantiates a new inits the hook. + */ + public ApplicationInitFailedHook() + { + super(); + } + + /* (non-Javadoc) + * @see fr.devinsy.kiss4web.kernel.dispatcher.hooks.Hook#matches(javax.servlet.ServletContext, javax.servlet.http.HttpServletRequest) + */ + @Override + public boolean matches(final ServletContext servletContext, final HttpServletRequest request) + { + boolean result; + + result = true; + + // + return result; + } + + /* (non-Javadoc) + * @see fr.devinsy.kiss4web.dispatcher.hooks.Hook#process(javax.servlet.ServletConfig, javax.servlet.ServletContext, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) + */ + @Override + public void process(final ServletConfig servletConfig, final ServletContext servletContext, final HttpServletRequest request, + final HttpServletResponse response) throws IOException, ServletException + { + try + { + logger.debug("Doing catch {}.", this.getClass().getName()); + + String path = servletContext.getRealPath("/") + request.getPathInfo(); + logger.info("path=[{}]", path); + + StringBuffer html = new URLPresenter("/fr/devinsy/kiss4web/dispatcher/hooks/applicationInitFailed.xhtml").dynamize(); + + // Display page. + response.setContentType("application/xhtml+xml; charset=UTF-8"); + response.getWriter().println(html); + + logger.info("Application Init Failed page returned."); + } + catch (XidynException exception) + { + exception.printStackTrace(); + new FatalHook().process(servletConfig, servletContext, request, response); + } + } +} diff --git a/src/fr/devinsy/kiss4web/dispatcher/hooks/ApplicationInitHook.java b/src/fr/devinsy/kiss4web/dispatcher/hooks/ApplicationInitHook.java new file mode 100644 index 0000000..d7abd7b --- /dev/null +++ b/src/fr/devinsy/kiss4web/dispatcher/hooks/ApplicationInitHook.java @@ -0,0 +1,92 @@ +/** + * Copyright (C) 2018-2021 Christian Pierre MOMON + * + * This file is part of Kiss4web. + * + * Kiss4web is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Kiss4web is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Kiss4web. If not, see + */ +package fr.devinsy.kiss4web.dispatcher.hooks; + +import java.io.IOException; + +import javax.servlet.ServletConfig; +import javax.servlet.ServletContext; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import fr.devinsy.xidyn.XidynException; +import fr.devinsy.xidyn.presenters.URLPresenter; + +/** + * The Class InitHook. + */ +public class ApplicationInitHook extends HookCore +{ + private static Logger logger = LoggerFactory.getLogger(ApplicationInitHook.class); + + /** + * Instantiates a new inits the hook. + */ + public ApplicationInitHook() + { + super(); + } + + /* (non-Javadoc) + * @see fr.devinsy.kiss4web.kernel.dispatcher.hooks.Hook#matches(javax.servlet.ServletContext, javax.servlet.http.HttpServletRequest) + */ + @Override + public boolean matches(final ServletContext servletContext, final HttpServletRequest request) + { + boolean result; + + result = true; + + // + return result; + } + + /* (non-Javadoc) + * @see fr.devinsy.kiss4web.dispatcher.hooks.Hook#process(javax.servlet.ServletConfig, javax.servlet.ServletContext, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) + */ + @Override + public void process(final ServletConfig servletConfig, final ServletContext servletContext, final HttpServletRequest request, + final HttpServletResponse response) throws IOException, ServletException + { + try + { + logger.debug("Doing catch {}.", this.getClass().getName()); + + String path = servletContext.getRealPath("/") + request.getPathInfo(); + logger.info("path=[{}]", path); + + StringBuffer html = new URLPresenter("/fr/devinsy/kiss4web/dispatcher/hooks/applicationInit.xhtml").dynamize(); + + // Display page. + response.setContentType("application/xhtml+xml; charset=UTF-8"); + response.getWriter().println(html); + + logger.info("Application Init page returned."); + } + catch (XidynException exception) + { + exception.printStackTrace(); + new FatalHook().process(servletConfig, servletContext, request, response); + } + } +} diff --git a/src/fr/devinsy/kiss4web/dispatcher/hooks/ErrorHook.java b/src/fr/devinsy/kiss4web/dispatcher/hooks/ErrorHook.java new file mode 100644 index 0000000..38b1eaf --- /dev/null +++ b/src/fr/devinsy/kiss4web/dispatcher/hooks/ErrorHook.java @@ -0,0 +1,99 @@ +/** + * Copyright (C) 2018-2021 Christian Pierre MOMON + * + * This file is part of Kiss4web. + * + * Kiss4web is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Kiss4web is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Kiss4web. If not, see + */ +package fr.devinsy.kiss4web.dispatcher.hooks; + +import java.io.File; +import java.io.IOException; + +import javax.servlet.ServletConfig; +import javax.servlet.ServletContext; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import fr.devinsy.xidyn.XidynException; +import fr.devinsy.xidyn.presenters.URLPresenter; + +/** + * The Class ErrorHook. + */ +public class ErrorHook extends HookCore +{ + private static Logger logger = LoggerFactory.getLogger(ErrorHook.class); + + /** + * Instantiates a new error hook. + */ + public ErrorHook() + { + super(); + } + + /* (non-Javadoc) + * @see fr.devinsy.kiss4web.kernel.dispatcher.hooks.Hook#matches(javax.servlet.ServletContext, javax.servlet.http.HttpServletRequest) + */ + @Override + public boolean matches(final ServletContext servletContext, final HttpServletRequest request) + { + boolean result; + + if (new File(servletContext.getRealPath("/") + request.getPathInfo()).exists()) + { + result = true; + } + else + { + result = false; + } + + // + return result; + } + + /* (non-Javadoc) + * @see fr.devinsy.kiss4web.dispatcher.hooks.Hook#process(javax.servlet.ServletConfig, javax.servlet.ServletContext, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) + */ + @Override + public void process(final ServletConfig servletConfig, final ServletContext servletContext, final HttpServletRequest request, + final HttpServletResponse response) throws IOException, ServletException + { + logger.debug("Doing catch."); + + try + { + String path = servletContext.getRealPath("/") + request.getPathInfo(); + logger.info("path=[{}]", path); + + StringBuffer html = new URLPresenter("/fr/devinsy/kiss4web/dispatcher/hooks/error.xhtml").dynamize(); + // Display page. + response.setContentType("application/xhtml+xml; charset=UTF-8"); + response.getWriter().println(html); + + logger.info("Error page returned for [{}].", path); + } + catch (XidynException exception) + { + exception.printStackTrace(); + new FatalHook().process(servletConfig, servletContext, request, response); + } + } +} diff --git a/src/fr/devinsy/kiss4web/dispatcher/hooks/Fatal.xhtml b/src/fr/devinsy/kiss4web/dispatcher/hooks/Fatal.xhtml new file mode 100644 index 0000000..ee41057 --- /dev/null +++ b/src/fr/devinsy/kiss4web/dispatcher/hooks/Fatal.xhtml @@ -0,0 +1,12 @@ + + + + +Kiss4web + + + +

Fatal

+ Fatal error detected. Please contact administrator. + + diff --git a/src/fr/devinsy/kiss4web/dispatcher/hooks/FatalHook.java b/src/fr/devinsy/kiss4web/dispatcher/hooks/FatalHook.java new file mode 100644 index 0000000..abf56a4 --- /dev/null +++ b/src/fr/devinsy/kiss4web/dispatcher/hooks/FatalHook.java @@ -0,0 +1,103 @@ +/** + * Copyright (C) 2018-2021 Christian Pierre MOMON + * + * This file is part of Kiss4web. + * + * Kiss4web is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Kiss4web is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Kiss4web. If not, see + */ +package fr.devinsy.kiss4web.dispatcher.hooks; + +import java.io.File; +import java.io.IOException; +import java.io.PrintWriter; + +import javax.servlet.ServletConfig; +import javax.servlet.ServletContext; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * The Class FatalHook. + */ +public class FatalHook extends HookCore +{ + private static Logger logger = LoggerFactory.getLogger(FatalHook.class); + + /** + * Instantiates a new fatal hook. + */ + public FatalHook() + { + super(); + } + + /* (non-Javadoc) + * @see fr.devinsy.kiss4web.kernel.dispatcher.hooks.Hook#matches(javax.servlet.ServletContext, javax.servlet.http.HttpServletRequest) + */ + @Override + public boolean matches(final ServletContext servletContext, final HttpServletRequest request) + { + boolean result; + + if (new File(servletContext.getRealPath("/") + request.getPathInfo()).exists()) + { + result = true; + } + else + { + result = false; + } + + // + return result; + } + + /* (non-Javadoc) + * @see fr.devinsy.kiss4web.dispatcher.hooks.Hook#process(javax.servlet.ServletConfig, javax.servlet.ServletContext, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) + */ + @Override + public void process(final ServletConfig servletConfig, final ServletContext servletContext, final HttpServletRequest request, + final HttpServletResponse response) throws IOException, ServletException + { + logger.debug("Doing catch."); + + String path = servletContext.getRealPath("/") + request.getPathInfo(); + logger.info("path=[{}]", path); + + // Display fatal error page. + response.setContentType("text/html; charset=UTF-8"); + PrintWriter out = response.getWriter(); + out.println(""); + out.println(""); + out.println("
"); + out.println("A fatal error occured:
"); + out.println("
");
+        // out.println(source.getMessage());
+        out.println("
"); + out.println("
"); + // if (source.getMessage() != null) + // { + // out.println("
" + XidynUtils.restoreEntities(new
+        // StringBuffer(source.getMessage())) + "
"); + // } + out.println("
"); + out.println(""); + + logger.info("File returned directly [{}] with mimetype [{}].", path, servletContext.getMimeType(path)); + } +} diff --git a/src/fr/devinsy/kiss4web/dispatcher/hooks/Hooks.java b/src/fr/devinsy/kiss4web/dispatcher/hooks/Hooks.java new file mode 100644 index 0000000..294607a --- /dev/null +++ b/src/fr/devinsy/kiss4web/dispatcher/hooks/Hooks.java @@ -0,0 +1,37 @@ +/** + * Copyright (C) 2021 Christian Pierre MOMON + * + * This file is part of Kiss4web. + * + * Kiss4web is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Kiss4web is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Kiss4web. If not, see + */ +package fr.devinsy.kiss4web.dispatcher.hooks; + +import java.util.ArrayList; + +/** + * The Class HookList. + */ +public class Hooks extends ArrayList +{ + private static final long serialVersionUID = 3580793472824912708L; + + /** + * Instantiates a new hook list. + */ + public Hooks() + { + super(); + } +} diff --git a/src/fr/devinsy/kiss4web/dispatcher/hooks/InitFailedHook.java b/src/fr/devinsy/kiss4web/dispatcher/hooks/InitFailedHook.java new file mode 100644 index 0000000..abd819f --- /dev/null +++ b/src/fr/devinsy/kiss4web/dispatcher/hooks/InitFailedHook.java @@ -0,0 +1,88 @@ +/** + * Copyright (C) 2018-2021 Christian Pierre MOMON + * + * This file is part of Kiss4web. + * + * Kiss4web is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Kiss4web is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Kiss4web. If not, see + */ +package fr.devinsy.kiss4web.dispatcher.hooks; + +import java.io.File; +import java.io.IOException; + +import javax.servlet.ServletConfig; +import javax.servlet.ServletContext; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import fr.devinsy.kiss4web.dispatcher.KissDispatcherUtils; + +/** + * The Class InitFailedHook. + */ +public class InitFailedHook extends HookCore +{ + private static Logger logger = LoggerFactory.getLogger(InitFailedHook.class); + + /** + * Instantiates a new inits the failed hook. + */ + public InitFailedHook() + { + super(); + } + + /* (non-Javadoc) + * @see fr.devinsy.kiss4web.kernel.dispatcher.hooks.Hook#matches(javax.servlet.ServletContext, javax.servlet.http.HttpServletRequest) + */ + @Override + public boolean matches(final ServletContext servletContext, final HttpServletRequest request) + { + boolean result; + + if (new File(servletContext.getRealPath("/") + request.getPathInfo()).exists()) + { + result = true; + } + else + { + result = false; + } + + // + return result; + } + + /* (non-Javadoc) + * @see fr.devinsy.kiss4web.dispatcher.hooks.Hook#process(javax.servlet.ServletConfig, javax.servlet.ServletContext, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) + */ + @Override + public void process(final ServletConfig servletConfig, final ServletContext servletContext, final HttpServletRequest request, + final HttpServletResponse response) throws IOException, ServletException + { + logger.debug("Doing catch."); + + String path = servletContext.getRealPath("/") + request.getPathInfo(); + logger.info("path=[{}]", path); + + String mimeType = servletContext.getMimeType(path); + KissDispatcherUtils.returnInlineFile(response, new File(path), mimeType); + + logger.info("File returned directly [{}] with mimetype [{}].", path, servletContext.getMimeType(path)); + } +} diff --git a/src/fr/devinsy/kiss4web/dispatcher/hooks/InitHook.java b/src/fr/devinsy/kiss4web/dispatcher/hooks/InitHook.java new file mode 100644 index 0000000..3faf5b9 --- /dev/null +++ b/src/fr/devinsy/kiss4web/dispatcher/hooks/InitHook.java @@ -0,0 +1,92 @@ +/** + * Copyright (C) 2018-2021 Christian Pierre MOMON + * + * This file is part of Kiss4web. + * + * Kiss4web is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Kiss4web is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Kiss4web. If not, see + */ +package fr.devinsy.kiss4web.dispatcher.hooks; + +import java.io.IOException; + +import javax.servlet.ServletConfig; +import javax.servlet.ServletContext; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import fr.devinsy.xidyn.XidynException; +import fr.devinsy.xidyn.presenters.URLPresenter; + +/** + * The Class InitHook. + */ +public class InitHook extends HookCore +{ + private static Logger logger = LoggerFactory.getLogger(InitHook.class); + + /** + * Instantiates a new inits the hook. + */ + public InitHook() + { + super(); + } + + /* (non-Javadoc) + * @see fr.devinsy.kiss4web.kernel.dispatcher.hooks.Hook#matches(javax.servlet.ServletContext, javax.servlet.http.HttpServletRequest) + */ + @Override + public boolean matches(final ServletContext servletContext, final HttpServletRequest request) + { + boolean result; + + result = true; + + // + return result; + } + + /* (non-Javadoc) + * @see fr.devinsy.kiss4web.dispatcher.hooks.Hook#process(javax.servlet.ServletConfig, javax.servlet.ServletContext, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) + */ + @Override + public void process(final ServletConfig servletConfig, final ServletContext servletContext, final HttpServletRequest request, + final HttpServletResponse response) throws IOException, ServletException + { + try + { + logger.debug("Doing catch {}.", this.getClass().getName()); + + String path = servletContext.getRealPath("/") + request.getPathInfo(); + logger.info("path=[{}]", path); + + StringBuffer html = new URLPresenter("/fr/devinsy/kiss4web/dispatcher/hooks/init.xhtml").dynamize(); + + // Display page. + response.setContentType("application/xhtml+xml; charset=UTF-8"); + response.getWriter().println(html); + + logger.info("Init page returned."); + } + catch (XidynException exception) + { + exception.printStackTrace(); + new FatalHook().process(servletConfig, servletContext, request, response); + } + } +} diff --git a/src/fr/devinsy/kiss4web/dispatcher/hooks/MaintenanceHook.java b/src/fr/devinsy/kiss4web/dispatcher/hooks/MaintenanceHook.java new file mode 100644 index 0000000..41c96b4 --- /dev/null +++ b/src/fr/devinsy/kiss4web/dispatcher/hooks/MaintenanceHook.java @@ -0,0 +1,100 @@ +/** + * Copyright (C) 2018-2021 Christian Pierre MOMON + * + * This file is part of Kiss4web. + * + * Kiss4web is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Kiss4web is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Kiss4web. If not, see + */ +package fr.devinsy.kiss4web.dispatcher.hooks; + +import java.io.File; +import java.io.IOException; + +import javax.servlet.ServletConfig; +import javax.servlet.ServletContext; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import fr.devinsy.xidyn.XidynException; +import fr.devinsy.xidyn.presenters.URLPresenter; + +/** + * The Class MaintenanceHook. + */ +public class MaintenanceHook extends HookCore +{ + private static Logger logger = LoggerFactory.getLogger(MaintenanceHook.class); + + /** + * Instantiates a new maintenance hook. + */ + public MaintenanceHook() + { + super(); + } + + /* (non-Javadoc) + * @see fr.devinsy.kiss4web.kernel.dispatcher.hooks.Hook#matches(javax.servlet.ServletContext, javax.servlet.http.HttpServletRequest) + */ + @Override + public boolean matches(final ServletContext servletContext, final HttpServletRequest request) + { + boolean result; + + if (new File(servletContext.getRealPath("/") + request.getPathInfo()).exists()) + { + result = true; + } + else + { + result = false; + } + + // + return result; + } + + /* (non-Javadoc) + * @see fr.devinsy.kiss4web.dispatcher.hooks.Hook#process(javax.servlet.ServletConfig, javax.servlet.ServletContext, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) + */ + @Override + public void process(final ServletConfig servletConfig, final ServletContext servletContext, final HttpServletRequest request, + final HttpServletResponse response) throws IOException, ServletException + { + try + { + logger.debug("Doing catch {}.", this.getClass().getName()); + + String path = servletContext.getRealPath("/") + request.getPathInfo(); + logger.info("path=[{}]", path); + + StringBuffer html = new URLPresenter("/fr/devinsy/kiss4web/dispatcher/hooks/maintenance.xhtml").dynamize(); + + // Display page. + response.setContentType("application/xhtml+xml; charset=UTF-8"); + response.getWriter().println(html); + + logger.info("Application Init page returned."); + } + catch (XidynException exception) + { + exception.printStackTrace(); + new FatalHook().process(servletConfig, servletContext, request, response); + } + } +} diff --git a/src/fr/devinsy/kiss4web/dispatcher/hooks/applicationInit.xhtml b/src/fr/devinsy/kiss4web/dispatcher/hooks/applicationInit.xhtml new file mode 100644 index 0000000..bb8dce9 --- /dev/null +++ b/src/fr/devinsy/kiss4web/dispatcher/hooks/applicationInit.xhtml @@ -0,0 +1,13 @@ + + + + + Kiss4web + + + + +

Init

+ Application is in init mode… Please wait for automatic reload. + + diff --git a/src/fr/devinsy/kiss4web/dispatcher/hooks/applicationInitFailed.xhtml b/src/fr/devinsy/kiss4web/dispatcher/hooks/applicationInitFailed.xhtml new file mode 100644 index 0000000..efcaea3 --- /dev/null +++ b/src/fr/devinsy/kiss4web/dispatcher/hooks/applicationInitFailed.xhtml @@ -0,0 +1,12 @@ + + + + +Kiss4web + + + +

Application Init Failed

+ Application detects an error. Please contact administrator. + + diff --git a/src/fr/devinsy/kiss4web/dispatcher/hooks/init.xhtml b/src/fr/devinsy/kiss4web/dispatcher/hooks/init.xhtml new file mode 100644 index 0000000..ea31e09 --- /dev/null +++ b/src/fr/devinsy/kiss4web/dispatcher/hooks/init.xhtml @@ -0,0 +1,13 @@ + + + + + Kiss4web + + + + +

Init

+ Kiss4web is in init mode… Please wait for automatic reload. + + diff --git a/src/fr/devinsy/kiss4web/dispatcher/hooks/initFailed.xhtml b/src/fr/devinsy/kiss4web/dispatcher/hooks/initFailed.xhtml new file mode 100644 index 0000000..156ef41 --- /dev/null +++ b/src/fr/devinsy/kiss4web/dispatcher/hooks/initFailed.xhtml @@ -0,0 +1,12 @@ + + + + +Kiss4web + + + +

Init Failed

+ Kiss4web detects an error. Please contact administrator. + + diff --git a/src/fr/devinsy/kiss4web/dispatcher/hooks/maintenance.xhtml b/src/fr/devinsy/kiss4web/dispatcher/hooks/maintenance.xhtml new file mode 100644 index 0000000..fd93241 --- /dev/null +++ b/src/fr/devinsy/kiss4web/dispatcher/hooks/maintenance.xhtml @@ -0,0 +1,12 @@ + + + + +Kiss4web + + + +

Maintenance

+ This website is in maintenance mode. Please try again later. + +