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/04/09 12:01:52 UTC

[james-project] branch master updated: JAMES-3554 JMAP: remove pushState field from Server Sent Events

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


The following commit(s) were added to refs/heads/master by this push:
     new f119aab  JAMES-3554 JMAP: remove pushState field from Server Sent Events
f119aab is described below

commit f119aab441682ff60cb12305bca0b744c5258916
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Tue Apr 6 23:15:35 2021 +0700

    JAMES-3554 JMAP: remove pushState field from Server Sent Events
---
 .../james/jmap/rfc8621/contract/EventSourceContract.scala    |  1 +
 .../org/apache/james/jmap/json/ResponseSerializer.scala      | 12 ++++++++++++
 .../org/apache/james/jmap/routes/EventSourceRoutes.scala     |  2 +-
 3 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/EventSourceContract.scala b/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/EventSourceContract.scala
index 032afca..37d8da6 100644
--- a/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/EventSourceContract.scala
+++ b/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/EventSourceContract.scala
@@ -255,6 +255,7 @@ trait EventSourceContract {
       .hasSize(1)
     assertThat(seq.head)
       .startsWith("event: state\ndata: {\"@type\":\"StateChange\",\"changed\":{\"29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6\":{\"Mailbox\":")
+    assertThat(seq.head).doesNotContain("pushState")
     assertThat(seq.head).endsWith("\n\n")
   }
 
diff --git a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/json/ResponseSerializer.scala b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/json/ResponseSerializer.scala
index 0c40307..143146c 100644
--- a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/json/ResponseSerializer.scala
+++ b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/json/ResponseSerializer.scala
@@ -197,6 +197,10 @@ object ResponseSerializer {
         JsObject(Map(
           "@type" -> JsString("StateChange"),
           "changed" -> changeWrites.writes(stateChange.changes))))
+  private val stateChangeWritesNoPushState: Writes[StateChange] = stateChange =>
+      JsObject(Map(
+        "@type" -> JsString("StateChange"),
+        "changed" -> changeWrites.writes(stateChange.changes)))
 
   private implicit val webSocketResponseWrites: Writes[WebSocketResponse] = response => {
     val apiResponseJson: JsObject = responseObjectFormat.writes(response.responseObject)
@@ -219,6 +223,12 @@ object ResponseSerializer {
     case response: WebSocketResponse => webSocketResponseWrites.writes(response)
     case error: WebSocketError => webSocketErrorWrites.writes(error)
   }
+  private val sseOutboundWrites: Writes[OutboundMessage] = {
+    case pingMessage: PingMessage => pingWrites.writes(pingMessage)
+    case stateChange: StateChange => stateChangeWritesNoPushState.writes(stateChange)
+    case response: WebSocketResponse => webSocketResponseWrites.writes(response)
+    case error: WebSocketError => webSocketErrorWrites.writes(error)
+  }
 
   def serialize(session: Session): JsValue = Json.toJson(session)
 
@@ -232,6 +242,8 @@ object ResponseSerializer {
 
   def serialize(outboundMessage: OutboundMessage): JsValue = Json.toJson(outboundMessage)
 
+  def serializeSSE(outboundMessage: OutboundMessage): JsValue = sseOutboundWrites.writes(outboundMessage)
+
   def deserializeRequestObject(input: String): JsResult[RequestObject] = Json.parse(input).validate[RequestObject]
 
   def deserializeWebSocketInboundMessage(input: String): JsResult[WebSocketInboundMessage] = Try(Json.parse(input).validate[WebSocketInboundMessage])
diff --git a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/routes/EventSourceRoutes.scala b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/routes/EventSourceRoutes.scala
index 16a8797..4439a17 100644
--- a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/routes/EventSourceRoutes.scala
+++ b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/routes/EventSourceRoutes.scala
@@ -213,7 +213,7 @@ class EventSourceRoutes@Inject() (@Named(InjectionKeys.RFC_8621) val authenticat
       case _: PingMessage => "ping"
       case _: StateChange => "state"
     }
-    s"event: $event\ndata: ${Json.stringify(ResponseSerializer.serialize(outboundMessage))}\n\n"
+    s"event: $event\ndata: ${Json.stringify(ResponseSerializer.serializeSSE(outboundMessage))}\n\n"
   }
 
   private def handleConnectionEstablishmentError(throwable: Throwable, response: HttpServerResponse): SMono[Void] = throwable match {

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