Step in work.

This commit is contained in:
Christian P. MOMON 2021-11-27 01:55:09 +01:00
parent 50a2de3164
commit d33924e876
19 changed files with 1180 additions and 3 deletions

View file

@ -0,0 +1,109 @@
/*
* Copyright (C) 2021 Christian Pierre MOMON <christian.momon@devinsy.fr>
*
* 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 <http://www.gnu.org/licenses/>.
*/
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 ==========");
}
}

View file

@ -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);
}
}

View file

@ -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 <http://www.gnu.org/licenses/>
*/
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<String, HttpServlet>
{
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;
}
}

View file

@ -26,15 +26,15 @@ import org.slf4j.LoggerFactory;
/** /**
* The Class KissClassCache. * The Class KissClassCache.
*/ */
public class KissClassCache extends HashMap<String, String> public class KissDispatcherCache2 extends HashMap<String, String>
{ {
private static final long serialVersionUID = 2058060444094070931L; 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. * Instantiates a new kiss class cache.
*/ */
public KissClassCache() public KissDispatcherCache2()
{ {
super(); super();
} }

View file

@ -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 <http://www.gnu.org/licenses/>
*/
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<String> 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;
}
}

View file

@ -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 <http://www.gnu.org/licenses/>
*/
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);
}
}
}

View file

@ -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 <http://www.gnu.org/licenses/>
*/
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);
}
}
}

View file

@ -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 <http://www.gnu.org/licenses/>
*/
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);
}
}
}

View file

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Kiss4web</title>
<meta charset="UTF-8" />
</head>
<body>
<h1>Fatal</h1>
Fatal error detected. Please contact administrator.
</body>
</html>

View file

@ -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 <http://www.gnu.org/licenses/>
*/
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("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>");
out.println("<!DOCTYPE html >");
out.println("<html><header></header><body>");
out.println("A fatal error occured:<br/>");
out.println("<pre>");
// out.println(source.getMessage());
out.println("</pre>");
out.println("<hr />");
// if (source.getMessage() != null)
// {
// out.println("<pre>" + XidynUtils.restoreEntities(new
// StringBuffer(source.getMessage())) + "</pre>");
// }
out.println("<hr />");
out.println("</body></html>");
logger.info("File returned directly [{}] with mimetype [{}].", path, servletContext.getMimeType(path));
}
}

View file

@ -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 <http://www.gnu.org/licenses/>
*/
package fr.devinsy.kiss4web.dispatcher.hooks;
import java.util.ArrayList;
/**
* The Class HookList.
*/
public class Hooks extends ArrayList<Hook>
{
private static final long serialVersionUID = 3580793472824912708L;
/**
* Instantiates a new hook list.
*/
public Hooks()
{
super();
}
}

View file

@ -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 <http://www.gnu.org/licenses/>
*/
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));
}
}

View file

@ -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 <http://www.gnu.org/licenses/>
*/
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);
}
}
}

View file

@ -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 <http://www.gnu.org/licenses/>
*/
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);
}
}
}

View file

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Kiss4web</title>
<meta charset="UTF-8" />
<meta http-equiv="refresh" content="10" />
</head>
<body>
<h1>Init</h1>
Application is in init mode… Please wait for automatic reload.
</body>
</html>

View file

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Kiss4web</title>
<meta charset="UTF-8" />
</head>
<body>
<h1>Application Init Failed</h1>
Application detects an error. Please contact administrator.
</body>
</html>

View file

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Kiss4web</title>
<meta charset="UTF-8" />
<meta http-equiv="refresh" content="10" />
</head>
<body>
<h1>Init</h1>
Kiss4web is in init mode… Please wait for automatic reload.
</body>
</html>

View file

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Kiss4web</title>
<meta charset="UTF-8" />
</head>
<body>
<h1>Init Failed</h1>
Kiss4web detects an error. Please contact administrator.
</body>
</html>

View file

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Kiss4web</title>
<meta charset="UTF-8" />
</head>
<body>
<h1>Maintenance</h1>
This website is in maintenance mode. Please try again later.
</body>
</html>