You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by rg...@apache.org on 2018/09/30 16:51:08 UTC

[5/9] logging-log4j-audit git commit: [LOG4J2-2443] Consistent throwning of ConstraintValidationException for valitation errors

[LOG4J2-2443] Consistent throwning of ConstraintValidationException for valitation errors


Project: http://git-wip-us.apache.org/repos/asf/logging-log4j-audit/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j-audit/commit/bf545f37
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j-audit/tree/bf545f37
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j-audit/diff/bf545f37

Branch: refs/heads/master
Commit: bf545f37122cd080d17278f8516e2091a04c75fa
Parents: 13f0581
Author: Andrei Ivanov <an...@arnia.ro>
Authored: Sun Sep 16 16:31:09 2018 +0300
Committer: Andrei Ivanov <an...@arnia.ro>
Committed: Sun Sep 16 16:31:09 2018 +0300

----------------------------------------------------------------------
 .../org/apache/logging/log4j/audit/AbstractEventLogger.java | 9 +++++----
 .../org/apache/logging/log4j/audit/AuditLoggerTest.java     | 4 ++--
 2 files changed, 7 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j-audit/blob/bf545f37/log4j-audit/log4j-audit-api/src/main/java/org/apache/logging/log4j/audit/AbstractEventLogger.java
----------------------------------------------------------------------
diff --git a/log4j-audit/log4j-audit-api/src/main/java/org/apache/logging/log4j/audit/AbstractEventLogger.java b/log4j-audit/log4j-audit-api/src/main/java/org/apache/logging/log4j/audit/AbstractEventLogger.java
index da2254a..8f9a5e6 100644
--- a/log4j-audit/log4j-audit-api/src/main/java/org/apache/logging/log4j/audit/AbstractEventLogger.java
+++ b/log4j-audit/log4j-audit-api/src/main/java/org/apache/logging/log4j/audit/AbstractEventLogger.java
@@ -25,6 +25,7 @@ import org.apache.logging.log4j.catalog.api.Attribute;
 import org.apache.logging.log4j.catalog.api.Constraint;
 import org.apache.logging.log4j.catalog.api.Event;
 import org.apache.logging.log4j.catalog.api.EventAttribute;
+import org.apache.logging.log4j.catalog.api.exception.ConstraintValidationException;
 import org.apache.logging.log4j.catalog.api.plugins.ConstraintPlugins;
 import org.apache.logging.log4j.message.StructuredDataMessage;
 
@@ -146,7 +147,7 @@ public abstract class AbstractEventLogger {
             errors.append("Event ").append(eventName).append(" is missing required attribute(s) ").append(missingAttributes.toString());
         }
         if (errors.length() > 0) {
-            throw new AuditException(errors.toString());
+            throw new ConstraintValidationException(errors.toString());
         }
         List<String> attributeNames = catalogManager.getAttributeNames(eventName, event.getCatalogId());
         StringBuilder buf = new StringBuilder();
@@ -159,7 +160,7 @@ public abstract class AbstractEventLogger {
             }
         }
         if (buf.length() > 0) {
-            throw new AuditException("Event " + eventName + " contains invalid attribute(s) " + buf.toString());
+            throw new ConstraintValidationException("Event " + eventName + " contains invalid attribute(s) " + buf.toString());
         }
 
         List<String> reqCtxAttrs = catalogManager.getRequiredContextAttributes(eventName, event.getCatalogId());
@@ -175,7 +176,7 @@ public abstract class AbstractEventLogger {
                 }
             }
             if (sb.length() > 0) {
-                throw new IllegalStateException("Event " + msg.getId().getName() +
+                throw new ConstraintValidationException("Event " + msg.getId().getName() +
                         " is missing required RequestContextMapping values for " + sb.toString());
             }
         }
@@ -193,7 +194,7 @@ public abstract class AbstractEventLogger {
             }
         }
         if (errors.length() > 0) {
-            throw new AuditException("Event " + eventName + " has incorrect data in the Thread Context: " + errors.toString());
+            throw new ConstraintValidationException("Event " + eventName + " has incorrect data in the Thread Context: " + errors.toString());
         }
         msg.putAll(attributes);
         try {

http://git-wip-us.apache.org/repos/asf/logging-log4j-audit/blob/bf545f37/log4j-audit/log4j-audit-api/src/test/java/org/apache/logging/log4j/audit/AuditLoggerTest.java
----------------------------------------------------------------------
diff --git a/log4j-audit/log4j-audit-api/src/test/java/org/apache/logging/log4j/audit/AuditLoggerTest.java b/log4j-audit/log4j-audit-api/src/test/java/org/apache/logging/log4j/audit/AuditLoggerTest.java
index abe6eb8..0749829 100644
--- a/log4j-audit/log4j-audit-api/src/test/java/org/apache/logging/log4j/audit/AuditLoggerTest.java
+++ b/log4j-audit/log4j-audit-api/src/test/java/org/apache/logging/log4j/audit/AuditLoggerTest.java
@@ -22,7 +22,7 @@ import org.apache.logging.log4j.audit.catalog.CatalogManager;
 import org.apache.logging.log4j.audit.catalog.CatalogManagerImpl;
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.audit.catalog.StringCatalogReader;
-import org.apache.logging.log4j.audit.exception.AuditException;
+import org.apache.logging.log4j.catalog.api.exception.ConstraintValidationException;
 import org.apache.logging.log4j.core.Appender;
 import org.apache.logging.log4j.core.LoggerContext;
 import org.apache.logging.log4j.core.config.Configuration;
@@ -99,7 +99,7 @@ public class AuditLoggerTest {
         assertTrue("No toAccount", msg.contains("toAccount=\"123456\""));
     }
 
-    @Test(expected = AuditException.class)
+    @Test(expected = ConstraintValidationException.class)
     public void testBadAttribute() {
         ThreadContext.put("companyId", "12345");
         ThreadContext.put("ipAddress", "127.0.0.1");