Author: matthieu
Date: Fri Dec 11 10:09:01 2015
New Revision: 1719325

URL: http://svn.apache.org/viewvc?rev=1719325&view=rev
Log:
JAMES-1644 Add JMAP module in cassandra-guice

Added:
    
james/project/trunk/server/container/cassandra-guice/src/main/java/org/apache/james/modules/protocols/JMAPServerModule.java
Modified:
    james/project/trunk/server/container/cassandra-guice/pom.xml
    
james/project/trunk/server/container/cassandra-guice/src/main/java/org/apache/james/CassandraJamesServerMain.java
    
james/project/trunk/server/container/cassandra-guice/src/test/java/org/apache/james/CassandraJamesServerTest.java

Modified: james/project/trunk/server/container/cassandra-guice/pom.xml
URL: 
http://svn.apache.org/viewvc/james/project/trunk/server/container/cassandra-guice/pom.xml?rev=1719325&r1=1719324&r2=1719325&view=diff
==============================================================================
--- james/project/trunk/server/container/cassandra-guice/pom.xml (original)
+++ james/project/trunk/server/container/cassandra-guice/pom.xml Fri Dec 11 
10:09:01 2015
@@ -369,6 +369,12 @@
                     <artifactId>awaitility</artifactId>
                 </dependency>
                 <dependency>
+                    <groupId>com.jayway.restassured</groupId>
+                    <artifactId>rest-assured</artifactId>
+                    <version>2.5.0</version>
+                    <scope>test</scope>
+                </dependency>
+                <dependency>
                     <groupId>commons-daemon</groupId>
                     <artifactId>commons-daemon</artifactId>
                 </dependency>

Modified: 
james/project/trunk/server/container/cassandra-guice/src/main/java/org/apache/james/CassandraJamesServerMain.java
URL: 
http://svn.apache.org/viewvc/james/project/trunk/server/container/cassandra-guice/src/main/java/org/apache/james/CassandraJamesServerMain.java?rev=1719325&r1=1719324&r2=1719325&view=diff
==============================================================================
--- 
james/project/trunk/server/container/cassandra-guice/src/main/java/org/apache/james/CassandraJamesServerMain.java
 (original)
+++ 
james/project/trunk/server/container/cassandra-guice/src/main/java/org/apache/james/CassandraJamesServerMain.java
 Fri Dec 11 10:09:01 2015
@@ -27,6 +27,7 @@ import org.apache.james.modules.mailbox.
 import org.apache.james.modules.mailbox.CassandraSessionModule;
 import org.apache.james.modules.mailbox.ElasticSearchMailboxModule;
 import org.apache.james.modules.protocols.IMAPServerModule;
+import org.apache.james.modules.protocols.JMAPServerModule;
 import org.apache.james.modules.protocols.LMTPServerModule;
 import org.apache.james.modules.protocols.POP3ServerModule;
 import org.apache.james.modules.protocols.ProtocolHandlerModule;
