diff options
Diffstat (limited to 'eaaf_core')
9 files changed, 87 insertions, 17 deletions
diff --git a/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/data/ErrorConfig.java b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/data/ErrorConfig.java index b9cacb1c..5f1d0976 100644 --- a/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/data/ErrorConfig.java +++ b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/data/ErrorConfig.java @@ -2,6 +2,9 @@ package at.gv.egiz.eaaf.core.impl.data; import java.util.List; +import com.fasterxml.jackson.annotation.JsonSetter; +import com.fasterxml.jackson.annotation.Nulls; + import at.gv.egiz.eaaf.core.impl.idp.auth.services.IErrorService.ActionType; import lombok.AllArgsConstructor; import lombok.Builder; @@ -44,6 +47,12 @@ public class ErrorConfig { @Builder.Default private Boolean useInternalAsExternal = false; + @Getter + @Setter + @Builder.Default + @JsonSetter(nulls = Nulls.SKIP) + private Boolean writeThrowable = true; + /** * Get type of error-handling flow. * diff --git a/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/AbstractAuthenticationManager.java b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/AbstractAuthenticationManager.java index 76bc09e6..3d0d2a3b 100644 --- a/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/AbstractAuthenticationManager.java +++ b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/AbstractAuthenticationManager.java @@ -379,7 +379,7 @@ public abstract class AbstractAuthenticationManager implements IAuthenticationMa final Throwable taskCause = cause.getCause(); if (taskCause != null && taskCause instanceof EaafException) { final EaafException moaTaskCause = (EaafException) taskCause; - log.info(taskCause.getMessage(), taskCause); + log.info(taskCause.getMessage()); throw moaTaskCause; } diff --git a/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/services/DefaultErrorService.java b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/services/DefaultErrorService.java index cd89f8a5..c9606026 100644 --- a/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/services/DefaultErrorService.java +++ b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/services/DefaultErrorService.java @@ -105,6 +105,10 @@ public class DefaultErrorService implements IErrorService { @Getter private LogLevel logLevel; + @Getter + @Builder.Default + private boolean writeThrowable = true; + @Override public Map<String, String> getAdditionalGuiModelElements() { return Collections.emptyMap(); diff --git a/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/services/IErrorService.java b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/services/IErrorService.java index 45b1cfe8..d6d310a5 100644 --- a/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/services/IErrorService.java +++ b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/services/IErrorService.java @@ -157,6 +157,13 @@ public interface IErrorService { Throwable getThrowable(); /** + * Flag that indicates if stake-trace should be logged for that error. + * + * @return <code>true</code> in case of log stake-trace, otherwise false + */ + boolean isWriteThrowable(); + + /** * Get the log-level for this internal errorId. * * @return Level to Log the error diff --git a/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/services/ProtocolAuthenticationService.java b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/services/ProtocolAuthenticationService.java index 6de2f94a..ef293f64 100644 --- a/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/services/ProtocolAuthenticationService.java +++ b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/services/ProtocolAuthenticationService.java @@ -326,29 +326,47 @@ public class ProtocolAuthenticationService implements IProtocolAuthenticationSer } private void logExceptionToTechnicalLog(IHandleData errorData) { - // In case of a TaskExecutionException, which is only a container for - // process-errors, - // extract internal exception + if (errorData.isWriteThrowable()) { + if (!(errorData.getThrowable() instanceof EaafException) + || LogLevel.ERROR.equals(errorData.getLogLevel())) { + log.error(errorData.getPreFormatedErrorMessage(), errorData.getThrowable()); - // Log exception - if (!(errorData.getThrowable() instanceof EaafException) - || LogLevel.ERROR.equals(errorData.getLogLevel())) { - log.error(errorData.getPreFormatedErrorMessage(), errorData.getThrowable()); + } else if (LogLevel.WARN.equals(errorData.getLogLevel())) { + log.warn(errorData.getPreFormatedErrorMessage(), errorData.getThrowable()); - } else if (LogLevel.WARN.equals(errorData.getLogLevel())) { - log.warn(errorData.getPreFormatedErrorMessage(), errorData.getThrowable()); + } else if (LogLevel.INFO.equals(errorData.getLogLevel())) { + log.info(errorData.getPreFormatedErrorMessage(), errorData.getThrowable()); - } else if (LogLevel.INFO.equals(errorData.getLogLevel())) { - log.info(errorData.getPreFormatedErrorMessage(), errorData.getThrowable()); + } else if (LogLevel.DEBUG.equals(errorData.getLogLevel())) { + log.debug(errorData.getPreFormatedErrorMessage(), errorData.getThrowable()); - } else if (LogLevel.DEBUG.equals(errorData.getLogLevel())) { - log.debug(errorData.getPreFormatedErrorMessage(), errorData.getThrowable()); + } else { + log.warn("Get unsupported LogLevelType: {}. Use {} as default", + errorData.getLogLevel(), LogLevel.ERROR); + log.error(errorData.getPreFormatedErrorMessage(), errorData.getThrowable()); + + } } else { - log.warn("Get unsupported LogLevelType: {}. Use {} as default", - errorData.getLogLevel(), LogLevel.ERROR); - log.error(errorData.getPreFormatedErrorMessage(), errorData.getThrowable()); + if (!(errorData.getThrowable() instanceof EaafException) + || LogLevel.ERROR.equals(errorData.getLogLevel())) { + log.error(errorData.getPreFormatedErrorMessage()); + + } else if (LogLevel.WARN.equals(errorData.getLogLevel())) { + log.warn(errorData.getPreFormatedErrorMessage()); + + } else if (LogLevel.INFO.equals(errorData.getLogLevel())) { + log.info(errorData.getPreFormatedErrorMessage()); + } else if (LogLevel.DEBUG.equals(errorData.getLogLevel())) { + log.debug(errorData.getPreFormatedErrorMessage()); + + } else { + log.warn("Get unsupported LogLevelType: {}. Use {} as default", + errorData.getLogLevel(), LogLevel.ERROR); + log.error(errorData.getPreFormatedErrorMessage()); + + } } } diff --git a/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/services/TicketErrorService.java b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/services/TicketErrorService.java index 39262f70..08fe2159 100644 --- a/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/services/TicketErrorService.java +++ b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/services/TicketErrorService.java @@ -85,6 +85,7 @@ public abstract class TicketErrorService implements IErrorService { return HandleData.builder() .throwable(throwable) + .writeThrowable(errorFlowConfig.getWriteThrowable()) .internalErrorCode(internalErrorId) .actionType(errorHandlingFlow) .logLevel(LogLevel.fromString(errorFlowConfig.getLogLevel())) @@ -260,6 +261,10 @@ public abstract class TicketErrorService implements IErrorService { private LogLevel logLevel; @Getter + @Builder.Default + private boolean writeThrowable = true; + + @Getter private Map<String, String> additionalGuiModelElements; public String getPreFormatedErrorMessage() { diff --git a/eaaf_core/src/test/java/at/gv/egiz/eaaf/core/impl/idp/auth/dummy/DummyDefaultErrorService.java b/eaaf_core/src/test/java/at/gv/egiz/eaaf/core/impl/idp/auth/dummy/DummyDefaultErrorService.java index ad7e9bdc..a331d382 100644 --- a/eaaf_core/src/test/java/at/gv/egiz/eaaf/core/impl/idp/auth/dummy/DummyDefaultErrorService.java +++ b/eaaf_core/src/test/java/at/gv/egiz/eaaf/core/impl/idp/auth/dummy/DummyDefaultErrorService.java @@ -107,6 +107,10 @@ public class DummyDefaultErrorService implements IErrorService { @Getter private LogLevel logLevel; + + @Getter + @Builder.Default + private boolean writeThrowable = true; @Getter private Map<String, String> additionalGuiModelElements; diff --git a/eaaf_core/src/test/java/at/gv/egiz/eaaf/core/impl/idp/auth/service/TicketErrorServiceTest.java b/eaaf_core/src/test/java/at/gv/egiz/eaaf/core/impl/idp/auth/service/TicketErrorServiceTest.java index d30f5a95..3391e109 100644 --- a/eaaf_core/src/test/java/at/gv/egiz/eaaf/core/impl/idp/auth/service/TicketErrorServiceTest.java +++ b/eaaf_core/src/test/java/at/gv/egiz/eaaf/core/impl/idp/auth/service/TicketErrorServiceTest.java @@ -34,6 +34,7 @@ import at.gv.egiz.eaaf.core.impl.idp.auth.dummy.DummyPendingRequest; import at.gv.egiz.eaaf.core.impl.idp.auth.services.IErrorService; import at.gv.egiz.eaaf.core.impl.idp.auth.services.IErrorService.LogLevel; import ch.qos.logback.classic.spi.ILoggingEvent; +import lombok.SneakyThrows; import lombok.val; @RunWith(SpringJUnit4ClassRunner.class) @@ -68,6 +69,26 @@ public class TicketErrorServiceTest { } @Test + @SneakyThrows + public void checkWriteThrowableFlag() { + + DummyPendingRequest pendingReq = new DummyPendingRequest(); + pendingReq.setPendingRequestId("324"); + pendingReq.setSpEntityId(RandomStringUtils.randomAlphabetic(5)); + + Assert.assertTrue(ticketErrorService.createHandleData(new EaafException("module.binding.14"), pendingReq) + .isWriteThrowable()); + + Assert.assertTrue(ticketErrorService.createHandleData(new EaafException("internal.pendingreqid.06"), + pendingReq) + .isWriteThrowable()); + + Assert.assertFalse(ticketErrorService.createHandleData(new EaafException("module.binding.33"), pendingReq) + .isWriteThrowable()); + + } + + @Test public void coverDifferentExceptions() throws EaafException { DummyPendingRequest pendingReq = new DummyPendingRequest(); diff --git a/eaaf_core/src/test/resources/config/error_conf.yaml b/eaaf_core/src/test/resources/config/error_conf.yaml index 0e204e97..0536624e 100644 --- a/eaaf_core/src/test/resources/config/error_conf.yaml +++ b/eaaf_core/src/test/resources/config/error_conf.yaml @@ -91,6 +91,7 @@ - action: no_ticket externalCode: 1200 logLevel: info + writeThrowable: false internalCode: - module.binding.33 - module.binding.34 @@ -99,6 +100,7 @@ - action: no_ticket externalCode: 9199 logLevel: WARN + writeThrowable: true internalCode: - module.binding.14 - module.binding.25 |