From d025ac30b9c65a19535c7d6955b084960b4d0621 Mon Sep 17 00:00:00 2001 From: lalber Date: Mon, 8 Mar 2021 18:27:55 +0100 Subject: First version of feature --- .../impl/idp/auth/services/ErrorTicketService.java | 212 +++++++++++++++++++++ 1 file changed, 212 insertions(+) create mode 100644 eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/services/ErrorTicketService.java (limited to 'eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/services/ErrorTicketService.java') diff --git a/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/services/ErrorTicketService.java b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/services/ErrorTicketService.java new file mode 100644 index 00000000..c5bac225 --- /dev/null +++ b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/services/ErrorTicketService.java @@ -0,0 +1,212 @@ +package at.gv.egiz.eaaf.core.impl.idp.auth.services; + +import at.gv.egiz.eaaf.core.api.IStatusMessenger; +import at.gv.egiz.eaaf.core.api.data.EaafConstants; +import at.gv.egiz.eaaf.core.api.idp.IConfiguration; +import at.gv.egiz.eaaf.core.exceptions.EaafException; +import at.gv.egiz.eaaf.core.exceptions.TaskExecutionException; +import at.gv.egiz.eaaf.core.impl.idp.controller.ProtocolFinalizationController; +import at.gv.egiz.eaaf.core.impl.utils.FileUtils; +import at.gv.egiz.eaaf.core.impl.utils.ServletUtils; +import lombok.Getter; +import org.apache.commons.lang3.RandomStringUtils; +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.text.StringEscapeUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.io.Resource; +import org.springframework.core.io.ResourceLoader; +import org.springframework.stereotype.Service; + +import javax.annotation.PostConstruct; +import javax.servlet.http.HttpServletRequest; +import java.io.InputStream; +import java.util.HashMap; +import java.util.Map; +import java.util.Properties; + +@Service() +public class ErrorTicketService { + private static final Logger log = LoggerFactory.getLogger(ErrorTicketService.class); + + private static final String CONFIG_PROP_ERRORHANDLING_ACTION_PATH = "core.errorhandling.action"; + private static final String TECH_LOG_MSG = "errorCode={} Message={}"; + private static final String TICKET_LOG_MSG = "Ticket={} errorCode={} Message={}"; + + private final HashMap propertyMap = new HashMap(); + + + public enum ActionType { + TICKET_REDIRECT("ticket_redirect"), TICKET_NOREDIRECT("ticket_noredirect"), NOTICKET_REDIRECT( + "noticket_redirect"), NOTICKET_NOREDIRECT("noticket_noredirect"); + + private final String name; + + ActionType(final String text) { + this.name = text; + } + + @Override + public String toString() { + return name; + } + } + + @Autowired(required = true) + IConfiguration basicConfig; + @Autowired(required = true) + ResourceLoader resourceLoader; + + @PostConstruct + private void initialize() throws EaafException { + log.info("initErrorTicketService"); + + final String ticketConfPath = basicConfig.getBasicConfiguration(CONFIG_PROP_ERRORHANDLING_ACTION_PATH); + log.info("ticketConfPath" + ticketConfPath); + + + if (StringUtils.isEmpty(ticketConfPath)) { + log.error("Error: Path to errorhandling action configuration not known"); + throw new EaafException("Error: Path to errorhandling action configuration not known"); + } else { + + Properties getProperties = new Properties(); + try { + + final String fullFilePath = FileUtils + .makeAbsoluteUrl(ticketConfPath, basicConfig.getConfigurationRootDirectory()); + final Resource ressource = resourceLoader.getResource(fullFilePath); + final InputStream is = ressource.getInputStream(); + getProperties.load(is); + is.close(); + propertyMap.putAll((Map) getProperties); + + // log.error(propertyMap.toString()); + // log.error("working: " + propertyMap.get("auth.00")); + + } catch (Exception e) { + log.error("Error: something went wrong"); + throw new EaafException("Error: Parsing errorhandling actions failed"); + } + } + } + + public HandleData createHandleData(Throwable throwable, HttpServletRequest req) { + HandleData data = new HandleData(throwable, req); + extractErrorCode(data); + setUpErrorData(data); + + return data; + } + + private void extractErrorCode(HandleData data) { + Throwable originalException; + if (data.throwable instanceof TaskExecutionException + && ((TaskExecutionException) data.throwable).getOriginalException() != null) { + originalException = ((TaskExecutionException) data.throwable).getOriginalException(); + + } else { + originalException = data.throwable; + + } + + if (!(originalException instanceof EaafException)) { + data.errorCode = IStatusMessenger.CODES_INTERNAL_ERROR_GENERIC; + + } else { + data.errorCode = ((EaafException) originalException).getErrorId(); + + } + } + + private void setUpErrorData(HandleData data) { + + if (propertyMap.containsKey(data.errorCode)) { + String action = propertyMap.get(data.errorCode); + + if (action.equals(ActionType.TICKET_REDIRECT.toString())) { + data.actionType = ActionType.TICKET_REDIRECT; + data.generateSupportTicket(); + data.generateRedirect(); + + } else if (action.equals(ActionType.TICKET_NOREDIRECT.toString())) { + data.actionType = ActionType.TICKET_NOREDIRECT; + data.generateSupportTicket(); + + } else if (action.equals(ActionType.NOTICKET_REDIRECT.toString())) { + data.actionType = ActionType.NOTICKET_REDIRECT; + data.generateRedirect(); + + } else {// ActionType.NOTICKET_NOREDIRECT -> nothing to be done + data.actionType = ActionType.NOTICKET_NOREDIRECT; + + } + + } else { + data.generateSupportTicket(); + // TODO log with ticket gernal internal error + } + } + + public class HandleData { + private final HttpServletRequest req; + @Getter private String supportTicket; + @Getter private String redirectUrl; + @Getter private final Throwable throwable; + @Getter private String errorCode; + @Getter private ActionType actionType; + + + private HandleData(Throwable throwable, HttpServletRequest req) { + this.throwable = throwable; + this.req = req; + } + + private void generateRedirect() { + redirectUrl = ServletUtils.getBaseUrl(req); + redirectUrl += "/" + ProtocolFinalizationController.ENDPOINT_ERROR_REDIRECT + + "?" + EaafConstants.PARAM_HTTP_ERROR_CODE + "=" + + StringEscapeUtils.escapeHtml4(req.getParameter(EaafConstants.PARAM_HTTP_ERROR_CODE));; + + } + + private void generateSupportTicket() { + + String randomCode = RandomStringUtils.randomAlphanumeric(4).toUpperCase() + '-' + + RandomStringUtils.randomAlphanumeric(4).toUpperCase() + '-' + + RandomStringUtils.randomAlphanumeric(4).toUpperCase(); + supportTicket = randomCode; + } + + public void log_error() { + + if (supportTicket != null) { + log.error(TICKET_LOG_MSG, supportTicket, errorCode, throwable.getMessage(), + throwable); + } else { + log.error(TECH_LOG_MSG, errorCode, throwable.getMessage(), throwable); + } + } + + public void log_info() { + + if (supportTicket != null) { + log.info(TICKET_LOG_MSG, supportTicket, errorCode, throwable.getMessage(), throwable); + + } else { + log.info(TECH_LOG_MSG, errorCode, throwable.getMessage(), throwable); + } + } + + public void log_warn() { + + if (supportTicket != null) { + log.warn(TICKET_LOG_MSG, supportTicket, errorCode, throwable.getMessage(), throwable); + + } else { + log.warn(TECH_LOG_MSG, errorCode, throwable.getMessage(), throwable); + } + } + } +} -- cgit v1.2.3 From b8d3937a99e54036be491b5df606ab6c5a81f480 Mon Sep 17 00:00:00 2001 From: lalber Date: Fri, 12 Mar 2021 16:11:07 +0100 Subject: added some error Handling --- .../egiz/eaaf/core/impl/idp/auth/services/ErrorTicketService.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/services/ErrorTicketService.java') diff --git a/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/services/ErrorTicketService.java b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/services/ErrorTicketService.java index c5bac225..3471aebe 100644 --- a/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/services/ErrorTicketService.java +++ b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/services/ErrorTicketService.java @@ -92,7 +92,7 @@ public class ErrorTicketService { } } - public HandleData createHandleData(Throwable throwable, HttpServletRequest req) { + public HandleData createHandleData(Throwable throwable, HttpServletRequest req) throws EaafException { HandleData data = new HandleData(throwable, req); extractErrorCode(data); setUpErrorData(data); @@ -120,7 +120,7 @@ public class ErrorTicketService { } } - private void setUpErrorData(HandleData data) { + private void setUpErrorData(HandleData data) throws EaafException { if (propertyMap.containsKey(data.errorCode)) { String action = propertyMap.get(data.errorCode); @@ -145,7 +145,8 @@ public class ErrorTicketService { } else { data.generateSupportTicket(); - // TODO log with ticket gernal internal error + throw new EaafException("internal.configuration.00", new Object[] {data.errorCode + "in on_error_action" + + ".properties"}); } } -- cgit v1.2.3 From 5bd780462933b439d2e323c18a5404da60e764a5 Mon Sep 17 00:00:00 2001 From: lalber Date: Tue, 16 Mar 2021 14:45:30 +0100 Subject: add some Junit fixes and other spotbug based ones --- .../impl/idp/auth/services/ErrorTicketService.java | 58 +++++++++++++++------- 1 file changed, 39 insertions(+), 19 deletions(-) (limited to 'eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/services/ErrorTicketService.java') diff --git a/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/services/ErrorTicketService.java b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/services/ErrorTicketService.java index 3471aebe..673b53c2 100644 --- a/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/services/ErrorTicketService.java +++ b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/services/ErrorTicketService.java @@ -86,12 +86,19 @@ public class ErrorTicketService { // log.error("working: " + propertyMap.get("auth.00")); } catch (Exception e) { - log.error("Error: something went wrong"); - throw new EaafException("Error: Parsing errorhandling actions failed"); + log.error("Error: something went wrong", e); + throw new EaafException("Error: Parsing errorhandling actions failed", new Object[]{}, e); } } } + /** + * creates error handling data. + * @param throwable error + * @param req http request + * @return eror handle Data + * @throws EaafException In case of an internal error + */ public HandleData createHandleData(Throwable throwable, HttpServletRequest req) throws EaafException { HandleData data = new HandleData(throwable, req); extractErrorCode(data); @@ -138,25 +145,30 @@ public class ErrorTicketService { data.actionType = ActionType.NOTICKET_REDIRECT; data.generateRedirect(); - } else {// ActionType.NOTICKET_NOREDIRECT -> nothing to be done + } else { // ActionType.NOTICKET_NOREDIRECT -> nothing to be done data.actionType = ActionType.NOTICKET_NOREDIRECT; } } else { data.generateSupportTicket(); - throw new EaafException("internal.configuration.00", new Object[] {data.errorCode + "in on_error_action" + - ".properties"}); + throw new EaafException("internal.configuration.00", + new Object[]{data.errorCode + "in on_error_action" + ".properties"}); } } - public class HandleData { + static class HandleData { private final HttpServletRequest req; - @Getter private String supportTicket; - @Getter private String redirectUrl; - @Getter private final Throwable throwable; - @Getter private String errorCode; - @Getter private ActionType actionType; + @Getter + private String supportTicket; + @Getter + private String redirectUrl; + @Getter + private final Throwable throwable; + @Getter + private String errorCode; + @Getter + private ActionType actionType; private HandleData(Throwable throwable, HttpServletRequest req) { @@ -166,30 +178,35 @@ public class ErrorTicketService { private void generateRedirect() { redirectUrl = ServletUtils.getBaseUrl(req); - redirectUrl += "/" + ProtocolFinalizationController.ENDPOINT_ERROR_REDIRECT - + "?" + EaafConstants.PARAM_HTTP_ERROR_CODE + "=" + - StringEscapeUtils.escapeHtml4(req.getParameter(EaafConstants.PARAM_HTTP_ERROR_CODE));; + redirectUrl += + "/" + ProtocolFinalizationController.ENDPOINT_ERROR_REDIRECT + "?" + EaafConstants.PARAM_HTTP_ERROR_CODE + "=" + + StringEscapeUtils.escapeHtml4(req.getParameter(EaafConstants.PARAM_HTTP_ERROR_CODE)); } private void generateSupportTicket() { - String randomCode = RandomStringUtils.randomAlphanumeric(4).toUpperCase() + '-' + - RandomStringUtils.randomAlphanumeric(4).toUpperCase() + '-' + - RandomStringUtils.randomAlphanumeric(4).toUpperCase(); + String randomCode = + RandomStringUtils.randomAlphanumeric(4).toUpperCase() + '-' + RandomStringUtils.randomAlphanumeric(4) + .toUpperCase() + '-' + RandomStringUtils.randomAlphanumeric(4).toUpperCase(); supportTicket = randomCode; } + /** + * Logs error to technical log. + */ public void log_error() { if (supportTicket != null) { - log.error(TICKET_LOG_MSG, supportTicket, errorCode, throwable.getMessage(), - throwable); + log.error(TICKET_LOG_MSG, supportTicket, errorCode, throwable.getMessage(), throwable); } else { log.error(TECH_LOG_MSG, errorCode, throwable.getMessage(), throwable); } } + /** + * Logs info to technical log. + */ public void log_info() { if (supportTicket != null) { @@ -200,6 +217,9 @@ public class ErrorTicketService { } } + /** + * Logs warn to technical log. + */ public void log_warn() { if (supportTicket != null) { -- cgit v1.2.3 From bf258e421c55baf64eb9bb30b95e4d29bfdef5eb Mon Sep 17 00:00:00 2001 From: lalber Date: Sun, 21 Mar 2021 12:52:27 +0100 Subject: Junit fixes --- .../core/impl/idp/auth/services/ErrorTicketService.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/services/ErrorTicketService.java') diff --git a/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/services/ErrorTicketService.java b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/services/ErrorTicketService.java index 673b53c2..8bcb5305 100644 --- a/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/services/ErrorTicketService.java +++ b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/services/ErrorTicketService.java @@ -68,13 +68,15 @@ public class ErrorTicketService { if (StringUtils.isEmpty(ticketConfPath)) { log.error("Error: Path to errorhandling action configuration not known"); - throw new EaafException("Error: Path to errorhandling action configuration not known"); + throw new EaafException("internal.configuration.00", + new Object[]{CONFIG_PROP_ERRORHANDLING_ACTION_PATH}); } else { Properties getProperties = new Properties(); + String fullFilePath = null; try { - final String fullFilePath = FileUtils + fullFilePath = FileUtils .makeAbsoluteUrl(ticketConfPath, basicConfig.getConfigurationRootDirectory()); final Resource ressource = resourceLoader.getResource(fullFilePath); final InputStream is = ressource.getInputStream(); @@ -86,8 +88,9 @@ public class ErrorTicketService { // log.error("working: " + propertyMap.get("auth.00")); } catch (Exception e) { - log.error("Error: something went wrong", e); - throw new EaafException("Error: Parsing errorhandling actions failed", new Object[]{}, e); + log.error("Error: could not found file.", e); + throw new EaafException("internal.configuration.01", + new Object[]{CONFIG_PROP_ERRORHANDLING_ACTION_PATH, "File cloud not be found."}); } } } @@ -153,7 +156,7 @@ public class ErrorTicketService { } else { data.generateSupportTicket(); throw new EaafException("internal.configuration.00", - new Object[]{data.errorCode + "in on_error_action" + ".properties"}); + new Object[]{data.errorCode + " in on_error_action" + ".properties"}); } } -- cgit v1.2.3 From f76af302b54a0ddc0668ae93a2d32a07b60e6495 Mon Sep 17 00:00:00 2001 From: lalber Date: Fri, 26 Mar 2021 08:48:10 +0100 Subject: better error conf and some fixes --- .../eaaf/core/impl/idp/auth/services/ErrorTicketService.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/services/ErrorTicketService.java') diff --git a/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/services/ErrorTicketService.java b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/services/ErrorTicketService.java index 8bcb5305..08fb04c6 100644 --- a/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/services/ErrorTicketService.java +++ b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/services/ErrorTicketService.java @@ -39,7 +39,8 @@ public class ErrorTicketService { public enum ActionType { TICKET_REDIRECT("ticket_redirect"), TICKET_NOREDIRECT("ticket_noredirect"), NOTICKET_REDIRECT( - "noticket_redirect"), NOTICKET_NOREDIRECT("noticket_noredirect"); + "noticket_redirect"), NOTICKET_NOREDIRECT("noticket_noredirect"), NOTICKET_AUTOREDIRECT( + "noticket_autoredirect"); private final String name; @@ -67,7 +68,7 @@ public class ErrorTicketService { if (StringUtils.isEmpty(ticketConfPath)) { - log.error("Error: Path to errorhandling action configuration not known"); + log.error("Error: Path to errorhandling-action mapping not known"); throw new EaafException("internal.configuration.00", new Object[]{CONFIG_PROP_ERRORHANDLING_ACTION_PATH}); } else { @@ -90,7 +91,8 @@ public class ErrorTicketService { } catch (Exception e) { log.error("Error: could not found file.", e); throw new EaafException("internal.configuration.01", - new Object[]{CONFIG_PROP_ERRORHANDLING_ACTION_PATH, "File cloud not be found."}); + new Object[]{CONFIG_PROP_ERRORHANDLING_ACTION_PATH, "File for errorhandling-action mapping cloud " + + "not be found."}); } } } @@ -148,6 +150,9 @@ public class ErrorTicketService { data.actionType = ActionType.NOTICKET_REDIRECT; data.generateRedirect(); + } else if (action.equals(ActionType.NOTICKET_AUTOREDIRECT.toString())) { + data.actionType = ActionType.NOTICKET_AUTOREDIRECT; + } else { // ActionType.NOTICKET_NOREDIRECT -> nothing to be done data.actionType = ActionType.NOTICKET_NOREDIRECT; -- cgit v1.2.3 From f18e44490057ba6e5fa719fefc47c8fd2e039b04 Mon Sep 17 00:00:00 2001 From: lalber Date: Wed, 7 Apr 2021 16:56:26 +0200 Subject: Interface extraction --- .../impl/idp/auth/services/ErrorTicketService.java | 241 --------------------- 1 file changed, 241 deletions(-) delete mode 100644 eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/services/ErrorTicketService.java (limited to 'eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/services/ErrorTicketService.java') diff --git a/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/services/ErrorTicketService.java b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/services/ErrorTicketService.java deleted file mode 100644 index 08fb04c6..00000000 --- a/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/services/ErrorTicketService.java +++ /dev/null @@ -1,241 +0,0 @@ -package at.gv.egiz.eaaf.core.impl.idp.auth.services; - -import at.gv.egiz.eaaf.core.api.IStatusMessenger; -import at.gv.egiz.eaaf.core.api.data.EaafConstants; -import at.gv.egiz.eaaf.core.api.idp.IConfiguration; -import at.gv.egiz.eaaf.core.exceptions.EaafException; -import at.gv.egiz.eaaf.core.exceptions.TaskExecutionException; -import at.gv.egiz.eaaf.core.impl.idp.controller.ProtocolFinalizationController; -import at.gv.egiz.eaaf.core.impl.utils.FileUtils; -import at.gv.egiz.eaaf.core.impl.utils.ServletUtils; -import lombok.Getter; -import org.apache.commons.lang3.RandomStringUtils; -import org.apache.commons.lang3.StringUtils; -import org.apache.commons.text.StringEscapeUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.core.io.Resource; -import org.springframework.core.io.ResourceLoader; -import org.springframework.stereotype.Service; - -import javax.annotation.PostConstruct; -import javax.servlet.http.HttpServletRequest; -import java.io.InputStream; -import java.util.HashMap; -import java.util.Map; -import java.util.Properties; - -@Service() -public class ErrorTicketService { - private static final Logger log = LoggerFactory.getLogger(ErrorTicketService.class); - - private static final String CONFIG_PROP_ERRORHANDLING_ACTION_PATH = "core.errorhandling.action"; - private static final String TECH_LOG_MSG = "errorCode={} Message={}"; - private static final String TICKET_LOG_MSG = "Ticket={} errorCode={} Message={}"; - - private final HashMap propertyMap = new HashMap(); - - - public enum ActionType { - TICKET_REDIRECT("ticket_redirect"), TICKET_NOREDIRECT("ticket_noredirect"), NOTICKET_REDIRECT( - "noticket_redirect"), NOTICKET_NOREDIRECT("noticket_noredirect"), NOTICKET_AUTOREDIRECT( - "noticket_autoredirect"); - - private final String name; - - ActionType(final String text) { - this.name = text; - } - - @Override - public String toString() { - return name; - } - } - - @Autowired(required = true) - IConfiguration basicConfig; - @Autowired(required = true) - ResourceLoader resourceLoader; - - @PostConstruct - private void initialize() throws EaafException { - log.info("initErrorTicketService"); - - final String ticketConfPath = basicConfig.getBasicConfiguration(CONFIG_PROP_ERRORHANDLING_ACTION_PATH); - log.info("ticketConfPath" + ticketConfPath); - - - if (StringUtils.isEmpty(ticketConfPath)) { - log.error("Error: Path to errorhandling-action mapping not known"); - throw new EaafException("internal.configuration.00", - new Object[]{CONFIG_PROP_ERRORHANDLING_ACTION_PATH}); - } else { - - Properties getProperties = new Properties(); - String fullFilePath = null; - try { - - fullFilePath = FileUtils - .makeAbsoluteUrl(ticketConfPath, basicConfig.getConfigurationRootDirectory()); - final Resource ressource = resourceLoader.getResource(fullFilePath); - final InputStream is = ressource.getInputStream(); - getProperties.load(is); - is.close(); - propertyMap.putAll((Map) getProperties); - - // log.error(propertyMap.toString()); - // log.error("working: " + propertyMap.get("auth.00")); - - } catch (Exception e) { - log.error("Error: could not found file.", e); - throw new EaafException("internal.configuration.01", - new Object[]{CONFIG_PROP_ERRORHANDLING_ACTION_PATH, "File for errorhandling-action mapping cloud " - + "not be found."}); - } - } - } - - /** - * creates error handling data. - * @param throwable error - * @param req http request - * @return eror handle Data - * @throws EaafException In case of an internal error - */ - public HandleData createHandleData(Throwable throwable, HttpServletRequest req) throws EaafException { - HandleData data = new HandleData(throwable, req); - extractErrorCode(data); - setUpErrorData(data); - - return data; - } - - private void extractErrorCode(HandleData data) { - Throwable originalException; - if (data.throwable instanceof TaskExecutionException - && ((TaskExecutionException) data.throwable).getOriginalException() != null) { - originalException = ((TaskExecutionException) data.throwable).getOriginalException(); - - } else { - originalException = data.throwable; - - } - - if (!(originalException instanceof EaafException)) { - data.errorCode = IStatusMessenger.CODES_INTERNAL_ERROR_GENERIC; - - } else { - data.errorCode = ((EaafException) originalException).getErrorId(); - - } - } - - private void setUpErrorData(HandleData data) throws EaafException { - - if (propertyMap.containsKey(data.errorCode)) { - String action = propertyMap.get(data.errorCode); - - if (action.equals(ActionType.TICKET_REDIRECT.toString())) { - data.actionType = ActionType.TICKET_REDIRECT; - data.generateSupportTicket(); - data.generateRedirect(); - - } else if (action.equals(ActionType.TICKET_NOREDIRECT.toString())) { - data.actionType = ActionType.TICKET_NOREDIRECT; - data.generateSupportTicket(); - - } else if (action.equals(ActionType.NOTICKET_REDIRECT.toString())) { - data.actionType = ActionType.NOTICKET_REDIRECT; - data.generateRedirect(); - - } else if (action.equals(ActionType.NOTICKET_AUTOREDIRECT.toString())) { - data.actionType = ActionType.NOTICKET_AUTOREDIRECT; - - } else { // ActionType.NOTICKET_NOREDIRECT -> nothing to be done - data.actionType = ActionType.NOTICKET_NOREDIRECT; - - } - - } else { - data.generateSupportTicket(); - throw new EaafException("internal.configuration.00", - new Object[]{data.errorCode + " in on_error_action" + ".properties"}); - } - } - - static class HandleData { - private final HttpServletRequest req; - @Getter - private String supportTicket; - @Getter - private String redirectUrl; - @Getter - private final Throwable throwable; - @Getter - private String errorCode; - @Getter - private ActionType actionType; - - - private HandleData(Throwable throwable, HttpServletRequest req) { - this.throwable = throwable; - this.req = req; - } - - private void generateRedirect() { - redirectUrl = ServletUtils.getBaseUrl(req); - redirectUrl += - "/" + ProtocolFinalizationController.ENDPOINT_ERROR_REDIRECT + "?" + EaafConstants.PARAM_HTTP_ERROR_CODE + "=" - + StringEscapeUtils.escapeHtml4(req.getParameter(EaafConstants.PARAM_HTTP_ERROR_CODE)); - - } - - private void generateSupportTicket() { - - String randomCode = - RandomStringUtils.randomAlphanumeric(4).toUpperCase() + '-' + RandomStringUtils.randomAlphanumeric(4) - .toUpperCase() + '-' + RandomStringUtils.randomAlphanumeric(4).toUpperCase(); - supportTicket = randomCode; - } - - /** - * Logs error to technical log. - */ - public void log_error() { - - if (supportTicket != null) { - log.error(TICKET_LOG_MSG, supportTicket, errorCode, throwable.getMessage(), throwable); - } else { - log.error(TECH_LOG_MSG, errorCode, throwable.getMessage(), throwable); - } - } - - /** - * Logs info to technical log. - */ - public void log_info() { - - if (supportTicket != null) { - log.info(TICKET_LOG_MSG, supportTicket, errorCode, throwable.getMessage(), throwable); - - } else { - log.info(TECH_LOG_MSG, errorCode, throwable.getMessage(), throwable); - } - } - - /** - * Logs warn to technical log. - */ - public void log_warn() { - - if (supportTicket != null) { - log.warn(TICKET_LOG_MSG, supportTicket, errorCode, throwable.getMessage(), throwable); - - } else { - log.warn(TECH_LOG_MSG, errorCode, throwable.getMessage(), throwable); - } - } - } -} -- cgit v1.2.3