Improved Hooks.

This commit is contained in:
Christian P. MOMON 2023-11-27 23:34:07 +01:00
parent eeba80d4b2
commit bac5b466b3
13 changed files with 115 additions and 128 deletions

View file

@ -26,6 +26,5 @@
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry kind="lib" path="lib/devinsy-strings-0.17.0.jar" sourcepath="lib/devinsy-strings-0.17.0-sources.zip"/> <classpathentry kind="lib" path="lib/devinsy-strings-0.17.0.jar" sourcepath="lib/devinsy-strings-0.17.0-sources.zip"/>
<classpathentry kind="lib" path="lib/xidyn-1.17.0.jar" sourcepath="lib/xidyn-1.17.0-sources.zip"/>
<classpathentry kind="output" path="bin"/> <classpathentry kind="output" path="bin"/>
</classpath> </classpath>

View file

@ -15,6 +15,7 @@ org.eclipse.jdt.core.compiler.release=enabled
org.eclipse.jdt.core.compiler.source=17 org.eclipse.jdt.core.compiler.source=17
org.eclipse.jdt.core.formatter.align_assignment_statements_on_columns=false org.eclipse.jdt.core.formatter.align_assignment_statements_on_columns=false
org.eclipse.jdt.core.formatter.align_fields_grouping_blank_lines=2147483647 org.eclipse.jdt.core.formatter.align_fields_grouping_blank_lines=2147483647
org.eclipse.jdt.core.formatter.align_selector_in_method_invocation_on_expression_first_line=false
org.eclipse.jdt.core.formatter.align_type_members_on_columns=false org.eclipse.jdt.core.formatter.align_type_members_on_columns=false
org.eclipse.jdt.core.formatter.align_variable_declarations_on_columns=false org.eclipse.jdt.core.formatter.align_variable_declarations_on_columns=false
org.eclipse.jdt.core.formatter.align_with_spaces=false org.eclipse.jdt.core.formatter.align_with_spaces=false
@ -42,6 +43,8 @@ org.eclipse.jdt.core.formatter.alignment_for_conditional_expression_chain=0
org.eclipse.jdt.core.formatter.alignment_for_enum_constants=49 org.eclipse.jdt.core.formatter.alignment_for_enum_constants=49
org.eclipse.jdt.core.formatter.alignment_for_expressions_in_array_initializer=16 org.eclipse.jdt.core.formatter.alignment_for_expressions_in_array_initializer=16
org.eclipse.jdt.core.formatter.alignment_for_expressions_in_for_loop_header=0 org.eclipse.jdt.core.formatter.alignment_for_expressions_in_for_loop_header=0
org.eclipse.jdt.core.formatter.alignment_for_expressions_in_switch_case_with_arrow=0
org.eclipse.jdt.core.formatter.alignment_for_expressions_in_switch_case_with_colon=0
org.eclipse.jdt.core.formatter.alignment_for_logical_operator=16 org.eclipse.jdt.core.formatter.alignment_for_logical_operator=16
org.eclipse.jdt.core.formatter.alignment_for_method_declaration=0 org.eclipse.jdt.core.formatter.alignment_for_method_declaration=0
org.eclipse.jdt.core.formatter.alignment_for_module_statements=16 org.eclipse.jdt.core.formatter.alignment_for_module_statements=16
@ -50,6 +53,7 @@ org.eclipse.jdt.core.formatter.alignment_for_multiplicative_operator=16
org.eclipse.jdt.core.formatter.alignment_for_parameterized_type_references=0 org.eclipse.jdt.core.formatter.alignment_for_parameterized_type_references=0
org.eclipse.jdt.core.formatter.alignment_for_parameters_in_constructor_declaration=16 org.eclipse.jdt.core.formatter.alignment_for_parameters_in_constructor_declaration=16
org.eclipse.jdt.core.formatter.alignment_for_parameters_in_method_declaration=16 org.eclipse.jdt.core.formatter.alignment_for_parameters_in_method_declaration=16
org.eclipse.jdt.core.formatter.alignment_for_permitted_types_in_type_declaration=16
org.eclipse.jdt.core.formatter.alignment_for_record_components=16 org.eclipse.jdt.core.formatter.alignment_for_record_components=16
org.eclipse.jdt.core.formatter.alignment_for_relational_operator=0 org.eclipse.jdt.core.formatter.alignment_for_relational_operator=0
org.eclipse.jdt.core.formatter.alignment_for_resources_in_try=80 org.eclipse.jdt.core.formatter.alignment_for_resources_in_try=80
@ -60,6 +64,7 @@ org.eclipse.jdt.core.formatter.alignment_for_superclass_in_type_declaration=16
org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_enum_declaration=16 org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_enum_declaration=16
org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_record_declaration=16 org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_record_declaration=16
org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_type_declaration=16 org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_type_declaration=16
org.eclipse.jdt.core.formatter.alignment_for_switch_case_with_arrow=0
org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_constructor_declaration=16 org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_constructor_declaration=16
org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_method_declaration=16 org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_method_declaration=16
org.eclipse.jdt.core.formatter.alignment_for_type_annotations=0 org.eclipse.jdt.core.formatter.alignment_for_type_annotations=0
@ -111,6 +116,7 @@ org.eclipse.jdt.core.formatter.comment.indent_tag_description=false
org.eclipse.jdt.core.formatter.comment.insert_new_line_before_root_tags=insert org.eclipse.jdt.core.formatter.comment.insert_new_line_before_root_tags=insert
org.eclipse.jdt.core.formatter.comment.insert_new_line_between_different_tags=do not insert org.eclipse.jdt.core.formatter.comment.insert_new_line_between_different_tags=do not insert
org.eclipse.jdt.core.formatter.comment.insert_new_line_for_parameter=insert org.eclipse.jdt.core.formatter.comment.insert_new_line_for_parameter=insert
org.eclipse.jdt.core.formatter.comment.javadoc_do_not_separate_block_tags=false
org.eclipse.jdt.core.formatter.comment.line_length=80 org.eclipse.jdt.core.formatter.comment.line_length=80
org.eclipse.jdt.core.formatter.comment.new_lines_at_block_boundaries=true org.eclipse.jdt.core.formatter.comment.new_lines_at_block_boundaries=true
org.eclipse.jdt.core.formatter.comment.new_lines_at_javadoc_boundaries=true org.eclipse.jdt.core.formatter.comment.new_lines_at_javadoc_boundaries=true
@ -190,6 +196,7 @@ org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_invocation_arg
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_field_declarations=insert org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_field_declarations=insert
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_local_declarations=insert org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_local_declarations=insert
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_parameterized_type_reference=insert org.eclipse.jdt.core.formatter.insert_space_after_comma_in_parameterized_type_reference=insert
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_permitted_types=insert
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_record_components=insert org.eclipse.jdt.core.formatter.insert_space_after_comma_in_record_components=insert
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_superinterfaces=insert org.eclipse.jdt.core.formatter.insert_space_after_comma_in_superinterfaces=insert
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_switch_case_expressions=insert org.eclipse.jdt.core.formatter.insert_space_after_comma_in_switch_case_expressions=insert
@ -281,6 +288,7 @@ org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_invocation_ar
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_field_declarations=do not insert org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_field_declarations=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_local_declarations=do not insert org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_local_declarations=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_parameterized_type_reference=do not insert org.eclipse.jdt.core.formatter.insert_space_before_comma_in_parameterized_type_reference=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_permitted_types=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_record_components=do not insert org.eclipse.jdt.core.formatter.insert_space_before_comma_in_record_components=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_superinterfaces=do not insert org.eclipse.jdt.core.formatter.insert_space_before_comma_in_superinterfaces=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_switch_case_expressions=do not insert org.eclipse.jdt.core.formatter.insert_space_before_comma_in_switch_case_expressions=do not insert
@ -364,6 +372,8 @@ org.eclipse.jdt.core.formatter.keep_simple_do_while_body_on_same_line=false
org.eclipse.jdt.core.formatter.keep_simple_for_body_on_same_line=false org.eclipse.jdt.core.formatter.keep_simple_for_body_on_same_line=false
org.eclipse.jdt.core.formatter.keep_simple_getter_setter_on_one_line=false org.eclipse.jdt.core.formatter.keep_simple_getter_setter_on_one_line=false
org.eclipse.jdt.core.formatter.keep_simple_while_body_on_same_line=false org.eclipse.jdt.core.formatter.keep_simple_while_body_on_same_line=false
org.eclipse.jdt.core.formatter.keep_switch_body_block_on_one_line=one_line_never
org.eclipse.jdt.core.formatter.keep_switch_case_with_arrow_on_one_line=one_line_never
org.eclipse.jdt.core.formatter.keep_then_statement_on_same_line=false org.eclipse.jdt.core.formatter.keep_then_statement_on_same_line=false
org.eclipse.jdt.core.formatter.keep_type_declaration_on_one_line=one_line_never org.eclipse.jdt.core.formatter.keep_type_declaration_on_one_line=one_line_never
org.eclipse.jdt.core.formatter.lineSplit=150 org.eclipse.jdt.core.formatter.lineSplit=150
@ -404,5 +414,6 @@ org.eclipse.jdt.core.formatter.wrap_before_or_operator_multicatch=true
org.eclipse.jdt.core.formatter.wrap_before_relational_operator=true org.eclipse.jdt.core.formatter.wrap_before_relational_operator=true
org.eclipse.jdt.core.formatter.wrap_before_shift_operator=true org.eclipse.jdt.core.formatter.wrap_before_shift_operator=true
org.eclipse.jdt.core.formatter.wrap_before_string_concatenation=true org.eclipse.jdt.core.formatter.wrap_before_string_concatenation=true
org.eclipse.jdt.core.formatter.wrap_before_switch_case_arrow_operator=false
org.eclipse.jdt.core.formatter.wrap_outer_expressions_when_nested=true org.eclipse.jdt.core.formatter.wrap_outer_expressions_when_nested=true
org.eclipse.jdt.core.javaFormatter=org.eclipse.jdt.core.defaultJavaFormatter org.eclipse.jdt.core.javaFormatter=org.eclipse.jdt.core.defaultJavaFormatter

