Author: matthieu
Date: Fri Dec 11 10:08:53 2015
New Revision: 1719324

URL: http://svn.apache.org/viewvc?rev=1719324&view=rev
Log:
JAMES-1644 JMAP server bootstrap

Added:
    
james/project/trunk/server/container/cassandra-guice/src/main/java/org/apache/james/jmap/JMAPModule.java
    
james/project/trunk/server/container/cassandra-guice/src/test/java/org/apache/james/modules/TestJMAPServerModule.java
    
james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/JMAPServer.java

Added: 
james/project/trunk/server/container/cassandra-guice/src/main/java/org/apache/james/jmap/JMAPModule.java
URL: 
http://svn.apache.org/viewvc/james/project/trunk/server/container/cassandra-guice/src/main/java/org/apache/james/jmap/JMAPModule.java?rev=1719324&view=auto
==============================================================================
--- 
james/project/trunk/server/container/cassandra-guice/src/main/java/org/apache/james/jmap/JMAPModule.java
 (added)
+++ 
james/project/trunk/server/container/cassandra-guice/src/main/java/org/apache/james/jmap/JMAPModule.java
 Fri Dec 11 10:08:53 2015
@@ -0,0 +1,49 @@
+/****************************************************************
+ * 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.jmap;
+
+import org.apache.james.jmap.methods.RequestHandler;
+import org.apache.james.jmap.model.ProtocolRequest;
+import org.apache.james.jmap.model.ProtocolResponse;
+
+import com.google.inject.AbstractModule;
+import com.google.inject.name.Names;
+
+public class JMAPModule extends AbstractModule {
+
+    private static final int DEFAULT_PORT = 80;
+
+    @Override
+    protected void configure() {
+        install(new JMAPCommonModule());
+        bind(AuthenticationFilter.class);
+        bind(RequestHandler.class).toInstance(new RequestHandler() {
+
+            @Override
+            public ProtocolResponse process(ProtocolRequest request) {
+                // TODO Auto-generated method stub
+                return null;
+            }
+            
+        });
+
+        
bindConstant().annotatedWith(Names.named(JMAPServer.DEFAULT_JMAP_PORT)).to(DEFAULT_PORT);
+    }
+
+}

Added: 
james/project/trunk/server/container/cassandra-guice/src/test/java/org/apache/james/modules/TestJMAPServerModule.java
URL: 
http://svn.apache.org/viewvc/james/project/trunk/server/container/cassandra-guice/src/test/java/org/apache/james/modules/TestJMAPServerModule.java?rev=1719324&view=auto
==============================================================================
--- 
james/project/trunk/server/container/cassandra-guice/src/test/java/org/apache/james/modules/TestJMAPServerModule.java
 (added)
+++ 
james/project/trunk/server/container/cassandra-guice/src/test/java/org/apache/james/modules/TestJMAPServerModule.java
 Fri Dec 11 10:08:53 2015
@@ -0,0 +1,33 @@
+/****************************************************************
+ * 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;
+
+import org.apache.james.jmap.JMAPServer;
+
+import com.google.inject.AbstractModule;
+import com.google.inject.name.Names;
+
+public class TestJMAPServerModule extends AbstractModule{
+
+    @Override
+    protected void configure() {
+        
bindConstant().annotatedWith(Names.named(JMAPServer.DEFAULT_JMAP_PORT)).to(1080);
+    }
+}

Added: 
james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/JMAPServer.java
URL: 
http://svn.apache.org/viewvc/james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/JMAPServer.java?rev=1719324&view=auto
==============================================================================
--- 
james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/JMAPServer.java
 (added)
+++ 
james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/JMAPServer.java
 Fri Dec 11 10:08:53 2015
@@ -0,0 +1,78 @@
+/****************************************************************
+ * 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.jmap;
+
+import javax.annotation.PreDestroy;
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.inject.Singleton;
+
+import org.apache.commons.configuration.ConfigurationException;
+import org.apache.commons.configuration.HierarchicalConfiguration;
+import org.apache.james.http.jetty.Configuration;
+import org.apache.james.http.jetty.JettyHttpServer;
+import org.apache.james.lifecycle.api.Configurable;
+
+import com.google.common.base.Throwables;
+
+
+@Singleton
+public class JMAPServer implements Configurable {
+
+    public static final String DEFAULT_JMAP_PORT = "defaultJMAPPort";
+    
+    private final JettyHttpServer server;
+
+    @Inject
+    private JMAPServer(@Named(DEFAULT_JMAP_PORT) int port, 
+            AuthenticationServlet authenticationServlet, JMAPServlet 
jmapServlet,
+            AuthenticationFilter authenticationFilter) {
+
+        server = JettyHttpServer.create(Configuration.builder()
+                .port(port)
+                .serve("/authentication").with(authenticationServlet)
+                .filter("/authentication").with(new 
BypassOnPostFilter(authenticationFilter))
+                .serve("/jmap").with(jmapServlet)
+                .filter("/jmap").with(authenticationFilter)
+                .build());
+    }
+    @Override
+    public void configure(HierarchicalConfiguration config) throws 
ConfigurationException {
+        try {
+            server.start();
+        } catch (Exception e) {
+            Throwables.propagate(e);
+        }
+    }
+
+    @PreDestroy
+    public void stop() {
+        try {
+            server.stop();
+        } catch (Exception e) {
+            Throwables.propagate(e);
+        }
+    }
+
+    public int getPort() {
+        return server.getPort();
+    }
+
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to