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/11/01 12:34:26 UTC
[james-project] 02/03: JAMES-3539 MethodWithoutAccountId
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 937677ead39808bbffa7613a67e18ebddbe5f815
Author: Tung Van TRAN <vt...@linagora.com>
AuthorDate: Fri Oct 29 16:44:03 2021 +0700
JAMES-3539 MethodWithoutAccountId
---
.../org/apache/james/jmap/method/Method.scala | 38 ++++++++++++++++++++++
1 file changed, 38 insertions(+)
diff --git a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/Method.scala b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/Method.scala
index 4ae95d3..71f0ae3 100644
--- a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/Method.scala
+++ b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/Method.scala
@@ -102,3 +102,41 @@ trait MethodRequiringAccountId[REQUEST <: WithAccountId] extends Method {
def getRequest(mailboxSession: MailboxSession, invocation: Invocation): Either[Exception, REQUEST]
}
+
+trait WithoutAccountId {
+}
+
+trait MethodWithoutAccountId[REQUEST <: WithoutAccountId] extends Method {
+ def metricFactory: MetricFactory
+
+ def sessionSupplier: SessionSupplier
+
+ override def process(capabilities: Set[CapabilityIdentifier], invocation: InvocationWithContext, mailboxSession: MailboxSession): Publisher[InvocationWithContext] = {
+ val either: Either[Exception, Publisher[InvocationWithContext]] = for {
+ request <- getRequest(invocation.invocation)
+ } yield {
+ doProcess(invocation, mailboxSession, request)
+ }
+
+ val result: SFlux[InvocationWithContext] = SFlux.fromPublisher(either.fold(e => SFlux.error[InvocationWithContext](e), r => r))
+ .onErrorResume[InvocationWithContext] {
+ case e: UnsupportedRequestParameterException => SFlux.just[InvocationWithContext](InvocationWithContext(Invocation.error(
+ ErrorCode.InvalidArguments,
+ s"The following parameter ${e.unsupportedParam} is syntactically valid, but is not supported by the server.",
+ invocation.invocation.methodCallId), invocation.processingContext))
+ case e: UnsupportedNestingException => SFlux.just[InvocationWithContext](InvocationWithContext(Invocation.error(
+ ErrorCode.UnsupportedFilter,
+ description = e.message,
+ invocation.invocation.methodCallId), invocation.processingContext))
+ case e: IllegalArgumentException => SFlux.just[InvocationWithContext](InvocationWithContext(Invocation.error(ErrorCode.InvalidArguments, e.getMessage, invocation.invocation.methodCallId), invocation.processingContext))
+ case e: RequestTooLargeException => SFlux.just[InvocationWithContext](InvocationWithContext(Invocation.error(ErrorCode.RequestTooLarge, e.description, invocation.invocation.methodCallId), invocation.processingContext))
+ case e: Throwable => SFlux.error[InvocationWithContext](e)
+ }
+
+ metricFactory.decoratePublisherWithTimerMetric(JMAP_RFC8621_PREFIX + methodName.value, result)
+ }
+
+ def getRequest(invocation: Invocation): Either[Exception, REQUEST]
+
+ def doProcess(invocation: InvocationWithContext, mailboxSession: MailboxSession, request: REQUEST): Publisher[InvocationWithContext]
+}
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org