View file

@ -8,6 +8,7 @@ cleanup.add_missing_nls_tags=false
cleanup.add_missing_override_annotations=true cleanup.add_missing_override_annotations=true
cleanup.add_missing_override_annotations_interface_methods=true cleanup.add_missing_override_annotations_interface_methods=true
cleanup.add_serial_version_id=true cleanup.add_serial_version_id=true
cleanup.also_simplify_lambda=true
cleanup.always_use_blocks=true cleanup.always_use_blocks=true
cleanup.always_use_parentheses_in_expressions=false cleanup.always_use_parentheses_in_expressions=false
cleanup.always_use_this_for_non_static_field_access=true cleanup.always_use_this_for_non_static_field_access=true
@ -27,6 +28,7 @@ cleanup.convert_to_enhanced_for_loop=false
cleanup.convert_to_enhanced_for_loop_if_loop_var_used=true cleanup.convert_to_enhanced_for_loop_if_loop_var_used=true
cleanup.convert_to_switch_expressions=false cleanup.convert_to_switch_expressions=false
cleanup.correct_indentation=false cleanup.correct_indentation=false
cleanup.do_while_rather_than_while=true
cleanup.double_negation=false cleanup.double_negation=false
cleanup.else_if=false cleanup.else_if=false
cleanup.embedded_if=false cleanup.embedded_if=false
@ -60,6 +62,7 @@ cleanup.one_if_rather_than_duplicate_blocks_that_fall_through=true
cleanup.operand_factorization=false cleanup.operand_factorization=false
cleanup.organize_imports=false cleanup.organize_imports=false
cleanup.overridden_assignment=false cleanup.overridden_assignment=false
cleanup.overridden_assignment_move_decl=true
cleanup.plain_replacement=false cleanup.plain_replacement=false
cleanup.precompile_regex=false cleanup.precompile_regex=false
cleanup.primitive_comparison=false cleanup.primitive_comparison=false
@ -89,6 +92,7 @@ cleanup.remove_unnecessary_casts=true
cleanup.remove_unnecessary_nls_tags=true cleanup.remove_unnecessary_nls_tags=true
cleanup.remove_unused_imports=true cleanup.remove_unused_imports=true
cleanup.remove_unused_local_variables=false cleanup.remove_unused_local_variables=false
cleanup.remove_unused_method_parameters=false
cleanup.remove_unused_private_fields=true cleanup.remove_unused_private_fields=true
cleanup.remove_unused_private_members=false cleanup.remove_unused_private_members=false
cleanup.remove_unused_private_methods=true cleanup.remove_unused_private_methods=true
@ -101,7 +105,11 @@ cleanup.sort_members_all=false
cleanup.standard_comparison=false cleanup.standard_comparison=false
cleanup.static_inner_class=false cleanup.static_inner_class=false
cleanup.strictly_equal_or_different=false cleanup.strictly_equal_or_different=false
cleanup.stringbuffer_to_stringbuilder=false
cleanup.stringbuilder=false cleanup.stringbuilder=false
cleanup.stringbuilder_for_local_vars=true
cleanup.stringconcat_stringbuffer_stringbuilder=false
cleanup.stringconcat_to_textblock=false
cleanup.substring=false cleanup.substring=false
cleanup.switch=false cleanup.switch=false
cleanup.system_property=false cleanup.system_property=false
@ -136,10 +144,11 @@ cleanup_settings_version=2
eclipse.preferences.version=1 eclipse.preferences.version=1
editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true
formatter_profile=_Kiss4web formatter_profile=_Kiss4web
formatter_settings_version=21 formatter_settings_version=23
jautodoc.cleanup.add_header=false jautodoc.cleanup.add_header=false
jautodoc.cleanup.javadoc=false jautodoc.cleanup.javadoc=false
jautodoc.cleanup.replace_header=false jautodoc.cleanup.replace_header=false
org.eclipse.jdt.ui.text.custom_code_templates=
sp_cleanup.add_default_serial_version_id=true sp_cleanup.add_default_serial_version_id=true
sp_cleanup.add_generated_serial_version_id=false sp_cleanup.add_generated_serial_version_id=false
sp_cleanup.add_missing_annotations=true sp_cleanup.add_missing_annotations=true

