james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [james-project] 09/23: JAMES-2097 Logging for MockSMTP server
Date Fri, 06 Sep 2019 02:02:00 GMT
This is an automated email from the ASF dual-hosted git repository.

btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 1ef2900dd9aaca839ae6933b2a93527be11e8f18
Author: Benoit Tellier <btellier@linagora.com>
AuthorDate: Tue Sep 3 17:12:17 2019 +0700

    JAMES-2097 Logging for MockSMTP server
---
 server/mailet/mock-smtp-server/pom.xml                 |  5 +++++
 .../james/mock/smtp/server/MockMessageHandler.java     | 11 +++++++++--
 .../mailet/mock-smtp-server/src/resources/logback.xml  | 18 ++++++++++++++++++
 3 files changed, 32 insertions(+), 2 deletions(-)

diff --git a/server/mailet/mock-smtp-server/pom.xml b/server/mailet/mock-smtp-server/pom.xml
index 7d91561..d371982 100644
--- a/server/mailet/mock-smtp-server/pom.xml
+++ b/server/mailet/mock-smtp-server/pom.xml
@@ -55,6 +55,11 @@
             <scope>test</scope>
         </dependency>
         <dependency>
+            <groupId>ch.qos.logback</groupId>
+            <artifactId>logback-classic</artifactId>
+            <scope>runtime</scope>
+        </dependency>
+        <dependency>
             <groupId>com.fasterxml.jackson.core</groupId>
             <artifactId>jackson-databind</artifactId>
         </dependency>
diff --git a/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/MockMessageHandler.java
b/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/MockMessageHandler.java
index ff2558e..10a09ec 100644
--- a/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/MockMessageHandler.java
+++ b/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/MockMessageHandler.java
@@ -34,12 +34,15 @@ import org.apache.james.mock.smtp.server.model.MockSMTPBehaviorInformation;
 import org.apache.james.mock.smtp.server.model.Response;
 import org.apache.james.mock.smtp.server.model.Response.SMTPStatusCode;
 import org.apache.james.mock.smtp.server.model.SMTPCommand;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.subethamail.smtp.MessageHandler;
 import org.subethamail.smtp.RejectException;
-import org.subethamail.smtp.TooMuchDataException;
 
 public class MockMessageHandler implements MessageHandler {
 
+    private static final Logger LOGGER = LoggerFactory.getLogger(MockMessageHandler.class);
+
     @FunctionalInterface
     private interface Behavior<T> {
         void behave(T input) throws RejectException;
@@ -55,6 +58,7 @@ public class MockMessageHandler implements MessageHandler {
         @Override
         public void behave(T input) throws RejectException {
             Response response = behavior.getResponse();
+            LOGGER.info("Applying behavior {}", behavior);
             throw new RejectException(response.getCode().getRawCode(), response.getMessage());
         }
     }
@@ -125,7 +129,7 @@ public class MockMessageHandler implements MessageHandler {
     }
 
     @Override
-    public void data(InputStream data) throws RejectException, TooMuchDataException, IOException
{
+    public void data(InputStream data) throws RejectException {
         String dataString = readData(data);
         Optional<Behavior<String>> dataBehavior = firstMatchedBehavior(SMTPCommand.DATA,
dataString);
 
@@ -149,12 +153,14 @@ public class MockMessageHandler implements MessageHandler {
         Mail mail = mailBuilder.envelope(envelopeBuilder.build())
             .build();
         mailRepository.store(mail);
+        LOGGER.info("Storing mail with envelope {}", mail.getEnvelope());
     }
 
     private String readData(InputStream data) {
         try {
             return IOUtils.toString(data, StandardCharsets.UTF_8);
         } catch (IOException e) {
+            LOGGER.error("Error reading data", e);
             throw new RejectException(SMTPStatusCode.SYNTAX_ERROR_IN_PARAMETERS_OR_ARGUMENTS_501.getRawCode(),
"invalid data supplied");
         }
     }
@@ -163,6 +169,7 @@ public class MockMessageHandler implements MessageHandler {
         try {
             return new MailAddress(mailAddress);
         } catch (AddressException e) {
+            LOGGER.error("Error parsing mail address '{}'", mailAddress, e);
             throw new RejectException(SMTPStatusCode.SYNTAX_ERROR_IN_PARAMETERS_OR_ARGUMENTS_501.getRawCode(),
"invalid email address supplied");
         }
     }
diff --git a/server/mailet/mock-smtp-server/src/resources/logback.xml b/server/mailet/mock-smtp-server/src/resources/logback.xml
new file mode 100644
index 0000000..f9c4a22
--- /dev/null
+++ b/server/mailet/mock-smtp-server/src/resources/logback.xml
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<configuration>
+
+        <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
+                <encoder>
+                        <pattern>%d{HH:mm:ss.SSS} %highlight([%-5level]) %logger{15}
- %msg%n%rEx</pattern>
+                        <immediateFlush>false</immediateFlush>
+                </encoder>
+        </appender>
+
+        <root level="WARN">
+                <appender-ref ref="CONSOLE" />
+        </root>
+
+        <logger name="org.apache.james.mock.smtp.server" level="DEBUG"/>
+        <logger name="org.subethamail.smtp" level="DEBUG"/>
+
+</configuration>


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Mime
View raw message