@@ -66,7 +67,8 @@ public class CassandraJamesServerMain {
             new MailStoreRepositoryModule(),
             new CamelMailetContainerModule(),
             new QuotaModule(),
-            new ConfigurationProviderModule());
+            new ConfigurationProviderModule(),
+            new JMAPServerModule());
 
     public static void main(String[] args) throws Exception {
         CassandraJamesServer server = new CassandraJamesServer(Modules.combine(

Added: 
james/project/trunk/server/container/cassandra-guice/src/main/java/org/apache/james/modules/protocols/JMAPServerModule.java
URL: 
http://svn.apache.org/viewvc/james/project/trunk/server/container/cassandra-guice/src/main/java/org/apache/james/modules/protocols/JMAPServerModule.java?rev=1719325&view=auto
==============================================================================
--- 
james/project/trunk/server/container/cassandra-guice/src/main/java/org/apache/james/modules/protocols/JMAPServerModule.java
 (added)
+++ 
james/project/trunk/server/container/cassandra-guice/src/main/java/org/apache/james/modules/protocols/JMAPServerModule.java
 Fri Dec 11 10:09:01 2015
@@ -0,0 +1,60 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.modules.protocols;
+
+import org.apache.james.jmap.JMAPModule;
+import org.apache.james.jmap.JMAPServer;
+import org.apache.james.jmap.crypto.JamesSignatureHandler;
+import org.apache.james.utils.ConfigurationPerformer;
+
+import com.google.inject.AbstractModule;
+import com.google.inject.Inject;
+import com.google.inject.Singleton;
+import com.google.inject.multibindings.Multibinder;
+
+public class JMAPServerModule extends AbstractModule {
+
+    @Override
+    protected void configure() {
+        install(new JMAPModule());
+        Multibinder.newSetBinder(binder(), 
ConfigurationPerformer.class).addBinding().to(JMAPModuleConfigurationPerformer.class);
+    }
+
+    @Singleton
+    public static class JMAPModuleConfigurationPerformer implements 
ConfigurationPerformer {
+
+        private final JMAPServer server;
+        private final JamesSignatureHandler signatureHandler;
+
+        @Inject
+        public JMAPModuleConfigurationPerformer(JMAPServer server, 
JamesSignatureHandler signatureHandler) {
+            this.server = server;
+            this.signatureHandler = signatureHandler;
+        }
+
+        @Override
+        public void initModule() throws Exception {
+            signatureHandler.configure(null);
+            signatureHandler.init();
+            server.configure(null);
+        }
+    }
+
+}

Modified: 
james/project/trunk/server/container/cassandra-guice/src/test/java/org/apache/james/CassandraJamesServerTest.java
URL: 
http://svn.apache.org/viewvc/james/project/trunk/server/container/cassandra-guice/src/test/java/org/apache/james/CassandraJamesServerTest.java?rev=1719325&r1=1719324&r2=1719325&view=diff
==============================================================================
--- 
james/project/trunk/server/container/cassandra-guice/src/test/java/org/apache/james/CassandraJamesServerTest.java
 (original)
+++ 
james/project/trunk/server/container/cassandra-guice/src/test/java/org/apache/james/CassandraJamesServerTest.java
 Fri Dec 11 10:09:01 2015
@@ -18,6 +18,9 @@
  ****************************************************************/
 package org.apache.james;
 
+import static com.jayway.restassured.RestAssured.given;
+import static com.jayway.restassured.config.EncoderConfig.encoderConfig;
+import static com.jayway.restassured.config.RestAssuredConfig.newConfig;
 import static org.assertj.core.api.Assertions.assertThat;
 
 import java.io.IOException;
@@ -31,6 +34,7 @@ import org.apache.james.backends.cassand
 import org.apache.james.mailbox.elasticsearch.EmbeddedElasticSearch;
 import org.apache.james.modules.TestElasticSearchModule;
 import org.apache.james.modules.TestFilesystemModule;
+import org.apache.james.modules.TestJMAPServerModule;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Rule;
@@ -38,10 +42,13 @@ import org.junit.Test;
 import org.junit.rules.RuleChain;
 import org.junit.rules.TemporaryFolder;
 
+import com.google.common.base.Charsets;
 import com.google.inject.AbstractModule;
 import com.google.inject.Provides;
 import com.google.inject.Singleton;
 import com.google.inject.util.Modules;
+import com.jayway.restassured.RestAssured;
+import com.jayway.restassured.http.ContentType;
 
 public class CassandraJamesServerTest {
 
@@ -50,6 +57,7 @@ public class CassandraJamesServerTest {
     private static final int POP3_PORT = 1110;
     private static final int SMTP_PORT = 1025;
     private static final int LMTP_PORT = 1024;
+    private static final int JMAP_PORT = 1080;
     public static final int BUFFER_SIZE = 1000;
 
     private CassandraJamesServer server;
@@ -65,6 +73,7 @@ public class CassandraJamesServerTest {
         server = new 
CassandraJamesServer(Modules.override(CassandraJamesServerMain.defaultModule)
                 .with(new TestElasticSearchModule(embeddedElasticSearch),
                         new TestFilesystemModule(temporaryFolder.newFolder()),
+                        new TestJMAPServerModule(),
                         new AbstractModule() {
                     
                     @Override
@@ -82,6 +91,9 @@ public class CassandraJamesServerTest {
         socketChannel = SocketChannel.open();
 
         server.start();
+
+        RestAssured.port = JMAP_PORT;
+        RestAssured.config = 
newConfig().encoderConfig(encoderConfig().defaultContentCharset(Charsets.UTF_8));
     }
 
     @After
@@ -119,11 +131,22 @@ public class CassandraJamesServerTest {
         assertThat(getServerConnectionResponse(socketChannel)).contains("LMTP 
Server (JAMES Protocols Server) ready");
     }
 
+    @Test
+    public void connectJMAPServerShouldRespondBadRequest() throws Exception {
+        given()
+            .contentType(ContentType.JSON)
+            .accept(ContentType.JSON)
+            .body("{\"badAttributeName\": \"value\"}")
+        .when()
+            .post("/authentication")
+        .then()
+            .statusCode(400);
+    }
+
     private String getServerConnectionResponse(SocketChannel socketChannel) 
throws IOException {
         ByteBuffer byteBuffer = ByteBuffer.allocate(1000);
         socketChannel.read(byteBuffer);
         byte[] bytes = byteBuffer.array();
         return new String(bytes, Charset.forName("UTF-8"));
     }
-
 }



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

Reply via email to