Binary file not shown.

Binary file not shown.

View file

@ -1,5 +1,5 @@
/** /**
* Copyright (C) 2018-2021 Christian Pierre MOMON * Copyright (C) 2018-2023 Christian Pierre MOMON
* *
* This file is part of Kiss4web. * This file is part of Kiss4web.
* *
@ -19,6 +19,8 @@
package fr.devinsy.kiss4web.dispatcher.hooks; package fr.devinsy.kiss4web.dispatcher.hooks;
import java.io.IOException; import java.io.IOException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import javax.servlet.ServletConfig; import javax.servlet.ServletConfig;
import javax.servlet.ServletContext; import javax.servlet.ServletContext;
@ -26,12 +28,10 @@ import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import org.apache.commons.io.IOUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import fr.devinsy.xidyn.XidynException;
import fr.devinsy.xidyn.presenters.URLPresenter;
/** /**
* The Class InitHook. * The Class InitHook.
*/ */
@ -67,26 +67,20 @@ public class ApplicationInitFailedHook extends HookCore
@Override @Override
public void process(final ServletConfig servletConfig, final ServletContext servletContext, final HttpServletRequest request, public void process(final ServletConfig servletConfig, final ServletContext servletContext, final HttpServletRequest request,
final HttpServletResponse response) throws IOException, ServletException final HttpServletResponse response) throws IOException, ServletException
{
try
{ {
logger.debug("Doing catch {}.", this.getClass().getName()); logger.debug("Doing catch {}.", this.getClass().getName());
String path = servletContext.getRealPath("/") + request.getPathInfo(); String path = servletContext.getRealPath("/") + request.getPathInfo();
logger.info("path=[{}]", path); logger.info("path=[{}]", path);
StringBuffer html = new URLPresenter("/fr/devinsy/kiss4web/dispatcher/hooks/applicationInitFailed.xhtml").dynamize(); // Get page.
URL url = Hook.class.getResource("/fr/devinsy/kiss4web/dispatcher/hooks/applicationInitFailed.xhtml");
String xhtml = IOUtils.toString(url, StandardCharsets.UTF_8);
// Display page. // Display page.
response.setContentType("application/xhtml+xml; charset=UTF-8"); response.setContentType("application/xhtml+xml; charset=UTF-8");
response.getWriter().println(html); response.getWriter().println(xhtml);
logger.info("Application Init Failed page returned."); logger.info("Application Init Failed page returned.");
} }
catch (XidynException exception)
{
exception.printStackTrace();
new FatalHook().process(servletConfig, servletContext, request, response);
}
}
} }

