Step in dev.
This commit is contained in:
parent
c50aca1771
commit
50a2de3164
18 changed files with 711 additions and 399 deletions
|
@ -21,7 +21,6 @@ package fr.devinsy.kiss4web;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import org.apache.commons.lang3.exception.ExceptionUtils;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
@ -45,12 +44,11 @@ public class BuildInformation
|
||||||
*/
|
*/
|
||||||
public BuildInformation()
|
public BuildInformation()
|
||||||
{
|
{
|
||||||
Properties build = new Properties();
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
//
|
Properties build = new Properties();
|
||||||
build.load(BuildInformation.class.getResource("/build_information.properties").openStream());
|
|
||||||
|
build.load(BuildInformation.class.getResource("/fr.devinsy.kiss4web/build_information.properties").openStream());
|
||||||
|
|
||||||
//
|
//
|
||||||
this.productName = build.getProperty("product.name", "n/a");
|
this.productName = build.getProperty("product.name", "n/a");
|
||||||
|
@ -64,11 +62,8 @@ public class BuildInformation
|
||||||
}
|
}
|
||||||
catch (IOException exception)
|
catch (IOException exception)
|
||||||
{
|
{
|
||||||
//
|
logger.error("Error loading the build.properties file: " + exception.getMessage(), exception);
|
||||||
logger.error("Error loading the build.properties file: " + exception.getMessage());
|
|
||||||
logger.error(ExceptionUtils.getStackTrace(exception));
|
|
||||||
|
|
||||||
//
|
|
||||||
this.productName = "n/a";
|
this.productName = "n/a";
|
||||||
this.majorRevision = "n/a";
|
this.majorRevision = "n/a";
|
||||||
this.minorRevision = "n/a";
|
this.minorRevision = "n/a";
|
||||||
|
|
|
@ -1,48 +1,36 @@
|
||||||
/**
|
/**
|
||||||
* Copyright 2013-2021 Christian Pierre MOMON, DEVINSY, UMR 7186 LESC.
|
* Copyright 2013-2021 Christian Pierre MOMON
|
||||||
*
|
*
|
||||||
* christian.momon@devinsy.fr
|
* christian.momon@devinsy.fr
|
||||||
*
|
*
|
||||||
* This file is part of kiss4web. This software (Kiwa) is a computer program whose
|
* This file is part of Kiss4web.
|
||||||
* 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
|
* Kiss4web is free software: you can redistribute it and/or modify
|
||||||
* by the rules of distribution of free software. You can use, modify and/ or
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
* redistribute the software under the terms of the CeCILL license as circulated
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
* by CEA, CNRS and INRIA at the following URL "http://www.cecill.info".
|
* (at your option) any later version.
|
||||||
*
|
*
|
||||||
* As a counterpart to the access to the source code and rights to copy, modify
|
* Kiss4web is distributed in the hope that it will be useful,
|
||||||
* and redistribute granted by the license, users are provided only with a
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* limited warranty and the software's author, the holder of the economic
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* rights, and the successive licensors have only limited liability.
|
* GNU Lesser General Public License for more details.
|
||||||
*
|
*
|
||||||
* In this respect, the user's attention is drawn to the risks associated with
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
* loading, using, modifying and/or developing or reproducing the software by
|
* along with Kiss4web. If not, see <http://www.gnu.org/licenses/>
|
||||||
* 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;
|
package fr.devinsy.kiss4web;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
import javax.naming.ConfigurationException;
|
import javax.naming.ConfigurationException;
|
||||||
import javax.naming.Context;
|
import javax.naming.Context;
|
||||||
import javax.naming.InitialContext;
|
import javax.naming.InitialContext;
|
||||||
import javax.naming.NamingException;
|
import javax.naming.NamingException;
|
||||||
|
|
||||||
import org.apache.commons.lang3.exception.ExceptionUtils;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import fr.devinsy.util.strings.StringListUtils;
|
import fr.devinsy.strings.StringsUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Class EnvironmentInformation.
|
* The Class EnvironmentInformation.
|
||||||
|
@ -51,10 +39,7 @@ public class EnvironmentInformation
|
||||||
{
|
{
|
||||||
private static final Logger logger = LoggerFactory.getLogger(EnvironmentInformation.class);;
|
private static final Logger logger = LoggerFactory.getLogger(EnvironmentInformation.class);;
|
||||||
|
|
||||||
private String name;
|
private Context environment;
|
||||||
private String websiteName;
|
|
||||||
private String websiteUrl;
|
|
||||||
private String log4jFilePathname;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instantiates a new environment information.
|
* Instantiates a new environment information.
|
||||||
|
@ -66,65 +51,40 @@ public class EnvironmentInformation
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
//
|
|
||||||
Context initialContext = new InitialContext();
|
Context initialContext = new InitialContext();
|
||||||
Context environment = (Context) initialContext.lookup("java:comp/env");
|
this.environment = (Context) initialContext.lookup("java:comp/env");
|
||||||
|
|
||||||
//
|
|
||||||
this.name = (String) environment.lookup("kiss4web.environment.name");
|
|
||||||
|
|
||||||
//
|
|
||||||
this.websiteName = (String) environment.lookup("kiss4web.website.name");
|
|
||||||
|
|
||||||
//
|
|
||||||
this.websiteUrl = (String) environment.lookup("kiss4web.website.url");
|
|
||||||
if ((this.websiteUrl != null) && (!this.websiteUrl.endsWith("/")))
|
|
||||||
{
|
|
||||||
this.websiteUrl = this.websiteUrl + "/";
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
this.log4jFilePathname = (String) environment.lookup("kiss4web.log4j.path");
|
|
||||||
}
|
}
|
||||||
catch (NamingException exception)
|
catch (NamingException exception)
|
||||||
{
|
{
|
||||||
logger.error("Error setting the java:comp/env context: ", exception.getMessage());
|
logger.error("Error getting context information: ", exception.getMessage(), exception);
|
||||||
logger.error(ExceptionUtils.getStackTrace(exception));
|
|
||||||
logger.error("Environment information:");
|
|
||||||
logger.error("- name=[" + this.name + "]");
|
|
||||||
logger.error("- websiteUrl=[" + this.websiteUrl + "]");
|
|
||||||
logger.error("- log4jPath=[" + this.log4jFilePathname + "]");
|
|
||||||
|
|
||||||
throw new ConfigurationException("Error setting environment information: " + exception.getMessage());
|
throw new ConfigurationException("Error setting environment information: " + exception.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check availability of all fields.
|
// Check availability of all fields.
|
||||||
if (isNotAvailable())
|
if (!isAvailable())
|
||||||
{
|
{
|
||||||
logger.error("Environment information:");
|
|
||||||
logger.error("- name=[" + this.name + "]");
|
|
||||||
logger.error("- websiteUrl=[" + this.websiteUrl + "]");
|
|
||||||
logger.error("- log4jPath=[" + this.log4jFilePathname + "]");
|
|
||||||
|
|
||||||
throw new ConfigurationException("Environment information is not fully available.");
|
throw new ConfigurationException("Environment information is not fully available.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Gets the log 4 j path.
|
||||||
*
|
*
|
||||||
* @return
|
* @return the log 4 j path
|
||||||
|
* @throws ConfigurationException
|
||||||
|
* the configuration exception
|
||||||
*/
|
*/
|
||||||
public boolean isAvailable()
|
public String getLog4jPath() throws ConfigurationException
|
||||||
{
|
{
|
||||||
boolean result;
|
String result;
|
||||||
|
|
||||||
if (StringListUtils.containsBlank(this.name, this.websiteName, this.websiteUrl, this.log4jFilePathname))
|
try
|
||||||
{
|
{
|
||||||
result = false;
|
result = (String) this.environment.lookup("kiss4web.log4j.path");
|
||||||
}
|
}
|
||||||
else
|
catch (NamingException exception)
|
||||||
{
|
{
|
||||||
result = true;
|
throw new ConfigurationException("Context configuration error on log4j path.");
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@ -132,35 +92,168 @@ public class EnvironmentInformation
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Gets the name.
|
||||||
*
|
*
|
||||||
* @return
|
* @return the name
|
||||||
|
* @throws ConfigurationException
|
||||||
|
* the configuration exception
|
||||||
*/
|
*/
|
||||||
public boolean isNotAvailable()
|
public String getName() throws ConfigurationException
|
||||||
{
|
{
|
||||||
boolean result;
|
String result;
|
||||||
|
|
||||||
result = !isAvailable();
|
try
|
||||||
|
{
|
||||||
|
result = (String) this.environment.lookup("kiss4web.environment.name");
|
||||||
|
}
|
||||||
|
catch (NamingException exception)
|
||||||
|
{
|
||||||
|
throw new ConfigurationException("Context configuration error on environment name.");
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String log4jFilePathname()
|
/**
|
||||||
|
* Gets the statool infos configuration file.
|
||||||
|
*
|
||||||
|
* @return the statool infos configuration file
|
||||||
|
* @throws ConfigurationException
|
||||||
|
* the configuration exception
|
||||||
|
*/
|
||||||
|
public File getStatoolInfosConfigurationFile() throws ConfigurationException
|
||||||
{
|
{
|
||||||
return this.log4jFilePathname;
|
File result;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
String filepath = (String) this.environment.lookup("statoosinfosweb.configuration.file");
|
||||||
|
if (filepath == null)
|
||||||
|
{
|
||||||
|
result = null;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
result = new File(filepath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (NamingException exception)
|
||||||
|
{
|
||||||
|
throw new ConfigurationException("Context configuration missing 'statoosinfosweb.configuration.file'.");
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String name()
|
/**
|
||||||
|
* Gets the website name.
|
||||||
|
*
|
||||||
|
* @return the website name
|
||||||
|
* @throws ConfigurationException
|
||||||
|
* the configuration exception
|
||||||
|
*/
|
||||||
|
public String getWebsiteName() throws ConfigurationException
|
||||||
{
|
{
|
||||||
return this.name;
|
String result;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
result = (String) this.environment.lookup("kiss4web.website.name");
|
||||||
|
}
|
||||||
|
catch (NamingException exception)
|
||||||
|
{
|
||||||
|
throw new ConfigurationException("Context configuration error on website name.");
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String websiteName()
|
/**
|
||||||
|
* Gets the website package path.
|
||||||
|
*
|
||||||
|
* @return the website package path
|
||||||
|
* @throws ConfigurationException
|
||||||
|
* the configuration exception
|
||||||
|
*/
|
||||||
|
public String getWebsitePackagePath() throws ConfigurationException
|
||||||
{
|
{
|
||||||
return this.websiteName;
|
String result;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
result = (String) this.environment.lookup("kiss4web.website.packagepath");
|
||||||
|
|
||||||
|
if ((result != null) && (!result.endsWith(".")))
|
||||||
|
{
|
||||||
|
result = result + ".";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (NamingException exception)
|
||||||
|
{
|
||||||
|
throw new ConfigurationException("Context configuration error on website package path.");
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String websiteUrl()
|
/**
|
||||||
|
* Gets the website URL path.
|
||||||
|
*
|
||||||
|
* @return the website URL path
|
||||||
|
* @throws ConfigurationException
|
||||||
|
* the configuration exception
|
||||||
|
*/
|
||||||
|
public String getWebsiteURLPath() throws ConfigurationException
|
||||||
{
|
{
|
||||||
return this.websiteUrl;
|
String result;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
result = (String) this.environment.lookup("kiss4web.website.url");
|
||||||
|
if ((result != null) && (!result.endsWith("/")))
|
||||||
|
{
|
||||||
|
result = result + "/";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (NamingException exception)
|
||||||
|
{
|
||||||
|
throw new ConfigurationException("Context configuration error on website package path.");
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if is available.
|
||||||
|
*
|
||||||
|
* @return true, if is available
|
||||||
|
*/
|
||||||
|
public boolean isAvailable()
|
||||||
|
{
|
||||||
|
boolean result;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (StringsUtils.containsBlank(getName(), getWebsiteURLPath(), getWebsiteURLPath()))
|
||||||
|
{
|
||||||
|
result = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
result = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (NamingException exception)
|
||||||
|
{
|
||||||
|
result = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,23 @@ package fr.devinsy.kiss4web;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.commons.lang3.exception.ExceptionUtils;
|
|
||||||
|
import fr.devinsy.kiss4web.dispatcher.KissDispatcher;
|
||||||
|
import fr.devinsy.kiss4web.dispatcher.KissDispatcherFactory;
|
||||||
|
import fr.devinsy.kiss4web.dispatcher.hooks.ApplicationInitFailedHook;
|
||||||
|
import fr.devinsy.kiss4web.dispatcher.hooks.ApplicationInitHook;
|
||||||
|
import fr.devinsy.kiss4web.dispatcher.hooks.BlankHook;
|
||||||
|
import fr.devinsy.kiss4web.dispatcher.hooks.FatalHook;
|
||||||
|
import fr.devinsy.kiss4web.dispatcher.hooks.FolderHook;
|
||||||
|
import fr.devinsy.kiss4web.dispatcher.hooks.HookRegister;
|
||||||
|
import fr.devinsy.kiss4web.dispatcher.hooks.InitFailedHook;
|
||||||
|
import fr.devinsy.kiss4web.dispatcher.hooks.LongURLHook;
|
||||||
|
import fr.devinsy.kiss4web.dispatcher.hooks.MaintenanceHook;
|
||||||
|
import fr.devinsy.kiss4web.dispatcher.hooks.RootHook;
|
||||||
|
import fr.devinsy.kiss4web.dispatcher.hooks.ShortURLHook;
|
||||||
|
import fr.devinsy.kiss4web.dispatcher.hooks.WebContentHook;
|
||||||
|
import fr.devinsy.kiss4web.dispatcher.hooks.WebInfHook;
|
||||||
|
import fr.devinsy.kiss4web.dispatcher.hooks.XHTMLHook;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Class Kiss4web.
|
* The Class Kiss4web.
|
||||||
|
@ -30,64 +46,72 @@ public class Kiss4web
|
||||||
{
|
{
|
||||||
private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(Kiss4web.class);
|
private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(Kiss4web.class);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Enum Mode.
|
||||||
|
*/
|
||||||
|
public enum Mode
|
||||||
|
{
|
||||||
|
INIT,
|
||||||
|
INIT_FAILED,
|
||||||
|
APPLICATION_INIT,
|
||||||
|
APPLICATION_INIT_FAILED,
|
||||||
|
OPEN,
|
||||||
|
MAINTENANCE,
|
||||||
|
FATAL,
|
||||||
|
CUSTOM
|
||||||
|
}
|
||||||
|
|
||||||
private static class SingletonHolder
|
private static class SingletonHolder
|
||||||
{
|
{
|
||||||
private static final Kiss4web instance = new Kiss4web();
|
private static final Kiss4web instance = new Kiss4web();
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum Status
|
|
||||||
{
|
|
||||||
INIT_FAILED,
|
|
||||||
OPENED,
|
|
||||||
MAINTENANCE
|
|
||||||
}
|
|
||||||
|
|
||||||
private BuildInformation buildInformation;
|
private BuildInformation buildInformation;
|
||||||
private Status status;
|
private Mode mode;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instantiates a new kiss 4 web.
|
* Instantiates a new kiss 4 web.
|
||||||
*/
|
*/
|
||||||
private Kiss4web()
|
private Kiss4web()
|
||||||
{
|
{
|
||||||
//
|
String currentLog = "Kiss4web";
|
||||||
String currentLog = "Kiwa";
|
|
||||||
|
|
||||||
//
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
currentLog = "Kiwa";
|
this.mode = Mode.INIT;
|
||||||
logger.info("Kiwa initializing...");
|
|
||||||
|
//
|
||||||
|
currentLog = "Kiss4web";
|
||||||
|
logger.info("Kiss4web initializing...");
|
||||||
long startTime = new Date().getTime();
|
long startTime = new Date().getTime();
|
||||||
logInit(currentLog, "STARTING");
|
logInit(currentLog, "STARTING");
|
||||||
|
|
||||||
//
|
//
|
||||||
currentLog = "BuildInformation";
|
// currentLog = "BuildInformation";
|
||||||
this.buildInformation = new BuildInformation();
|
// this.buildInformation = new BuildInformation();
|
||||||
logger.info(" build information=[" + this.buildInformation.toString() + "]");
|
// logger.info(" build information=[" +
|
||||||
logInit(currentLog, "PASSED");
|
// this.buildInformation.toString() + "]");
|
||||||
|
// logInit(currentLog, "PASSED");
|
||||||
|
|
||||||
//
|
//
|
||||||
currentLog = "Kiwa";
|
|
||||||
|
//
|
||||||
|
setMode(Mode.APPLICATION_INIT);
|
||||||
|
logInit("set APPLICATION INIT mode", "PASSED");
|
||||||
|
|
||||||
|
//
|
||||||
|
currentLog = "Kiss4web";
|
||||||
logInit(currentLog, "STARTED");
|
logInit(currentLog, "STARTED");
|
||||||
long endTime = new Date().getTime();
|
long endTime = new Date().getTime();
|
||||||
logger.info("Kiss4web initialized in {}ms.", endTime - startTime);
|
logger.info("Kiss4web initialized in {}ms.", endTime - startTime);
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (Exception exception)
|
catch (Exception exception)
|
||||||
{
|
{
|
||||||
//
|
|
||||||
logInit(currentLog, "FAILED");
|
logInit(currentLog, "FAILED");
|
||||||
|
|
||||||
//
|
logger.warn("KISS4WEB INIT FAILED: " + exception.getMessage(), exception);
|
||||||
logger.warn("KISS4WEV INIT FAILED: " + exception.getMessage());
|
setMode(Mode.INIT_FAILED);
|
||||||
|
|
||||||
//
|
|
||||||
logger.warn(ExceptionUtils.getStackTrace(exception));
|
|
||||||
|
|
||||||
//
|
|
||||||
this.status = Kiss4web.Status.INIT_FAILED;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -102,24 +126,122 @@ public class Kiss4web
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the status.
|
* Gets the mode.
|
||||||
*
|
*
|
||||||
* @return the status
|
* @return the mode
|
||||||
*/
|
*/
|
||||||
public Kiss4web.Status getStatus()
|
public Mode getMode()
|
||||||
{
|
{
|
||||||
return this.status;
|
return this.mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the status.
|
* Sets the mode.
|
||||||
*
|
*
|
||||||
* @param status
|
* @param mode
|
||||||
* the new status
|
* the new mode
|
||||||
*/
|
*/
|
||||||
public void setStatus(final Status status)
|
public void setMode(final Mode mode)
|
||||||
{
|
{
|
||||||
this.status = status;
|
switch (mode)
|
||||||
|
{
|
||||||
|
case INIT:
|
||||||
|
break;
|
||||||
|
|
||||||
|
case INIT_FAILED:
|
||||||
|
{
|
||||||
|
if (this.mode == Mode.INIT)
|
||||||
|
{
|
||||||
|
this.mode = mode;
|
||||||
|
HookRegister hooks = new HookRegister("Init failed");
|
||||||
|
hooks.register(new InitFailedHook());
|
||||||
|
KissDispatcher.setHookRegister(hooks);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case APPLICATION_INIT:
|
||||||
|
{
|
||||||
|
if (this.mode == Mode.INIT)
|
||||||
|
{
|
||||||
|
this.mode = mode;
|
||||||
|
HookRegister hooks = new HookRegister("Application Init");
|
||||||
|
hooks.register(new ApplicationInitHook());
|
||||||
|
KissDispatcher.setHookRegister(hooks);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case APPLICATION_INIT_FAILED:
|
||||||
|
{
|
||||||
|
if (this.mode == Mode.APPLICATION_INIT_FAILED)
|
||||||
|
{
|
||||||
|
this.mode = mode;
|
||||||
|
HookRegister hooks = new HookRegister("Application Init failed");
|
||||||
|
hooks.register(new ApplicationInitFailedHook());
|
||||||
|
KissDispatcher.setHookRegister(hooks);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case OPEN:
|
||||||
|
{
|
||||||
|
this.mode = mode;
|
||||||
|
|
||||||
|
HookRegister hooks = new HookRegister("Open");
|
||||||
|
hooks.register(new BlankHook());
|
||||||
|
hooks.register(new RootHook());
|
||||||
|
hooks.register(new LongURLHook());
|
||||||
|
hooks.register(new FolderHook());
|
||||||
|
hooks.register(new ShortURLHook());
|
||||||
|
hooks.register(new XHTMLHook());
|
||||||
|
hooks.register(new WebContentHook());
|
||||||
|
hooks.register(new WebInfHook());
|
||||||
|
|
||||||
|
KissDispatcher.setHookRegister(hooks);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case MAINTENANCE:
|
||||||
|
{
|
||||||
|
this.mode = mode;
|
||||||
|
|
||||||
|
HookRegister hooks = new HookRegister("Maintenance");
|
||||||
|
hooks.register(new MaintenanceHook());
|
||||||
|
|
||||||
|
KissDispatcher.setHookRegister(hooks);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case FATAL:
|
||||||
|
{
|
||||||
|
this.mode = mode;
|
||||||
|
|
||||||
|
HookRegister hooks = new HookRegister("Fatal");
|
||||||
|
hooks.register(new FatalHook());
|
||||||
|
|
||||||
|
KissDispatcher.setHookRegister(hooks);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CUSTOM:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the mode custom.
|
||||||
|
*
|
||||||
|
* @param register
|
||||||
|
* the new mode custom
|
||||||
|
*/
|
||||||
|
public void setModeCustom(final HookRegister hooks)
|
||||||
|
{
|
||||||
|
if (hooks != null)
|
||||||
|
{
|
||||||
|
this.mode = Mode.CUSTOM;
|
||||||
|
KissDispatcher.setHookRegister(hooks);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/**
|
/**
|
||||||
* Copyright (C) 2006-2010, 2021 Christian Pierre MOMON
|
* Copyright (C) 2006-2021 Christian Pierre MOMON
|
||||||
*
|
*
|
||||||
* This file is part of Kiss4web.
|
* This file is part of Kiss4web.
|
||||||
*
|
*
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/**
|
/**
|
||||||
* Copyright (C) 2006-2010, 2013-2016 Christian Pierre MOMON
|
* Copyright (C) 2006-2021 Christian Pierre MOMON
|
||||||
*
|
*
|
||||||
* This file is part of Kiss4web.
|
* This file is part of Kiss4web.
|
||||||
*
|
*
|
||||||
|
@ -25,10 +25,10 @@ import org.apache.commons.codec.digest.DigestUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import fr.devinsy.util.strings.StringList;
|
import fr.devinsy.strings.StringList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* The Class SimpleSecurityAgent.
|
||||||
*/
|
*/
|
||||||
public class SimpleSecurityAgent
|
public class SimpleSecurityAgent
|
||||||
{
|
{
|
||||||
|
@ -46,8 +46,13 @@ public class SimpleSecurityAgent
|
||||||
private int authenticationDuration;
|
private int authenticationDuration;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Instantiates a new simple security agent.
|
||||||
*/
|
*
|
||||||
|
* @param prefix
|
||||||
|
* the prefix
|
||||||
|
* @param secretKey
|
||||||
|
* the secret key
|
||||||
|
*/
|
||||||
public SimpleSecurityAgent(final String prefix, final String secretKey)
|
public SimpleSecurityAgent(final String prefix, final String secretKey)
|
||||||
{
|
{
|
||||||
this.userIdLabel = prefix + "." + USERID_LABEL;
|
this.userIdLabel = prefix + "." + USERID_LABEL;
|
||||||
|
@ -58,8 +63,12 @@ public class SimpleSecurityAgent
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Account id.
|
||||||
*/
|
*
|
||||||
|
* @param request
|
||||||
|
* the request
|
||||||
|
* @return the string
|
||||||
|
*/
|
||||||
public String accountId(final HttpServletRequest request)
|
public String accountId(final HttpServletRequest request)
|
||||||
{
|
{
|
||||||
String result;
|
String result;
|
||||||
|
@ -71,8 +80,12 @@ public class SimpleSecurityAgent
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Auth.
|
||||||
*/
|
*
|
||||||
|
* @param request
|
||||||
|
* the request
|
||||||
|
* @return the string
|
||||||
|
*/
|
||||||
public String auth(final HttpServletRequest request)
|
public String auth(final HttpServletRequest request)
|
||||||
{
|
{
|
||||||
String result;
|
String result;
|
||||||
|
@ -85,6 +98,10 @@ public class SimpleSecurityAgent
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method builds a key from keys and a secret key.
|
* This method builds a key from keys and a secret key.
|
||||||
|
*
|
||||||
|
* @param keys
|
||||||
|
* the keys
|
||||||
|
* @return the string
|
||||||
*/
|
*/
|
||||||
public String computeAuth(final String... keys)
|
public String computeAuth(final String... keys)
|
||||||
{
|
{
|
||||||
|
@ -113,9 +130,11 @@ public class SimpleSecurityAgent
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Digest with secret.
|
||||||
*
|
*
|
||||||
* @param source
|
* @param source
|
||||||
* @return
|
* the source
|
||||||
|
* @return the string
|
||||||
*/
|
*/
|
||||||
public String digestWithSecret(final String source)
|
public String digestWithSecret(final String source)
|
||||||
{
|
{
|
||||||
|
@ -136,8 +155,9 @@ public class SimpleSecurityAgent
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Gets the authentication duration.
|
||||||
*
|
*
|
||||||
* @return
|
* @return the authentication duration
|
||||||
*/
|
*/
|
||||||
public int getAuthenticationDuration()
|
public int getAuthenticationDuration()
|
||||||
{
|
{
|
||||||
|
@ -146,6 +166,12 @@ public class SimpleSecurityAgent
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check authentication and refresh it (reset countdown).
|
* Check authentication and refresh it (reset countdown).
|
||||||
|
*
|
||||||
|
* @param request
|
||||||
|
* the request
|
||||||
|
* @param response
|
||||||
|
* the response
|
||||||
|
* @return true, if is authenticated
|
||||||
*/
|
*/
|
||||||
public boolean isAuthenticated(final HttpServletRequest request, final HttpServletResponse response)
|
public boolean isAuthenticated(final HttpServletRequest request, final HttpServletResponse response)
|
||||||
{
|
{
|
||||||
|
@ -177,8 +203,13 @@ public class SimpleSecurityAgent
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Reset.
|
||||||
*/
|
*
|
||||||
|
* @param request
|
||||||
|
* the request
|
||||||
|
* @param response
|
||||||
|
* the response
|
||||||
|
*/
|
||||||
public void reset(final HttpServletRequest request, final HttpServletResponse response)
|
public void reset(final HttpServletRequest request, final HttpServletResponse response)
|
||||||
{
|
{
|
||||||
CookieHelper.reset(response, this.authLabel);
|
CookieHelper.reset(response, this.authLabel);
|
||||||
|
@ -187,8 +218,17 @@ public class SimpleSecurityAgent
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Sets the authenticated.
|
||||||
*/
|
*
|
||||||
|
* @param request
|
||||||
|
* the request
|
||||||
|
* @param response
|
||||||
|
* the response
|
||||||
|
* @param accountId
|
||||||
|
* the account id
|
||||||
|
* @param userId
|
||||||
|
* the user id
|
||||||
|
*/
|
||||||
public void setAuthenticated(final HttpServletRequest request, final HttpServletResponse response, final String accountId, final String userId)
|
public void setAuthenticated(final HttpServletRequest request, final HttpServletResponse response, final String accountId, final String userId)
|
||||||
{
|
{
|
||||||
// Refresh cookie.
|
// Refresh cookie.
|
||||||
|
@ -202,8 +242,10 @@ public class SimpleSecurityAgent
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Sets the authentication duration.
|
||||||
*
|
*
|
||||||
* @param duration
|
* @param duration
|
||||||
|
* the new authentication duration
|
||||||
*/
|
*/
|
||||||
public void setAuthenticationDuration(final int duration)
|
public void setAuthenticationDuration(final int duration)
|
||||||
{
|
{
|
||||||
|
@ -211,8 +253,12 @@ public class SimpleSecurityAgent
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* User id.
|
||||||
*/
|
*
|
||||||
|
* @param request
|
||||||
|
* the request
|
||||||
|
* @return the string
|
||||||
|
*/
|
||||||
public String userId(final HttpServletRequest request)
|
public String userId(final HttpServletRequest request)
|
||||||
{
|
{
|
||||||
String result;
|
String result;
|
||||||
|
@ -224,8 +270,12 @@ public class SimpleSecurityAgent
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Digest.
|
||||||
*/
|
*
|
||||||
|
* @param keys
|
||||||
|
* the keys
|
||||||
|
* @return the string
|
||||||
|
*/
|
||||||
public static String digest(final String... keys)
|
public static String digest(final String... keys)
|
||||||
{
|
{
|
||||||
String result;
|
String result;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/**
|
/**
|
||||||
* Copyright (C) 2006-2010, 2013-2016 Christian Pierre MOMON
|
* Copyright (C) 2006-2021 Christian Pierre MOMON
|
||||||
*
|
*
|
||||||
* This file is part of Kiss4web.
|
* This file is part of Kiss4web.
|
||||||
*
|
*
|
||||||
|
@ -21,48 +21,39 @@ package fr.devinsy.kiss4web.dispatcher;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
import javax.naming.ConfigurationException;
|
|
||||||
import javax.servlet.ServletException;
|
import javax.servlet.ServletException;
|
||||||
import javax.servlet.http.HttpServlet;
|
import javax.servlet.http.HttpServlet;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import fr.devinsy.kiss4web.EnvironmentInformation;
|
|
||||||
import fr.devinsy.kiss4web.dispatcher.hooks.BlankHook;
|
|
||||||
import fr.devinsy.kiss4web.dispatcher.hooks.FolderHook;
|
|
||||||
import fr.devinsy.kiss4web.dispatcher.hooks.Hook;
|
import fr.devinsy.kiss4web.dispatcher.hooks.Hook;
|
||||||
import fr.devinsy.kiss4web.dispatcher.hooks.HookRegister;
|
import fr.devinsy.kiss4web.dispatcher.hooks.HookRegister;
|
||||||
import fr.devinsy.kiss4web.dispatcher.hooks.LongURLHook;
|
import fr.devinsy.kiss4web.dispatcher.hooks.InitHook;
|
||||||
import fr.devinsy.kiss4web.dispatcher.hooks.RootHook;
|
|
||||||
import fr.devinsy.kiss4web.dispatcher.hooks.ShortURLHook;
|
|
||||||
import fr.devinsy.kiss4web.dispatcher.hooks.WebContentHook;
|
|
||||||
import fr.devinsy.kiss4web.dispatcher.hooks.WebInfHook;
|
|
||||||
import fr.devinsy.kiss4web.dispatcher.hooks.XHTMLHook;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* The Class KissDispatcher.
|
||||||
*
|
*
|
||||||
* According that URL is under UTF-8 format. Set Tomcat connector if needs
|
* According that URL is under UTF-8 format. Set Tomcat connector if needs
|
||||||
* (<connector … URIEncoding="UTF-8" … />).
|
* (<connector … URIEncoding="UTF-8" … />).
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
public class KissDispatcher extends HttpServlet
|
public class KissDispatcher extends HttpServlet
|
||||||
{
|
{
|
||||||
private static final long serialVersionUID = -3471226305721330069L;
|
private static final long serialVersionUID = -3471226305721330069L;
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(KissDispatcher.class);
|
||||||
private static Logger logger = LoggerFactory.getLogger(KissDispatcher.class);
|
|
||||||
|
|
||||||
public static final int DEFAULT_CACHE_AGE = 2 * 60 * 60;
|
public static final int DEFAULT_CACHE_AGE = 2 * 60 * 60;
|
||||||
private KissClassCache cache;
|
|
||||||
|
private static HookRegister hookRegister = new HookRegister("Init").register(new InitHook());
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Instantiates a new kiss dispatcher.
|
||||||
*/
|
*/
|
||||||
public KissDispatcher()
|
public KissDispatcher()
|
||||||
{
|
{
|
||||||
this.cache = new KissClassCache();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -144,19 +135,6 @@ public class KissDispatcher extends HttpServlet
|
||||||
*/
|
*/
|
||||||
// String urlPath = request.getPathInfo();
|
// String urlPath = request.getPathInfo();
|
||||||
|
|
||||||
HookRegister hookRegister = KissDispatcherFactory.instance().catchers();
|
|
||||||
if (hookRegister.hooks().isEmpty())
|
|
||||||
{
|
|
||||||
hookRegister.register(new BlankHook());
|
|
||||||
hookRegister.register(new RootHook());
|
|
||||||
hookRegister.register(new LongURLHook());
|
|
||||||
hookRegister.register(new FolderHook());
|
|
||||||
hookRegister.register(new ShortURLHook());
|
|
||||||
hookRegister.register(new XHTMLHook());
|
|
||||||
hookRegister.register(new WebContentHook());
|
|
||||||
hookRegister.register(new WebInfHook());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Search a matching catcher.
|
// Search a matching catcher.
|
||||||
Hook hook = hookRegister.getMatching(this.getServletContext(), request);
|
Hook hook = hookRegister.getMatching(this.getServletContext(), request);
|
||||||
if (hook == null)
|
if (hook == null)
|
||||||
|
@ -166,6 +144,7 @@ public class KissDispatcher extends HttpServlet
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
logger.info("Catch found for {}", hook.getClass().getSimpleName());
|
||||||
hook.process(this.getServletConfig(), this.getServletContext(), request, response);
|
hook.process(this.getServletConfig(), this.getServletContext(), request, response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -174,8 +153,8 @@ public class KissDispatcher extends HttpServlet
|
||||||
logger.debug("TIME: {}ms {}", endTime - startTime, request.getPathInfo());
|
logger.debug("TIME: {}ms {}", endTime - startTime, request.getPathInfo());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/* (non-Javadoc)
|
||||||
*
|
* @see javax.servlet.http.HttpServlet#doDelete(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void doDelete(final HttpServletRequest request, final HttpServletResponse response) throws IOException, ServletException
|
public void doDelete(final HttpServletRequest request, final HttpServletResponse response) throws IOException, ServletException
|
||||||
|
@ -183,17 +162,17 @@ public class KissDispatcher extends HttpServlet
|
||||||
dispatch(request, response);
|
dispatch(request, response);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/* (non-Javadoc)
|
||||||
*
|
* @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void doGet(final HttpServletRequest request, final HttpServletResponse response) throws IOException, ServletException
|
public void doGet(final HttpServletRequest request, final HttpServletResponse response) throws IOException, ServletException
|
||||||
{
|
{
|
||||||
dispatch(request, response);
|
dispatch(request, response);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/* (non-Javadoc)
|
||||||
*
|
* @see javax.servlet.http.HttpServlet#doPost(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void doPost(final HttpServletRequest request, final HttpServletResponse response) throws IOException, ServletException
|
public void doPost(final HttpServletRequest request, final HttpServletResponse response) throws IOException, ServletException
|
||||||
|
@ -201,8 +180,8 @@ public class KissDispatcher extends HttpServlet
|
||||||
dispatch(request, response);
|
dispatch(request, response);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/* (non-Javadoc)
|
||||||
*
|
* @see javax.servlet.http.HttpServlet#doPut(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void doPut(final HttpServletRequest request, final HttpServletResponse response) throws IOException, ServletException
|
public void doPut(final HttpServletRequest request, final HttpServletResponse response) throws IOException, ServletException
|
||||||
|
@ -210,56 +189,31 @@ public class KissDispatcher extends HttpServlet
|
||||||
dispatch(request, response);
|
dispatch(request, response);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/* (non-Javadoc)
|
||||||
*
|
* @see javax.servlet.GenericServlet#init()
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void init() throws ServletException
|
public void init() throws ServletException
|
||||||
{
|
{
|
||||||
super.init();
|
super.init();
|
||||||
|
|
||||||
// Set logger.
|
System.out.println("KissDispatcher INIT.");
|
||||||
String logFilePathname;
|
}
|
||||||
try
|
|
||||||
|
/**
|
||||||
|
* Sets the hook register.
|
||||||
|
*
|
||||||
|
* @param register
|
||||||
|
* the new hook register
|
||||||
|
*/
|
||||||
|
public static void setHookRegister(final HookRegister register)
|
||||||
|
{
|
||||||
|
if ((register != null) && (!register.isEmpty()))
|
||||||
{
|
{
|
||||||
new EnvironmentInformation().toString();
|
HookRegister target = new HookRegister(register.getName());
|
||||||
|
target.registerAll(register);
|
||||||
logFilePathname = new EnvironmentInformation().log4jFilePathname();
|
hookRegister = target;
|
||||||
}
|
KissDispatcherFactory.instance().clearCache();
|
||||||
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
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
System.out.println("Log configuration defined (" + logFilePathname + "), will use it.");
|
|
||||||
|
|
||||||
if (!logFilePathname.startsWith("/"))
|
|
||||||
{
|
|
||||||
logFilePathname = getServletContext().getRealPath("/") + logFilePathname;
|
|
||||||
System.out.println("Log configuration redefined (" + logFilePathname + "), will use it.");
|
|
||||||
}
|
|
||||||
|
|
||||||
org.apache.log4j.PropertyConfigurator.configure(getServletContext().getRealPath("/") + logFilePathname);
|
|
||||||
}
|
|
||||||
catch (Exception exception)
|
|
||||||
{
|
|
||||||
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.");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/**
|
/**
|
||||||
* Copyright (C) 2006-2010, 2013-2018 Christian Pierre MOMON
|
* Copyright (C) 2006-2021 Christian Pierre MOMON
|
||||||
*
|
*
|
||||||
* This file is part of Kiss4web.
|
* This file is part of Kiss4web.
|
||||||
*
|
*
|
||||||
|
@ -20,8 +20,6 @@ package fr.devinsy.kiss4web.dispatcher;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Iterator;
|
|
||||||
|
|
||||||
import javax.servlet.ServletConfig;
|
import javax.servlet.ServletConfig;
|
||||||
import javax.servlet.ServletException;
|
import javax.servlet.ServletException;
|
||||||
|
@ -29,22 +27,15 @@ import javax.servlet.http.HttpServlet;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import fr.devinsy.kiss4web.kernel.Kiss4web;
|
|
||||||
import fr.devinsy.kiss4web.kernel.KissModule;
|
|
||||||
import fr.devinsy.kiss4web.kernel.dispatcher.hooks.HookRegister;
|
|
||||||
import fr.devinsy.strings.StringList;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A factory for creating KissDispatcher objects.
|
* A factory for creating KissDispatcher objects.
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
public class KissDispatcherFactory extends HashMap<String, String>
|
public class KissDispatcherFactory
|
||||||
{
|
{
|
||||||
private static final long serialVersionUID = 8711189110156064068L;
|
|
||||||
|
|
||||||
private static Logger logger = LoggerFactory.getLogger(KissDispatcherFactory.class);
|
private static Logger logger = LoggerFactory.getLogger(KissDispatcherFactory.class);
|
||||||
|
|
||||||
private static class SingletonHolder
|
private static class SingletonHolder
|
||||||
|
@ -52,26 +43,19 @@ public class KissDispatcherFactory extends HashMap<String, String>
|
||||||
private static final KissDispatcherFactory instance = new KissDispatcherFactory();
|
private static final KissDispatcherFactory instance = new KissDispatcherFactory();
|
||||||
}
|
}
|
||||||
|
|
||||||
private KissClassCache cache;
|
private KissDispatcherCache cache;
|
||||||
private HookRegister catchers;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instantiates a new kiss dispatcher factory.
|
* Instantiates a new kiss dispatcher factory.
|
||||||
*/
|
*/
|
||||||
private KissDispatcherFactory()
|
private KissDispatcherFactory()
|
||||||
{
|
{
|
||||||
this.cache = new KissClassCache();
|
this.cache = new KissDispatcherCache();
|
||||||
this.catchers = new HookRegister();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public void clearCache()
|
||||||
* Catchers.
|
|
||||||
*
|
|
||||||
* @return the hook register
|
|
||||||
*/
|
|
||||||
public HookRegister catchers()
|
|
||||||
{
|
{
|
||||||
return this.catchers;
|
this.cache.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -90,29 +74,33 @@ public class KissDispatcherFactory extends HashMap<String, String>
|
||||||
* @throws ServletException
|
* @throws ServletException
|
||||||
* the servlet exception
|
* the servlet exception
|
||||||
*/
|
*/
|
||||||
public void dispatchToServlet(final ServletConfig servletConfig, final HttpServletRequest request, final HttpServletResponse response,
|
public void dispatchPathToServlet(final ServletConfig servletConfig, final HttpServletRequest request, final HttpServletResponse response,
|
||||||
final String urlPath) throws IOException, ServletException
|
final String urlPath) throws IOException, ServletException
|
||||||
{
|
{
|
||||||
// Get the servlet.
|
// Get the servlet.
|
||||||
HttpServlet servlet;
|
HttpServlet servlet = this.cache.get(urlPath);
|
||||||
String className = this.cache.get(urlPath);
|
if (servlet == null)
|
||||||
if (className == null)
|
|
||||||
{
|
{
|
||||||
className = translateToClassName(urlPath);
|
String className = translateToClassName(urlPath);
|
||||||
|
|
||||||
logger.info("className=[" + className + "]");
|
logger.info("className=[" + className + "]");
|
||||||
|
|
||||||
// servlet = instanciateServletSearching("/website/" + className);
|
servlet = KissDispatcherUtils.instanciateServlet("website." + className);
|
||||||
servlet = KissDispatcherUtils.instanciateServlet("/website/" + className);
|
|
||||||
|
if (servlet == null)
|
||||||
|
{
|
||||||
|
logger.info("Trying with Page suffix.");
|
||||||
|
servlet = KissDispatcherUtils.instanciateServlet("website." + className.replaceAll("Xhtml$", "Page"));
|
||||||
|
}
|
||||||
|
|
||||||
if (servlet != null)
|
if (servlet != null)
|
||||||
{
|
{
|
||||||
this.cache.put(urlPath, className);
|
servlet.init(servletConfig);
|
||||||
|
this.cache.put(urlPath, servlet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
servlet = KissDispatcherUtils.instanciateServlet(className);
|
logger.info("Class cache MATCHED.");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Serve the servlet.
|
// Serve the servlet.
|
||||||
|
@ -129,57 +117,10 @@ public class KissDispatcherFactory extends HashMap<String, String>
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
servlet.init(servletConfig);
|
|
||||||
servlet.service(request, response);
|
servlet.service(request, response);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Instanciate servlet searching.
|
|
||||||
*
|
|
||||||
* @param className
|
|
||||||
* the class name
|
|
||||||
* @return the http servlet
|
|
||||||
*/
|
|
||||||
public HttpServlet instanciateServletSearching(final String className)
|
|
||||||
{
|
|
||||||
HttpServlet result;
|
|
||||||
|
|
||||||
if (className == null)
|
|
||||||
{
|
|
||||||
result = null;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
boolean ended = false;
|
|
||||||
Iterator<KissModule> iterator = Kiss4web.instance().modules().iterator();
|
|
||||||
result = null;
|
|
||||||
while (!ended)
|
|
||||||
{
|
|
||||||
if (iterator.hasNext())
|
|
||||||
{
|
|
||||||
KissModule module = iterator.next();
|
|
||||||
|
|
||||||
String currentClassName = KissDispatcherUtils.concatenatePackage(module.websiteRootPackage(), className);
|
|
||||||
HttpServlet servlet = KissDispatcherUtils.instanciateServlet(currentClassName);
|
|
||||||
if (servlet != null)
|
|
||||||
{
|
|
||||||
ended = true;
|
|
||||||
result = servlet;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ended = true;
|
|
||||||
result = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instance.
|
* Instance.
|
||||||
*
|
*
|
||||||
|
@ -194,10 +135,11 @@ public class KissDispatcherFactory extends HashMap<String, String>
|
||||||
* Translate to class name.
|
* Translate to class name.
|
||||||
*
|
*
|
||||||
* <pre>
|
* <pre>
|
||||||
* "/" => "Index_xhtml"
|
* "/" => "IndexXhtml"
|
||||||
* "/good/" => "good.Index_xhtml"
|
* "/good/" => "good.IndexXhtml"
|
||||||
* "/good/morning.xhtml" => "good.Morning_xhtml"
|
* "/good/morning.xhtml" => "good.MorningXhtml"
|
||||||
* "/good/morning_girl.xhtml" => "good.Morning_girl_xhtml"
|
* "/good/morning_girl.xhtml" => "good.MorningGirlXhtml"
|
||||||
|
* "/good/morning-girl.xhtml" => "good.MorningGirlXhtml"
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
* @param urlPath
|
* @param urlPath
|
||||||
|
@ -214,48 +156,78 @@ public class KissDispatcherFactory extends HashMap<String, String>
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
String[] tokens = urlPath.split("/");
|
if (urlPath.length() == 1)
|
||||||
if (tokens.length == 1)
|
|
||||||
{
|
{
|
||||||
result = "Index_xhtml";
|
result = "IndexXhtml";
|
||||||
}
|
}
|
||||||
else if (urlPath.endsWith("/"))
|
else if (urlPath.endsWith("/"))
|
||||||
{
|
{
|
||||||
StringList buffer = new StringList();
|
StringBuffer buffer = new StringBuffer(urlPath.length() + 50);
|
||||||
|
for (int index = 1; index < urlPath.length(); index++)
|
||||||
// Note: as pathInfo starts always with a '/', the first
|
|
||||||
// good token index is 1.
|
|
||||||
for (int tokenCounter = 1; tokenCounter <= tokens.length - 1; tokenCounter++)
|
|
||||||
{
|
{
|
||||||
buffer.append(tokens[tokenCounter]);
|
char letter = urlPath.charAt(index);
|
||||||
buffer.append('.');
|
|
||||||
}
|
|
||||||
|
|
||||||
// String lastToken = tokens[tokens.length - 1];
|
if (letter == '/')
|
||||||
// buffer.append(StringUtils.capitalize(lastToken)).append("_xhtml");
|
{
|
||||||
buffer.append("Index_xhtml");
|
buffer.append('.');
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
buffer.append(letter);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
buffer.append(".IndexXhtml");
|
||||||
|
|
||||||
result = buffer.toString();
|
result = buffer.toString();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
StringList buffer = new StringList();
|
int lastToken = urlPath.lastIndexOf('/');
|
||||||
|
|
||||||
// Note: as pathInfo starts always with a '/', the first
|
StringBuffer buffer = new StringBuffer(urlPath.length());
|
||||||
// good token index is 1.
|
for (int index = 1; index <= lastToken; index++)
|
||||||
for (int tokenCounter = 1; tokenCounter < tokens.length - 1; tokenCounter++)
|
|
||||||
{
|
{
|
||||||
buffer.append(tokens[tokenCounter]);
|
char letter = urlPath.charAt(index);
|
||||||
buffer.append('.');
|
|
||||||
|
if (letter == '/')
|
||||||
|
{
|
||||||
|
buffer.append('.');
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
buffer.append(letter);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String lastToken = tokens[tokens.length - 1];
|
boolean capitalizedNext = true;
|
||||||
buffer.append(StringUtils.capitalize(lastToken).replace('.', '_'));
|
for (int index = lastToken + 1; index < urlPath.length(); index++)
|
||||||
|
{
|
||||||
|
char letter = urlPath.charAt(index);
|
||||||
|
|
||||||
|
if ((letter == '_') || (letter == '-') || (letter == '.'))
|
||||||
|
{
|
||||||
|
capitalizedNext = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (capitalizedNext)
|
||||||
|
{
|
||||||
|
buffer.append(Character.toUpperCase(letter));
|
||||||
|
capitalizedNext = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
buffer.append(letter);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
result = buffer.toString();
|
result = buffer.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logger.info(urlPath + " -> " + result);
|
||||||
|
|
||||||
//
|
//
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/**
|
/**
|
||||||
* Copyright (C) 2006-2010, 2013-2016 Christian Pierre MOMON
|
* Copyright (C) 2006-2021 Christian Pierre MOMON
|
||||||
*
|
*
|
||||||
* This file is part of Kiss4web.
|
* This file is part of Kiss4web.
|
||||||
*
|
*
|
||||||
|
@ -22,6 +22,7 @@ import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Enumeration;
|
import java.util.Enumeration;
|
||||||
|
|
||||||
|
@ -35,24 +36,28 @@ import javax.servlet.http.HttpServletResponse;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import fr.devinsy.kiss4web.catchers.ShortURLRewriter;
|
import fr.devinsy.kiss4web.dispatcher.hooks.ShortURLRewriter;
|
||||||
import fr.devinsy.util.strings.StringList;
|
import fr.devinsy.strings.StringList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* The Class KissDispatcherUtils.
|
||||||
*/
|
*/
|
||||||
public class KissDispatcherUtils
|
public class KissDispatcherUtils
|
||||||
{
|
{
|
||||||
|
private static Logger logger = LoggerFactory.getLogger(KissDispatcherUtils.class);
|
||||||
|
|
||||||
public enum ContentDispositionType
|
public enum ContentDispositionType
|
||||||
{
|
{
|
||||||
ATTACHMENT,
|
ATTACHMENT,
|
||||||
INLINE
|
INLINE
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Logger logger = LoggerFactory.getLogger(KissDispatcherUtils.class);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Builds the class name.
|
||||||
*
|
*
|
||||||
|
* @param pathInfo
|
||||||
|
* the path info
|
||||||
|
* @return the string
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public static String buildClassName(final String pathInfo)
|
public static String buildClassName(final String pathInfo)
|
||||||
|
@ -92,7 +97,13 @@ public class KissDispatcherUtils
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Concatenate package.
|
||||||
*
|
*
|
||||||
|
* @param path
|
||||||
|
* the path
|
||||||
|
* @param className
|
||||||
|
* the class name
|
||||||
|
* @return the string
|
||||||
*/
|
*/
|
||||||
public static String concatenatePackage(final String path, final String className)
|
public static String concatenatePackage(final String path, final String className)
|
||||||
{
|
{
|
||||||
|
@ -116,13 +127,23 @@ public class KissDispatcherUtils
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Dispatch to servlet.
|
||||||
*
|
*
|
||||||
|
* @param servletConfig
|
||||||
|
* the servlet config
|
||||||
|
* @param request
|
||||||
|
* the request
|
||||||
|
* @param response
|
||||||
|
* the response
|
||||||
* @param className
|
* @param className
|
||||||
|
* the class name
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
|
* Signals that an I/O exception has occurred.
|
||||||
* @throws ServletException
|
* @throws ServletException
|
||||||
|
* the servlet exception
|
||||||
*/
|
*/
|
||||||
public static void dispatchToServlet(final ServletConfig servletConfig, final HttpServletRequest request, final HttpServletResponse response, final String className) throws IOException,
|
public static void dispatchToServlet(final ServletConfig servletConfig, final HttpServletRequest request, final HttpServletResponse response,
|
||||||
ServletException
|
final String className) throws IOException, ServletException
|
||||||
{
|
{
|
||||||
HttpServlet servlet = instanciateServlet(className);
|
HttpServlet servlet = instanciateServlet(className);
|
||||||
|
|
||||||
|
@ -147,7 +168,11 @@ public class KissDispatcherUtils
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Format class name.
|
||||||
*
|
*
|
||||||
|
* @param name
|
||||||
|
* the name
|
||||||
|
* @return the string
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public static String formatClassName(final String name)
|
public static String formatClassName(final String name)
|
||||||
|
@ -177,43 +202,51 @@ public class KissDispatcherUtils
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Instanciate servlet.
|
||||||
*
|
*
|
||||||
|
* @param className
|
||||||
|
* the class name
|
||||||
|
* @return the http servlet or null if no one found.
|
||||||
*/
|
*/
|
||||||
public static HttpServlet instanciateServlet(final String className)
|
public static HttpServlet instanciateServlet(final String classPathname)
|
||||||
{
|
{
|
||||||
HttpServlet result;
|
HttpServlet result;
|
||||||
|
|
||||||
Class<HttpServlet> servletClass = null;
|
Class<HttpServlet> servletClass = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
servletClass = (Class<HttpServlet>) Class.forName(className);
|
servletClass = (Class<HttpServlet>) Class.forName(classPathname);
|
||||||
}
|
}
|
||||||
catch (java.lang.ClassNotFoundException exception)
|
catch (java.lang.ClassNotFoundException exception)
|
||||||
{
|
{
|
||||||
result = null;
|
result = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.info("class=" + servletClass);
|
|
||||||
|
|
||||||
if (servletClass == null)
|
if (servletClass == null)
|
||||||
{
|
{
|
||||||
result = null;
|
result = null;
|
||||||
logger.error("unknown page: (" + className + ")");
|
logger.error("unknown page: [{}]", classPathname);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
result = servletClass.newInstance();
|
// result = servletClass.newInstance();
|
||||||
|
result = servletClass.getConstructor().newInstance();
|
||||||
}
|
}
|
||||||
catch (java.lang.InstantiationException exception)
|
catch (java.lang.InstantiationException exception)
|
||||||
{
|
{
|
||||||
logger.error("Can't instanciate servlet (" + className + ")", exception);
|
logger.error("Can't instanciate servlet (" + classPathname + ")", exception);
|
||||||
result = null;
|
result = null;
|
||||||
}
|
}
|
||||||
catch (java.lang.IllegalAccessException exception)
|
catch (java.lang.IllegalAccessException exception)
|
||||||
{
|
{
|
||||||
logger.error("(2) Can't instanciate servlet (" + className + ")", exception);
|
logger.error("(2) Can't instanciate servlet (" + classPathname + ")", exception);
|
||||||
|
result = null;
|
||||||
|
}
|
||||||
|
catch (IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException exception)
|
||||||
|
{
|
||||||
|
logger.error("(3) Can't instanciate servlet (" + classPathname + ")", exception);
|
||||||
result = null;
|
result = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -236,6 +269,9 @@ public class KissDispatcherUtils
|
||||||
* will be decoded in the class called later).
|
* will be decoded in the class called later).
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
|
* @param pathInfo
|
||||||
|
* the path info
|
||||||
|
* @return the string
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public static String pathInfoToClassName(final String pathInfo)
|
public static String pathInfoToClassName(final String pathInfo)
|
||||||
|
@ -287,7 +323,8 @@ public class KissDispatcherUtils
|
||||||
String lastToken = tokens[tokens.length - 1];
|
String lastToken = tokens[tokens.length - 1];
|
||||||
if (pathInfo.endsWith("/"))
|
if (pathInfo.endsWith("/"))
|
||||||
{
|
{
|
||||||
name.append(lastToken).append(".").append(lastToken.substring(0, 1).toUpperCase()).append(lastToken.substring(1)).append("_xhtml");
|
name.append(lastToken).append(".").append(lastToken.substring(0, 1).toUpperCase()).append(lastToken.substring(1))
|
||||||
|
.append("_xhtml");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -314,7 +351,13 @@ public class KissDispatcherUtils
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Path info to class name.
|
||||||
*
|
*
|
||||||
|
* @param pathInfo
|
||||||
|
* the path info
|
||||||
|
* @param prefix
|
||||||
|
* the prefix
|
||||||
|
* @return the string
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public static String pathInfoToClassName(final String pathInfo, final String prefix)
|
public static String pathInfoToClassName(final String pathInfo, final String prefix)
|
||||||
|
@ -341,7 +384,16 @@ public class KissDispatcherUtils
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Return attachment file.
|
||||||
*
|
*
|
||||||
|
* @param response
|
||||||
|
* the response
|
||||||
|
* @param file
|
||||||
|
* the file
|
||||||
|
* @param mimeType
|
||||||
|
* the mime type
|
||||||
|
* @throws IOException
|
||||||
|
* Signals that an I/O exception has occurred.
|
||||||
*/
|
*/
|
||||||
public static void returnAttachmentFile(final HttpServletResponse response, final File file, final String mimeType) throws IOException
|
public static void returnAttachmentFile(final HttpServletResponse response, final File file, final String mimeType) throws IOException
|
||||||
{
|
{
|
||||||
|
@ -349,9 +401,21 @@ public class KissDispatcherUtils
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Return file.
|
||||||
*
|
*
|
||||||
|
* @param response
|
||||||
|
* the response
|
||||||
|
* @param file
|
||||||
|
* the file
|
||||||
|
* @param mimeType
|
||||||
|
* the mime type
|
||||||
|
* @param contentDisposition
|
||||||
|
* the content disposition
|
||||||
|
* @throws IOException
|
||||||
|
* Signals that an I/O exception has occurred.
|
||||||
*/
|
*/
|
||||||
public static void returnFile(final HttpServletResponse response, final File file, final String mimeType, final ContentDispositionType contentDisposition) throws IOException
|
public static void returnFile(final HttpServletResponse response, final File file, final String mimeType,
|
||||||
|
final ContentDispositionType contentDisposition) throws IOException
|
||||||
{
|
{
|
||||||
|
|
||||||
if ((file == null) || (!file.exists()))
|
if ((file == null) || (!file.exists()))
|
||||||
|
@ -428,10 +492,25 @@ public class KissDispatcherUtils
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Return file.
|
||||||
*
|
*
|
||||||
|
* @param response
|
||||||
|
* the response
|
||||||
|
* @param fileName
|
||||||
|
* the file name
|
||||||
|
* @param data
|
||||||
|
* the data
|
||||||
|
* @param mimeType
|
||||||
|
* the mime type
|
||||||
|
* @param contentDisposition
|
||||||
|
* the content disposition
|
||||||
|
* @param cacheAge
|
||||||
|
* the cache age
|
||||||
|
* @throws IOException
|
||||||
|
* Signals that an I/O exception has occurred.
|
||||||
*/
|
*/
|
||||||
public static void returnFile(final HttpServletResponse response, final String fileName, final byte[] data, final String mimeType, final ContentDispositionType contentDisposition,
|
public static void returnFile(final HttpServletResponse response, final String fileName, final byte[] data, final String mimeType,
|
||||||
final int cacheAge) throws IOException
|
final ContentDispositionType contentDisposition, final int cacheAge) throws IOException
|
||||||
{
|
{
|
||||||
|
|
||||||
if (data == null)
|
if (data == null)
|
||||||
|
@ -491,7 +570,16 @@ public class KissDispatcherUtils
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Return inline file.
|
||||||
*
|
*
|
||||||
|
* @param response
|
||||||
|
* the response
|
||||||
|
* @param file
|
||||||
|
* the file
|
||||||
|
* @param mimeType
|
||||||
|
* the mime type
|
||||||
|
* @throws IOException
|
||||||
|
* Signals that an I/O exception has occurred.
|
||||||
*/
|
*/
|
||||||
public static void returnInlineFile(final HttpServletResponse response, final File file, final String mimeType) throws IOException
|
public static void returnInlineFile(final HttpServletResponse response, final File file, final String mimeType) throws IOException
|
||||||
{
|
{
|
||||||
|
@ -499,9 +587,11 @@ public class KissDispatcherUtils
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Show parameters.
|
||||||
*
|
*
|
||||||
* @param request
|
* @param request
|
||||||
* @return
|
* the request
|
||||||
|
* @return the string
|
||||||
*/
|
*/
|
||||||
public static String showParameters(final HttpServletRequest request)
|
public static String showParameters(final HttpServletRequest request)
|
||||||
{
|
{
|
||||||
|
|
|
@ -31,7 +31,6 @@ import javax.servlet.http.HttpServletResponse;
|
||||||
*/
|
*/
|
||||||
public interface Hook
|
public interface Hook
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if is terminal.
|
* Checks if is terminal.
|
||||||
*
|
*
|
||||||
|
|
|
@ -18,9 +18,7 @@
|
||||||
*/
|
*/
|
||||||
package fr.devinsy.kiss4web.dispatcher.hooks;
|
package fr.devinsy.kiss4web.dispatcher.hooks;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import javax.servlet.ServletContext;
|
import javax.servlet.ServletContext;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
@ -30,16 +28,28 @@ import javax.servlet.http.HttpServletRequest;
|
||||||
*/
|
*/
|
||||||
public class HookRegister
|
public class HookRegister
|
||||||
{
|
{
|
||||||
List<Hook> hooks;
|
private String name;
|
||||||
|
private Hooks hooks;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instantiates a new hook register.
|
* Instantiates a new hook register.
|
||||||
*/
|
*/
|
||||||
public HookRegister()
|
public HookRegister(final String name)
|
||||||
{
|
{
|
||||||
super();
|
super();
|
||||||
|
|
||||||
this.hooks = new ArrayList<Hook>();
|
this.name = name;
|
||||||
|
this.hooks = new Hooks();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hooks.
|
||||||
|
*
|
||||||
|
* @return the list
|
||||||
|
*/
|
||||||
|
public Hooks getHooks()
|
||||||
|
{
|
||||||
|
return this.hooks;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -81,14 +91,24 @@ public class HookRegister
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public String getName()
|
||||||
* Hooks.
|
|
||||||
*
|
|
||||||
* @return the list
|
|
||||||
*/
|
|
||||||
public List<Hook> hooks()
|
|
||||||
{
|
{
|
||||||
return this.hooks;
|
return this.name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if is empty.
|
||||||
|
*
|
||||||
|
* @return true, if is empty
|
||||||
|
*/
|
||||||
|
public boolean isEmpty()
|
||||||
|
{
|
||||||
|
boolean result;
|
||||||
|
|
||||||
|
result = this.hooks.isEmpty();
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -97,8 +117,20 @@ public class HookRegister
|
||||||
* @param hook
|
* @param hook
|
||||||
* the hook
|
* the hook
|
||||||
*/
|
*/
|
||||||
public void register(final Hook hook)
|
public HookRegister register(final Hook hook)
|
||||||
{
|
{
|
||||||
|
HookRegister result;
|
||||||
|
|
||||||
this.hooks.add(hook);
|
this.hooks.add(hook);
|
||||||
|
|
||||||
|
result = this;
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void registerAll(final HookRegister register)
|
||||||
|
{
|
||||||
|
this.hooks.addAll(register.getHooks());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,7 @@ import javax.servlet.http.HttpServletResponse;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import fr.devinsy.kiss4web.dispatcher.KissDispatcherUtils;
|
import fr.devinsy.kiss4web.dispatcher.KissDispatcherFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Class LongURLHook.
|
* The Class LongURLHook.
|
||||||
|
@ -75,6 +75,6 @@ public class LongURLHook extends HookCore
|
||||||
|
|
||||||
String rewritedURLPath = LongURLRewriter.unrewrite(urlPath);
|
String rewritedURLPath = LongURLRewriter.unrewrite(urlPath);
|
||||||
|
|
||||||
KissDispatcherUtils.dispatchToServlet(servletConfig, request, response, rewritedURLPath);
|
KissDispatcherFactory.instance().dispatchPathToServlet(servletConfig, request, response, rewritedURLPath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,7 @@ import javax.servlet.http.HttpServletRequest;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import fr.devinsy.util.strings.StringList;
|
import fr.devinsy.strings.StringList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Class LongURLRewriter.
|
* The Class LongURLRewriter.
|
||||||
|
|
|
@ -29,7 +29,7 @@ import javax.servlet.http.HttpServletResponse;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import fr.devinsy.kiss4web.dispatcher.KissDispatcherUtils;
|
import fr.devinsy.kiss4web.dispatcher.KissDispatcherFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Class RootHook.
|
* The Class RootHook.
|
||||||
|
@ -78,8 +78,8 @@ public class RootHook extends HookCore
|
||||||
{
|
{
|
||||||
logger.debug("Doing catch.");
|
logger.debug("Doing catch.");
|
||||||
|
|
||||||
String className = "index.xhtml";
|
String classPath = "index.xhtml";
|
||||||
|
|
||||||
KissDispatcherUtils.dispatchToServlet(servletConfig, request, response, className);
|
KissDispatcherFactory.instance().dispatchPathToServlet(servletConfig, request, response, classPath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,7 @@ import javax.servlet.http.HttpServletResponse;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import fr.devinsy.kiss4web.dispatcher.KissDispatcherUtils;
|
import fr.devinsy.kiss4web.dispatcher.KissDispatcherFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Class ShortURLHook.
|
* The Class ShortURLHook.
|
||||||
|
@ -72,9 +72,12 @@ public class ShortURLHook extends HookCore
|
||||||
logger.debug("Doing catch.");
|
logger.debug("Doing catch.");
|
||||||
|
|
||||||
String urlPath = request.getPathInfo();
|
String urlPath = request.getPathInfo();
|
||||||
|
|
||||||
String rewritedURLPath = ShortURLRewriter.unrewrite(urlPath);
|
String rewritedURLPath = ShortURLRewriter.unrewrite(urlPath);
|
||||||
|
|
||||||
KissDispatcherUtils.dispatchToServlet(servletConfig, request, response, rewritedURLPath);
|
logger.info("rewritedURLPath={}", rewritedURLPath);
|
||||||
|
|
||||||
|
KissDispatcherFactory.instance().dispatchPathToServlet(servletConfig, request, response, rewritedURLPath);
|
||||||
|
// KissDispatcherFactory.instance().dispatchPathToServlet(servletConfig,
|
||||||
|
// request, response, urlPath, rewritedURLPath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,7 @@ import javax.servlet.http.HttpServletRequest;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import fr.devinsy.util.strings.StringList;
|
import fr.devinsy.strings.StringList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Class ShortURLRewriter.
|
* The Class ShortURLRewriter.
|
||||||
|
@ -92,7 +92,7 @@ public class ShortURLRewriter
|
||||||
*
|
*
|
||||||
* <pre>
|
* <pre>
|
||||||
* "/good/article.xhtm?id=123&class=today&title=story's about me"
|
* "/good/article.xhtm?id=123&class=today&title=story's about me"
|
||||||
* => rewriteShorturl("/good/article", "xhtml", "123", "Story's aboute me");
|
* => rewriteShorturl("/good/article", "xhtml", "123", "Story's about me");
|
||||||
* => "/good/article-123-today-story-s-about-me.xhtml"
|
* => "/good/article-123-today-story-s-about-me.xhtml"
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
|
|
|
@ -55,6 +55,7 @@ public class WebContentHook extends HookCore
|
||||||
{
|
{
|
||||||
boolean result;
|
boolean result;
|
||||||
|
|
||||||
|
logger.info("Check for {}", servletContext.getRealPath("/") + request.getPathInfo());
|
||||||
if (new File(servletContext.getRealPath("/") + request.getPathInfo()).exists())
|
if (new File(servletContext.getRealPath("/") + request.getPathInfo()).exists())
|
||||||
{
|
{
|
||||||
result = true;
|
result = true;
|
||||||
|
|
|
@ -55,6 +55,7 @@ public class WebInfHook extends HookCore
|
||||||
{
|
{
|
||||||
boolean result;
|
boolean result;
|
||||||
|
|
||||||
|
logger.info("Check for {}", servletContext.getRealPath("/") + "WEB-INF/classes/website" + request.getPathInfo());
|
||||||
if (new File(servletContext.getRealPath("/") + "WEB-INF/classes/website" + request.getPathInfo()).exists())
|
if (new File(servletContext.getRealPath("/") + "WEB-INF/classes/website" + request.getPathInfo()).exists())
|
||||||
{
|
{
|
||||||
result = true;
|
result = true;
|
||||||
|
|
|
@ -29,7 +29,7 @@ import javax.servlet.http.HttpServletResponse;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import fr.devinsy.kiss4web.dispatcher.KissDispatcherUtils;
|
import fr.devinsy.kiss4web.dispatcher.KissDispatcherFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Class XHTMLHook.
|
* The Class XHTMLHook.
|
||||||
|
@ -80,6 +80,6 @@ public class XHTMLHook extends HookCore
|
||||||
|
|
||||||
String urlPath = request.getPathInfo();
|
String urlPath = request.getPathInfo();
|
||||||
|
|
||||||
KissDispatcherUtils.dispatchToServlet(servletConfig, request, response, urlPath);
|
KissDispatcherFactory.instance().dispatchPathToServlet(servletConfig, request, response, urlPath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue