james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From matth...@apache.org
Subject svn commit: r1719368 - in /james/project/trunk/server/protocols/jmap/src: main/java/org/apache/james/jmap/methods/ main/java/org/apache/james/jmap/model/ test/java/org/apache/james/jmap/methods/
Date Fri, 11 Dec 2015 12:30:36 GMT
Author: matthieu
Date: Fri Dec 11 12:30:35 2015
New Revision: 1719368

URL: http://svn.apache.org/viewvc?rev=1719368&view=rev
Log:
JAMES-1644 JmapResponse is now a class and the Method Response is an Object inside

	We don't care about response typing as we use Jackson serialization
	for this purpose. It allows to create an actual container that
	borrows generic informations like ClientId or Method (as a String)

Modified:
    james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMailboxesMethod.java
    james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/JmapResponse.java
    james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/JmapResponseWriter.java
    james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/JmapResponseWriterImpl.java
    james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/GetMailboxesResponse.java
    james/project/trunk/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/JmapResponseWriterImplTest.java
    james/project/trunk/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/RequestHandlerTest.java

Modified: james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMailboxesMethod.java
URL: http://svn.apache.org/viewvc/james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMailboxesMethod.java?rev=1719368&r1=1719367&r2=1719368&view=diff
==============================================================================
--- james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMailboxesMethod.java
(original)
+++ james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMailboxesMethod.java
Fri Dec 11 12:30:35 2015
@@ -25,6 +25,7 @@ import java.util.Optional;
 import javax.inject.Inject;
 
 import org.apache.commons.lang.NotImplementedException;
+import org.apache.james.jmap.methods.JmapResponse.Builder;
 import org.apache.james.jmap.model.AuthenticatedProtocolRequest;
 import org.apache.james.jmap.model.GetMailboxesRequest;
 import org.apache.james.jmap.model.GetMailboxesResponse;
@@ -69,6 +70,7 @@ public class GetMailboxesMethod<Id exten
     }
 
     public ProtocolResponse process(AuthenticatedProtocolRequest request) {
+        Builder responseBuilder = JmapResponse.forRequest(request);
         try {
             jmapRequestParser.extractJmapRequest(request, GetMailboxesRequest.class);
         } catch (IOException e) {
@@ -81,8 +83,8 @@ public class GetMailboxesMethod<Id exten
         
         try {
             MailboxSession mailboxSession = request.getMailboxSession();
-            GetMailboxesResponse mailboxesResponse = getMailboxesResponse(mailboxSession);
-            return jmapResponseWriter.formatMethodResponse(request, mailboxesResponse);
+            responseBuilder.response(getMailboxesResponse(mailboxSession));
+            return jmapResponseWriter.formatMethodResponse(responseBuilder.build());
         } catch (MailboxException e) {
             return jmapResponseWriter.formatErrorResponse(request);
         }

Modified: james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/JmapResponse.java
URL: http://svn.apache.org/viewvc/james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/JmapResponse.java?rev=1719368&r1=1719367&r2=1719368&view=diff
==============================================================================
--- james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/JmapResponse.java
(original)
+++ james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/JmapResponse.java
Fri Dec 11 12:30:35 2015
@@ -19,6 +19,67 @@
 
 package org.apache.james.jmap.methods;
 
-public interface JmapResponse {
+import org.apache.james.jmap.model.ClientId;
+import org.apache.james.jmap.model.ProtocolRequest;
 
+public class JmapResponse {
+
+    public static Builder builder() {
+        return new Builder();
+    }
+    
+    public static Builder forRequest(ProtocolRequest request) {
+        return builder().clientId(request.getClientId()).method(request.getMethod());
+    }
+    
+    public static class Builder {
+        
+        private String method;
+        private ClientId id;
+        private Object response;
+
+        private Builder() {
+        }
+
+        public Builder method(String method) {
+            this.method = method;
+            return this;
+        }
+        
+        public Builder clientId(ClientId id) {
+            this.id = id;
+            return this;
+        }
+        
+        public Builder response(Object response) {
+            this.response = response;
+            return this;
+        }
+        
+        public JmapResponse build() {
+            return new JmapResponse(method, id, response);
+        }
+    }
+    
+    private final String method;
+    private final ClientId clientId;
+    private final Object response;
+    
+    private JmapResponse(String method, ClientId clientId, Object response) {
+        this.method = method;
+        this.clientId = clientId;
+        this.response = response;
+    }
+
+    public String getMethod() {
+        return method;
+    }
+    
+    public Object getResponse() {
+        return response;
+    }
+    
+    public ClientId getClientId() {
+        return clientId;
+    }
 }

Modified: james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/JmapResponseWriter.java
URL: http://svn.apache.org/viewvc/james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/JmapResponseWriter.java?rev=1719368&r1=1719367&r2=1719368&view=diff
==============================================================================
--- james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/JmapResponseWriter.java
(original)
+++ james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/JmapResponseWriter.java
Fri Dec 11 12:30:35 2015
@@ -24,7 +24,7 @@ import org.apache.james.jmap.model.Proto
 
 public interface JmapResponseWriter {
 
-    ProtocolResponse formatMethodResponse(ProtocolRequest request, JmapResponse jmapResponse);
+    ProtocolResponse formatMethodResponse(JmapResponse jmapResponse);
 
     ProtocolResponse formatErrorResponse(ProtocolRequest request);
 

Modified: james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/JmapResponseWriterImpl.java
URL: http://svn.apache.org/viewvc/james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/JmapResponseWriterImpl.java?rev=1719368&r1=1719367&r2=1719368&view=diff
==============================================================================
--- james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/JmapResponseWriterImpl.java
(original)
+++ james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/JmapResponseWriterImpl.java
Fri Dec 11 12:30:35 2015
@@ -45,9 +45,11 @@ public class JmapResponseWriterImpl impl
     }
 
     @Override
-    public ProtocolResponse formatMethodResponse(ProtocolRequest request, JmapResponse jmapResponse)
{
-        ObjectNode objectNode = objectMapper.valueToTree(jmapResponse);
-        return new ProtocolResponse(request.getMethod(), objectNode, request.getClientId());
+    public ProtocolResponse formatMethodResponse(JmapResponse jmapResponse) {
+        return new ProtocolResponse(
+                jmapResponse.getMethod(), 
+                objectMapper.valueToTree(jmapResponse.getResponse()), 
+                jmapResponse.getClientId());
     }
 
     @Override

Modified: james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/GetMailboxesResponse.java
URL: http://svn.apache.org/viewvc/james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/GetMailboxesResponse.java?rev=1719368&r1=1719367&r2=1719368&view=diff
==============================================================================
--- james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/GetMailboxesResponse.java
(original)
+++ james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/GetMailboxesResponse.java
Fri Dec 11 12:30:35 2015
@@ -22,11 +22,10 @@ import java.util.List;
 import java.util.Optional;
 
 import org.apache.commons.lang.NotImplementedException;
-import org.apache.james.jmap.methods.JmapResponse;
 
 import com.google.common.collect.ImmutableList;
 
-public class GetMailboxesResponse implements JmapResponse {
+public class GetMailboxesResponse {
 
     public static Builder builder() {
         return new Builder();

Modified: james/project/trunk/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/JmapResponseWriterImplTest.java
URL: http://svn.apache.org/viewvc/james/project/trunk/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/JmapResponseWriterImplTest.java?rev=1719368&r1=1719367&r2=1719368&view=diff
==============================================================================
--- james/project/trunk/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/JmapResponseWriterImplTest.java
(original)
+++ james/project/trunk/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/JmapResponseWriterImplTest.java
Fri Dec 11 12:30:35 2015
@@ -49,7 +49,11 @@ public class JmapResponseWriterImplTest
                 new ObjectNode(new JsonNodeFactory(false)).textNode(expectedClientId)} ;
 
         JmapResponseWriterImpl jmapResponseWriterImpl = new JmapResponseWriterImpl(ImmutableSet.of(new
Jdk8Module()));
-        ProtocolResponse response = jmapResponseWriterImpl.formatMethodResponse(ProtocolRequest.deserialize(nodes),
null);
+        ProtocolRequest request = ProtocolRequest.deserialize(nodes);
+        ProtocolResponse response = jmapResponseWriterImpl.formatMethodResponse(JmapResponse
+                .forRequest(request)
+                .response(null)
+                .build());
 
         assertThat(response.getMethod()).isEqualTo(expectedMethod);
         assertThat(response.getResults().findValue("id").asText()).isEqualTo(expectedId);
@@ -72,14 +76,18 @@ public class JmapResponseWriterImplTest
         responseClass.id = expectedId;
 
         JmapResponseWriterImpl jmapResponseWriterImpl = new JmapResponseWriterImpl(ImmutableSet.of(new
Jdk8Module()));
-        ProtocolResponse response = jmapResponseWriterImpl.formatMethodResponse(ProtocolRequest.deserialize(nodes),
responseClass);
+        ProtocolResponse response = jmapResponseWriterImpl.formatMethodResponse(
+                JmapResponse
+                .forRequest(ProtocolRequest.deserialize(nodes))
+                .response(responseClass)
+                .build());
 
         assertThat(response.getMethod()).isEqualTo(expectedMethod);
         assertThat(response.getResults().findValue("id").asText()).isEqualTo(expectedId);
         assertThat(response.getClientId()).isEqualTo(ClientId.of(expectedClientId));
     }
 
-    private static class ResponseClass implements JmapResponse {
+    private static class ResponseClass {
 
         @SuppressWarnings("unused")
         public String id;

Modified: james/project/trunk/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/RequestHandlerTest.java
URL: http://svn.apache.org/viewvc/james/project/trunk/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/RequestHandlerTest.java?rev=1719368&r1=1719367&r2=1719368&view=diff
==============================================================================
--- james/project/trunk/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/RequestHandlerTest.java
(original)
+++ james/project/trunk/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/RequestHandlerTest.java
Fri Dec 11 12:30:35 2015
@@ -55,7 +55,7 @@ public class RequestHandlerTest {
         }
     }
 
-    public static class TestJmapResponse implements JmapResponse {
+    public static class TestJmapResponse {
 
         private final String id;
         private final String name;
@@ -100,8 +100,11 @@ public class RequestHandlerTest {
         public ProtocolResponse process(AuthenticatedProtocolRequest request) {
             try {
                 TestJmapRequest typedRequest = jmapRequestParser.extractJmapRequest(request,
TestJmapRequest.class);
-                return jmapResponseWriter.formatMethodResponse(request, 
-                        new TestJmapResponse(typedRequest.getId(), typedRequest.getName(),
"works"));
+                return jmapResponseWriter.formatMethodResponse(
+                            JmapResponse
+                                .forRequest(request)
+                                .response(new TestJmapResponse(typedRequest.getId(), typedRequest.getName(),
"works"))
+                                .build());
             } catch (IOException e) {
                 return jmapResponseWriter.formatErrorResponse(request);
             }



---------------------------------------------------------------------
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