View file

@ -1,5 +1,5 @@
/** /**
* Copyright (C) 2018-2021 Christian Pierre MOMON * Copyright (C) 2018-2023 Christian Pierre MOMON
* *
* This file is part of Kiss4web. * This file is part of Kiss4web.
* *
@ -19,6 +19,8 @@
package fr.devinsy.kiss4web.dispatcher.hooks; package fr.devinsy.kiss4web.dispatcher.hooks;
import java.io.IOException; import java.io.IOException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import javax.servlet.ServletConfig; import javax.servlet.ServletConfig;
import javax.servlet.ServletContext; import javax.servlet.ServletContext;
@ -26,12 +28,10 @@ import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import org.apache.commons.io.IOUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import fr.devinsy.xidyn.XidynException;
import fr.devinsy.xidyn.presenters.URLPresenter;
/** /**
* The Class InitHook. * The Class InitHook.
*/ */
@ -67,26 +67,20 @@ public class ApplicationInitHook extends HookCore
@Override @Override
public void process(final ServletConfig servletConfig, final ServletContext servletContext, final HttpServletRequest request, public void process(final ServletConfig servletConfig, final ServletContext servletContext, final HttpServletRequest request,
final HttpServletResponse response) throws IOException, ServletException final HttpServletResponse response) throws IOException, ServletException
{
try
{ {
logger.debug("Doing catch {}.", this.getClass().getName()); logger.debug("Doing catch {}.", this.getClass().getName());
String path = servletContext.getRealPath("/") + request.getPathInfo(); String path = servletContext.getRealPath("/") + request.getPathInfo();
logger.info("path=[{}]", path); logger.info("path=[{}]", path);
StringBuffer html = new URLPresenter("/fr/devinsy/kiss4web/dispatcher/hooks/applicationInit.xhtml").dynamize(); // Get page.
URL url = Hook.class.getResource("/fr/devinsy/kiss4web/dispatcher/hooks/applicationInit.xhtml");
String xhtml = IOUtils.toString(url, StandardCharsets.UTF_8);
// Display page. // Display page.
response.setContentType("application/xhtml+xml; charset=UTF-8"); response.setContentType("application/xhtml+xml; charset=UTF-8");
response.getWriter().println(html); response.getWriter().println(xhtml);
logger.info("Application Init page returned."); logger.info("Application Init page returned.");
} }
catch (XidynException exception)
{
exception.printStackTrace();
new FatalHook().process(servletConfig, servletContext, request, response);
}
}
} }

