You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@james.apache.org by bt...@apache.org on 2021/10/29 15:25:24 UTC
[james-project] 02/03: http GET for mock email count
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 7438614a114442459a73b1bf1a30871da8054de6
Author: Szabolcs Szucs <sz...@patientsknowbest.com>
AuthorDate: Wed Oct 27 22:57:16 2021 +0200
http GET for mock email count
---
.../james/mock/smtp/server/HTTPConfigurationServer.java | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/HTTPConfigurationServer.java b/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/HTTPConfigurationServer.java
index 957332c..330d617 100644
--- a/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/HTTPConfigurationServer.java
+++ b/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/HTTPConfigurationServer.java
@@ -98,6 +98,7 @@ public class HTTPConfigurationServer {
static final String SMTP_EXTENSIONS = "/smtpExtensions";
static final String VERSION = "/version";
static final String SMTP_MAILS = "/smtpMails";
+ static final String SMTP_MAILS_COUNT = "/smtpMailsCount";
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper()
.registerModule(new Jdk8Module())
@@ -140,6 +141,7 @@ public class HTTPConfigurationServer {
.delete(SMTP_BEHAVIORS, this::deleteBehaviors)
.delete(SMTP_EXTENSIONS, this::deleteExtensions)
.get(SMTP_MAILS, this::getMails)
+ .get(SMTP_MAILS_COUNT, this::getMailsCount)
.delete(SMTP_MAILS, this::deleteMails))
.bindNow());
}
@@ -240,4 +242,17 @@ public class HTTPConfigurationServer {
return res.status(INTERNAL_SERVER_ERROR).send();
}
}
+
+ private Publisher<Void> getMailsCount(HttpServerRequest req, HttpServerResponse res) {
+ var count = receivedMailRepository.list().stream().count();
+
+ try {
+ return res.status(OK)
+ .header(CONTENT_TYPE, APPLICATION_JSON)
+ .sendString(Mono.just(OBJECT_MAPPER.writeValueAsString(count)));
+ } catch (JsonProcessingException e) {
+ LOGGER.error("Could not serialize JSON", e);
+ return res.status(INTERNAL_SERVER_ERROR).send();
+ }
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org