View file

@ -1,5 +1,5 @@
/** /**
* Copyright (C) 2018-2021 Christian Pierre MOMON * Copyright (C) 2018-2023 Christian Pierre MOMON
* *
* This file is part of Kiss4web. * This file is part of Kiss4web.
* *
@ -20,6 +20,8 @@ package fr.devinsy.kiss4web.dispatcher.hooks;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import javax.servlet.ServletConfig; import javax.servlet.ServletConfig;
import javax.servlet.ServletContext; import javax.servlet.ServletContext;
@ -27,12 +29,10 @@ import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import org.apache.commons.io.IOUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import fr.devinsy.xidyn.XidynException;
import fr.devinsy.xidyn.presenters.URLPresenter;
/** /**
* The Class ErrorHook. * The Class ErrorHook.
*/ */
@ -78,22 +78,17 @@ public class ErrorHook extends HookCore
{ {
logger.debug("Doing catch."); logger.debug("Doing catch.");
try
{
String path = servletContext.getRealPath("/") + request.getPathInfo(); String path = servletContext.getRealPath("/") + request.getPathInfo();
logger.info("path=[{}]", path); logger.info("path=[{}]", path);
StringBuffer html = new URLPresenter("/fr/devinsy/kiss4web/dispatcher/hooks/error.xhtml").dynamize(); // Get page.
URL url = Hook.class.getResource("/fr/devinsy/kiss4web/dispatcher/hooks/error.xhtml");
String xhtml = IOUtils.toString(url, StandardCharsets.UTF_8);
// Display page. // Display page.
response.setContentType("application/xhtml+xml; charset=UTF-8"); response.setContentType("application/xhtml+xml; charset=UTF-8");
response.getWriter().println(html); response.getWriter().println(xhtml);
logger.info("Error page returned for [{}].", path); logger.info("Error page returned for [{}].", path);
} }
catch (XidynException exception)
{
exception.printStackTrace();
new FatalHook().process(servletConfig, servletContext, request, response);
}
}
} }

View file

@ -1,5 +1,5 @@
/** /**
* Copyright (C) 2018-2021 Christian Pierre MOMON * Copyright (C) 2018-2023 Christian Pierre MOMON
* *
* This file is part of Kiss4web. * This file is part of Kiss4web.
* *
@ -20,7 +20,8 @@ package fr.devinsy.kiss4web.dispatcher.hooks;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.PrintWriter; import java.net.URL;
import java.nio.charset.StandardCharsets;
import javax.servlet.ServletConfig; import javax.servlet.ServletConfig;
import javax.servlet.ServletContext; import javax.servlet.ServletContext;
@ -28,6 +29,7 @@ import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import org.apache.commons.io.IOUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -79,25 +81,14 @@ public class FatalHook extends HookCore
String path = servletContext.getRealPath("/") + request.getPathInfo(); String path = servletContext.getRealPath("/") + request.getPathInfo();
logger.info("path=[{}]", path); logger.info("path=[{}]", path);
// Display fatal error page. // Get page.
response.setContentType("text/html; charset=UTF-8"); URL url = Hook.class.getResource("/fr/devinsy/kiss4web/dispatcher/hooks/fatal.xhtml");
PrintWriter out = response.getWriter(); String xhtml = IOUtils.toString(url, StandardCharsets.UTF_8);
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)); // Display page.
response.setContentType("application/xhtml+xml; charset=UTF-8");
response.getWriter().println(xhtml);
logger.info("Fatal page returned.");
} }
} }

View file

@ -1,5 +1,5 @@
/** /**
* Copyright (C) 2018-2021 Christian Pierre MOMON * Copyright (C) 2018-2023 Christian Pierre MOMON
* *
* This file is part of Kiss4web. * This file is part of Kiss4web.
* *
@ -20,6 +20,8 @@ package fr.devinsy.kiss4web.dispatcher.hooks;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import javax.servlet.ServletConfig; import javax.servlet.ServletConfig;
import javax.servlet.ServletContext; import javax.servlet.ServletContext;
@ -27,11 +29,10 @@ import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import org.apache.commons.io.IOUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import fr.devinsy.kiss4web.dispatcher.KissDispatcherUtils;
/** /**
* The Class InitFailedHook. * The Class InitFailedHook.
*/ */
@ -80,9 +81,14 @@ public class InitFailedHook extends HookCore
String path = servletContext.getRealPath("/") + request.getPathInfo(); String path = servletContext.getRealPath("/") + request.getPathInfo();
logger.info("path=[{}]", path); logger.info("path=[{}]", path);
String mimeType = servletContext.getMimeType(path); // Get page.
KissDispatcherUtils.returnInlineFile(response, new File(path), mimeType); URL url = Hook.class.getResource("/fr/devinsy/kiss4web/dispatcher/hooks/initFailed.xhtml");
String xhtml = IOUtils.toString(url, StandardCharsets.UTF_8);
logger.info("File returned directly [{}] with mimetype [{}].", path, servletContext.getMimeType(path)); // Display page.
response.setContentType("application/xhtml+xml; charset=UTF-8");
response.getWriter().println(xhtml);
logger.info("Init Failed page returned.");
} }
} }

View file

@ -1,5 +1,5 @@
/** /**
* Copyright (C) 2018-2021 Christian Pierre MOMON * Copyright (C) 2018-2023 Christian Pierre MOMON
* *
* This file is part of Kiss4web. * This file is part of Kiss4web.
* *
@ -19,6 +19,8 @@
package fr.devinsy.kiss4web.dispatcher.hooks; package fr.devinsy.kiss4web.dispatcher.hooks;
import java.io.IOException; import java.io.IOException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import javax.servlet.ServletConfig; import javax.servlet.ServletConfig;
import javax.servlet.ServletContext; import javax.servlet.ServletContext;
@ -26,12 +28,10 @@ import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import org.apache.commons.io.IOUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import fr.devinsy.xidyn.XidynException;
import fr.devinsy.xidyn.presenters.URLPresenter;
/** /**
* The Class InitHook. * The Class InitHook.
*/ */
@ -67,26 +67,20 @@ public class InitHook extends HookCore
@Override @Override
public void process(final ServletConfig servletConfig, final ServletContext servletContext, final HttpServletRequest request, public void process(final ServletConfig servletConfig, final ServletContext servletContext, final HttpServletRequest request,
final HttpServletResponse response) throws IOException, ServletException final HttpServletResponse response) throws IOException, ServletException
{
try
{ {
logger.debug("Doing catch {}.", this.getClass().getName()); logger.debug("Doing catch {}.", this.getClass().getName());
String path = servletContext.getRealPath("/") + request.getPathInfo(); String path = servletContext.getRealPath("/") + request.getPathInfo();
logger.info("path=[{}]", path); logger.info("path=[{}]", path);
StringBuffer html = new URLPresenter("/fr/devinsy/kiss4web/dispatcher/hooks/init.xhtml").dynamize(); // Get page.
URL url = Hook.class.getResource("/fr/devinsy/kiss4web/dispatcher/hooks/init.xhtml");
String xhtml = IOUtils.toString(url, StandardCharsets.UTF_8);
// Display page. // Display page.
response.setContentType("application/xhtml+xml; charset=UTF-8"); response.setContentType("application/xhtml+xml; charset=UTF-8");
response.getWriter().println(html); response.getWriter().println(xhtml);
logger.info("Init page returned."); logger.info("Init page returned.");
} }
catch (XidynException exception)
{
exception.printStackTrace();
new FatalHook().process(servletConfig, servletContext, request, response);
}
}
} }

View file

@ -1,5 +1,5 @@
/** /**
* Copyright (C) 2018-2021 Christian Pierre MOMON * Copyright (C) 2018-2023 Christian Pierre MOMON
* *
* This file is part of Kiss4web. * This file is part of Kiss4web.
* *
@ -20,6 +20,8 @@ package fr.devinsy.kiss4web.dispatcher.hooks;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import javax.servlet.ServletConfig; import javax.servlet.ServletConfig;
import javax.servlet.ServletContext; import javax.servlet.ServletContext;
@ -27,12 +29,10 @@ import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import org.apache.commons.io.IOUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import fr.devinsy.xidyn.XidynException;
import fr.devinsy.xidyn.presenters.URLPresenter;
/** /**
* The Class MaintenanceHook. * The Class MaintenanceHook.
*/ */
@ -75,26 +75,20 @@ public class MaintenanceHook extends HookCore
@Override @Override
public void process(final ServletConfig servletConfig, final ServletContext servletContext, final HttpServletRequest request, public void process(final ServletConfig servletConfig, final ServletContext servletContext, final HttpServletRequest request,
final HttpServletResponse response) throws IOException, ServletException final HttpServletResponse response) throws IOException, ServletException
{
try
{ {
logger.debug("Doing catch {}.", this.getClass().getName()); logger.debug("Doing catch {}.", this.getClass().getName());
String path = servletContext.getRealPath("/") + request.getPathInfo(); String path = servletContext.getRealPath("/") + request.getPathInfo();
logger.info("path=[{}]", path); logger.info("path=[{}]", path);
StringBuffer html = new URLPresenter("/fr/devinsy/kiss4web/dispatcher/hooks/maintenance.xhtml").dynamize(); // Get page.
URL url = Hook.class.getResource("/fr/devinsy/kiss4web/dispatcher/hooks/maintenance.xhtml");
String xhtml = IOUtils.toString(url, StandardCharsets.UTF_8);
// Display page. // Display page.
response.setContentType("application/xhtml+xml; charset=UTF-8"); response.setContentType("application/xhtml+xml; charset=UTF-8");
response.getWriter().println(html); response.getWriter().println(xhtml);
logger.info("Application Init page returned."); logger.info("Maintenance page returned.");
}
catch (XidynException exception)
{
exception.printStackTrace();
new FatalHook().process(servletConfig, servletContext, request, response);
}
} }
} }