james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [15/21] james-project git commit: JAMES-1902 create webadmin module
Date Tue, 14 Mar 2017 11:14:56 GMT
JAMES-1902 create webadmin module


Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/6cc8ed09
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/6cc8ed09
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/6cc8ed09

Branch: refs/heads/master
Commit: 6cc8ed093bfc5631abb75048c7346a643f40c0ab
Parents: 3d0e2ae
Author: Matthieu Baechler <matthieu.baechler@gmail.com>
Authored: Tue Dec 27 15:16:09 2016 +0100
Committer: benwa <btellier@linagora.com>
Committed: Tue Mar 14 18:13:55 2017 +0700

----------------------------------------------------------------------
 server/container/guice/guice-common/pom.xml     |   8 +-
 .../java/org/apache/james/WebAdminServer.java   |  25 ---
 .../modules/server/WebAdminServerModule.java    | 115 ------------
 .../apache/james/utils/WebAdminGuiceProbe.java  |  37 ----
 server/container/guice/pom.xml                  |  26 ++-
 .../container/guice/protocols/webadmin/pom.xml  | 184 +++++++++++++++++++
 .../java/org/apache/james/WebAdminServer.java   |  25 +++
 .../modules/server/WebAdminServerModule.java    | 115 ++++++++++++
 .../apache/james/utils/WebAdminGuiceProbe.java  |  37 ++++
 9 files changed, 381 insertions(+), 191 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/6cc8ed09/server/container/guice/guice-common/pom.xml
----------------------------------------------------------------------
diff --git a/server/container/guice/guice-common/pom.xml b/server/container/guice/guice-common/pom.xml
index d294ca2..80f8ea2 100644
--- a/server/container/guice/guice-common/pom.xml
+++ b/server/container/guice/guice-common/pom.xml
@@ -209,6 +209,10 @@
                 </dependency>
                 <dependency>
                     <groupId>${project.groupId}</groupId>
+                    <artifactId>james-server-guice-webadmin</artifactId>
+                </dependency>
+                <dependency>
+                    <groupId>${project.groupId}</groupId>
                     <artifactId>james-server-mailets</artifactId>
                 </dependency>
                 <dependency>
@@ -252,10 +256,6 @@
                     <artifactId>james-server-onami</artifactId>
                 </dependency>
                 <dependency>
-                    <groupId>org.apache.james</groupId>
-                    <artifactId>james-server-webadmin</artifactId>
-                </dependency>
-                <dependency>
                     <groupId>org.apache.james.protocols</groupId>
                     <artifactId>protocols-imap</artifactId>
                 </dependency>

http://git-wip-us.apache.org/repos/asf/james-project/blob/6cc8ed09/server/container/guice/guice-common/src/main/java/org/apache/james/WebAdminServer.java
----------------------------------------------------------------------
diff --git a/server/container/guice/guice-common/src/main/java/org/apache/james/WebAdminServer.java
b/server/container/guice/guice-common/src/main/java/org/apache/james/WebAdminServer.java
deleted file mode 100644
index a08df88..0000000
--- a/server/container/guice/guice-common/src/main/java/org/apache/james/WebAdminServer.java
+++ /dev/null
@@ -1,25 +0,0 @@
-/****************************************************************
- * 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;
-
-import org.apache.james.utils.WebAdminGuiceProbe;
-
-public interface WebAdminServer {
-    WebAdminGuiceProbe getWebAdminProbe();
-}

http://git-wip-us.apache.org/repos/asf/james-project/blob/6cc8ed09/server/container/guice/guice-common/src/main/java/org/apache/james/modules/server/WebAdminServerModule.java
----------------------------------------------------------------------
diff --git a/server/container/guice/guice-common/src/main/java/org/apache/james/modules/server/WebAdminServerModule.java
b/server/container/guice/guice-common/src/main/java/org/apache/james/modules/server/WebAdminServerModule.java
deleted file mode 100644
index a9aed5c..0000000
--- a/server/container/guice/guice-common/src/main/java/org/apache/james/modules/server/WebAdminServerModule.java
+++ /dev/null
@@ -1,115 +0,0 @@
-/****************************************************************
- * 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.server;
-
-import static org.apache.james.webadmin.WebAdminServer.NO_CONFIGURATION;
-import static org.apache.james.webadmin.WebAdminServer.WEBADMIN_ENABLED;
-import static org.apache.james.webadmin.WebAdminServer.WEBADMIN_PORT;
-
-import java.io.FileNotFoundException;
-import java.util.List;
-
-import org.apache.commons.configuration.ConfigurationException;
-import org.apache.james.lifecycle.api.Configurable;
-import org.apache.james.utils.ConfigurationPerformer;
-import org.apache.james.utils.GuiceProbe;
-import org.apache.james.utils.PropertiesProvider;
-import org.apache.james.utils.WebAdminGuiceProbe;
-import org.apache.james.webadmin.FixedPort;
-import org.apache.james.webadmin.Port;
-import org.apache.james.webadmin.Routes;
-import org.apache.james.webadmin.WebAdminServer;
-import org.apache.james.webadmin.routes.DomainRoutes;
-import org.apache.james.webadmin.routes.UserMailboxesRoutes;
-import org.apache.james.webadmin.routes.UserRoutes;
-import org.apache.james.webadmin.utils.JsonTransformer;
-
-import com.google.common.base.Throwables;
-import com.google.common.collect.ImmutableList;
-import com.google.inject.AbstractModule;
-import com.google.inject.Inject;
-import com.google.inject.Provides;
-import com.google.inject.Scopes;
-import com.google.inject.Singleton;
-import com.google.inject.multibindings.Multibinder;
-import com.google.inject.name.Named;
-
-public class WebAdminServerModule extends AbstractModule {
-
-    @Override
-    protected void configure() {
-        bind(JsonTransformer.class).in(Scopes.SINGLETON);
-        bind(WebAdminServer.class).in(Scopes.SINGLETON);
-
-        Multibinder<Routes> routesMultibinder = Multibinder.newSetBinder(binder(),
Routes.class);
-        routesMultibinder.addBinding().to(DomainRoutes.class);
-        routesMultibinder.addBinding().to(UserRoutes.class);
-        routesMultibinder.addBinding().to(UserMailboxesRoutes.class);
-
-        Multibinder.newSetBinder(binder(), ConfigurationPerformer.class).addBinding().to(WebAdminServerModuleConfigurationPerformer.class);
-        Multibinder.newSetBinder(binder(), GuiceProbe.class).addBinding().to(WebAdminGuiceProbe.class);
-    }
-
-    @Provides
-    @Named(WEBADMIN_PORT)
-    public Port provideWebAdminPort(PropertiesProvider propertiesProvider) throws Exception
{
-        try {
-            return new FixedPort(propertiesProvider.getConfiguration("webadmin").getInt("port",
WebAdminServer.DEFAULT_PORT));
-        } catch (FileNotFoundException e) {
-            return new FixedPort(WebAdminServer.DEFAULT_PORT);
-        }
-    }
-
-    @Provides
-    @Named(WEBADMIN_ENABLED)
-    public boolean provideWebAdminEnabled(PropertiesProvider propertiesProvider) throws Exception
{
-        try {
-            return propertiesProvider.getConfiguration("webadmin").getBoolean("enabled",
false);
-        } catch (FileNotFoundException e) {
-            return false;
-        }
-    }
-
-    @Singleton
-    public static class WebAdminServerModuleConfigurationPerformer implements ConfigurationPerformer
{
-
-        private final WebAdminServer webAdminServer;
-
-        @Inject
-        public WebAdminServerModuleConfigurationPerformer(WebAdminServer webAdminServer)
{
-            this.webAdminServer = webAdminServer;
-        }
-
-        @Override
-        public void initModule() {
-            try {
-                webAdminServer.configure(NO_CONFIGURATION);
-            } catch (ConfigurationException e) {
-                throw Throwables.propagate(e);
-            }
-        }
-
-        @Override
-        public List<Class<? extends Configurable>> forClasses() {
-            return ImmutableList.of(WebAdminServer.class);
-        }
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/james-project/blob/6cc8ed09/server/container/guice/guice-common/src/main/java/org/apache/james/utils/WebAdminGuiceProbe.java
----------------------------------------------------------------------
diff --git a/server/container/guice/guice-common/src/main/java/org/apache/james/utils/WebAdminGuiceProbe.java
b/server/container/guice/guice-common/src/main/java/org/apache/james/utils/WebAdminGuiceProbe.java
deleted file mode 100644
index a68155c..0000000
--- a/server/container/guice/guice-common/src/main/java/org/apache/james/utils/WebAdminGuiceProbe.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/****************************************************************
- * 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.utils;
-
-import javax.inject.Inject;
-
-import org.apache.james.webadmin.WebAdminServer;
-
-public class WebAdminGuiceProbe implements GuiceProbe {
-    private final WebAdminServer webAdminServer;
-
-    @Inject
-    public WebAdminGuiceProbe(WebAdminServer webAdminServer) {
-        this.webAdminServer = webAdminServer;
-    }
-
-    public int getWebAdminPort() {
-        return webAdminServer.getPort().toInt();
-    }
-}

http://git-wip-us.apache.org/repos/asf/james-project/blob/6cc8ed09/server/container/guice/pom.xml
----------------------------------------------------------------------
diff --git a/server/container/guice/pom.xml b/server/container/guice/pom.xml
index 44fdf85..5824129 100644
--- a/server/container/guice/pom.xml
+++ b/server/container/guice/pom.xml
@@ -37,53 +37,58 @@
             <dependency>
                 <groupId>${project.groupId}</groupId>
                 <artifactId>james-server-guice-configuration</artifactId>
-                <version>3.0.0-beta6-SNAPSHOT</version>
+                <version>${project.version}</version>
             </dependency>
             <dependency>
                 <groupId>${project.groupId}</groupId>
                 <artifactId>james-server-guice-imap</artifactId>
-                <version>3.0.0-beta6-SNAPSHOT</version>
+                <version>${project.version}</version>
             </dependency>
             <dependency>
                 <groupId>${project.groupId}</groupId>
                 <artifactId>james-server-guice-jmap</artifactId>
-                <version>3.0.0-beta6-SNAPSHOT</version>
+                <version>${project.version}</version>
             </dependency>
             <dependency>
                 <groupId>${project.groupId}</groupId>
                 <artifactId>james-server-guice-jmap</artifactId>
-                <version>3.0.0-beta6-SNAPSHOT</version>
+                <version>${project.version}</version>
                 <type>test-jar</type>
             </dependency>
             <dependency>
                 <groupId>${project.groupId}</groupId>
                 <artifactId>james-server-guice-lmtp</artifactId>
-                <version>3.0.0-beta6-SNAPSHOT</version>
+                <version>${project.version}</version>
             </dependency>
             <dependency>
                 <groupId>${project.groupId}</groupId>
                 <artifactId>james-server-guice-mailbox</artifactId>
-                <version>3.0.0-beta6-SNAPSHOT</version>
+                <version>${project.version}</version>
             </dependency>
             <dependency>
                 <groupId>${project.groupId}</groupId>
                 <artifactId>james-server-guice-mailet</artifactId>
-                <version>3.0.0-beta6-SNAPSHOT</version>
+                <version>${project.version}</version>
             </dependency>
             <dependency>
                 <groupId>${project.groupId}</groupId>
                 <artifactId>james-server-guice-managedsieve</artifactId>
-                <version>3.0.0-beta6-SNAPSHOT</version>
+                <version>${project.version}</version>
             </dependency>
             <dependency>
                 <groupId>${project.groupId}</groupId>
                 <artifactId>james-server-guice-pop</artifactId>
-                <version>3.0.0-beta6-SNAPSHOT</version>
+                <version>${project.version}</version>
             </dependency>
             <dependency>
                 <groupId>${project.groupId}</groupId>
                 <artifactId>james-server-guice-smtp</artifactId>
-                <version>3.0.0-beta6-SNAPSHOT</version>
+                <version>${project.version}</version>
+            </dependency>
+            <dependency>
+                <groupId>${project.groupId}</groupId>
+                <artifactId>james-server-guice-webadmin</artifactId>
+                <version>${project.version}</version>
             </dependency>
         </dependencies>
     </dependencyManagement>
@@ -104,6 +109,7 @@
         <module>protocols/managedsieve</module>
         <module>protocols/pop</module>
         <module>protocols/smtp</module>
+        <module>protocols/webadmin</module>
     </modules>
 </project>
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/6cc8ed09/server/container/guice/protocols/webadmin/pom.xml
----------------------------------------------------------------------
diff --git a/server/container/guice/protocols/webadmin/pom.xml b/server/container/guice/protocols/webadmin/pom.xml
new file mode 100644
index 0000000..acfeda2
--- /dev/null
+++ b/server/container/guice/protocols/webadmin/pom.xml
@@ -0,0 +1,184 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <parent>
+        <artifactId>james-server-guice</artifactId>
+        <groupId>org.apache.james</groupId>
+        <version>3.0.0-beta6-SNAPSHOT</version>
+        <relativePath>../../pom.xml</relativePath>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+
+    <artifactId>james-server-guice-webadmin</artifactId>
+
+    <name>Apache James :: Server :: Guice :: Webadmin</name>
+    <description>Webadmin modules for Guice implementation of James server</description>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-bundle-plugin</artifactId>
+                <extensions>true</extensions>
+            </plugin>
+        </plugins>
+    </build>
+
+    <profiles>
+        <profile>
+            <id>disable-build-for-older-jdk</id>
+            <activation>
+                <jdk>(,1.8)</jdk>
+            </activation>
+            <build>
+                <plugins>
+                    <plugin>
+                        <artifactId>maven-jar-plugin</artifactId>
+                        <executions>
+                            <execution>
+                                <id>default-jar</id>
+                                <phase>none</phase>
+                            </execution>
+                            <execution>
+                                <id>jar</id>
+                                <phase>none</phase>
+                            </execution>
+                            <execution>
+                                <id>test-jar</id>
+                                <phase>none</phase>
+                            </execution>
+                        </executions>
+                    </plugin>
+                    <plugin>
+                        <artifactId>maven-compiler-plugin</artifactId>
+                        <executions>
+                            <execution>
+                                <id>default-compile</id>
+                                <phase>none</phase>
+                            </execution>
+                            <execution>
+                                <id>default-testCompile</id>
+                                <phase>none</phase>
+                            </execution>
+                        </executions>
+                    </plugin>
+                    <plugin>
+                        <artifactId>maven-surefire-plugin</artifactId>
+                        <executions>
+                            <execution>
+                                <id>default-test</id>
+                                <phase>none</phase>
+                            </execution>
+                        </executions>
+                    </plugin>
+                    <plugin>
+                        <artifactId>maven-source-plugin</artifactId>
+                        <executions>
+                            <execution>
+                                <id>attach-sources</id>
+                                <phase>none</phase>
+                            </execution>
+                        </executions>
+                    </plugin>
+                    <plugin>
+                        <artifactId>maven-install-plugin</artifactId>
+                        <executions>
+                            <execution>
+                                <id>default-install</id>
+                                <phase>none</phase>
+                            </execution>
+                        </executions>
+                    </plugin>
+                    <plugin>
+                        <artifactId>maven-resources-plugin</artifactId>
+                        <executions>
+                            <execution>
+                                <id>default-resources</id>
+                                <phase>none</phase>
+                            </execution>
+                            <execution>
+                                <id>default-testResources</id>
+                                <phase>none</phase>
+                            </execution>
+                        </executions>
+                    </plugin>
+                    <plugin>
+                        <artifactId>maven-site-plugin</artifactId>
+                        <executions>
+                            <execution>
+                                <id>attach-descriptor</id>
+                                <phase>none</phase>
+                            </execution>
+                        </executions>
+                    </plugin>
+                </plugins>
+            </build>
+        </profile>
+        <profile>
+            <id>build-for-jdk-8</id>
+            <activation>
+                <jdk>[1.8,)</jdk>
+            </activation>
+            <build>
+                <plugins>
+                    <plugin>
+                        <groupId>org.apache.maven.plugins</groupId>
+                        <artifactId>maven-compiler-plugin</artifactId>
+                        <configuration>
+                            <source>1.8</source>
+                            <target>1.8</target>
+                        </configuration>
+                    </plugin>
+                </plugins>
+            </build>
+            <dependencies>
+                <dependency>
+                    <groupId>${project.groupId}</groupId>
+                    <artifactId>james-server-guice-configuration</artifactId>
+                </dependency>
+                <dependency>
+                    <groupId>org.apache.james</groupId>
+                    <artifactId>james-server-webadmin</artifactId>
+                </dependency>
+                <dependency>
+                    <groupId>com.google.inject</groupId>
+                    <artifactId>guice</artifactId>
+                </dependency>
+                <dependency>
+                    <groupId>com.google.inject.extensions</groupId>
+                    <artifactId>guice-multibindings</artifactId>
+                </dependency>
+            </dependencies>
+        </profile>
+        <profile>
+            <id>animal-sniffer-java-8</id>
+            <activation>
+                <jdk>[1.8,)</jdk>
+            </activation>
+            <build>
+                <plugins>
+                    <plugin>
+                        <groupId>org.codehaus.mojo</groupId>
+                        <artifactId>animal-sniffer-maven-plugin</artifactId>
+                        <configuration>
+                            <signature>
+                                <groupId>org.codehaus.mojo.signature</groupId>
+                                <artifactId>java18</artifactId>
+                                <version>1.0</version>
+                            </signature>
+                        </configuration>
+                        <executions>
+                            <execution>
+                                <id>check_java_8</id>
+                                <phase>test</phase>
+                                <goals>
+                                    <goal>check</goal>
+                                </goals>
+                            </execution>
+                        </executions>
+                    </plugin>
+                </plugins>
+            </build>
+        </profile>
+    </profiles>
+
+</project>

http://git-wip-us.apache.org/repos/asf/james-project/blob/6cc8ed09/server/container/guice/protocols/webadmin/src/main/java/org/apache/james/WebAdminServer.java
----------------------------------------------------------------------
diff --git a/server/container/guice/protocols/webadmin/src/main/java/org/apache/james/WebAdminServer.java
b/server/container/guice/protocols/webadmin/src/main/java/org/apache/james/WebAdminServer.java
new file mode 100644
index 0000000..a08df88
--- /dev/null
+++ b/server/container/guice/protocols/webadmin/src/main/java/org/apache/james/WebAdminServer.java
@@ -0,0 +1,25 @@
+/****************************************************************
+ * 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;
+
+import org.apache.james.utils.WebAdminGuiceProbe;
+
+public interface WebAdminServer {
+    WebAdminGuiceProbe getWebAdminProbe();
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/6cc8ed09/server/container/guice/protocols/webadmin/src/main/java/org/apache/james/modules/server/WebAdminServerModule.java
----------------------------------------------------------------------
diff --git a/server/container/guice/protocols/webadmin/src/main/java/org/apache/james/modules/server/WebAdminServerModule.java
b/server/container/guice/protocols/webadmin/src/main/java/org/apache/james/modules/server/WebAdminServerModule.java
new file mode 100644
index 0000000..a9aed5c
--- /dev/null
+++ b/server/container/guice/protocols/webadmin/src/main/java/org/apache/james/modules/server/WebAdminServerModule.java
@@ -0,0 +1,115 @@
+/****************************************************************
+ * 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.server;
+
+import static org.apache.james.webadmin.WebAdminServer.NO_CONFIGURATION;
+import static org.apache.james.webadmin.WebAdminServer.WEBADMIN_ENABLED;
+import static org.apache.james.webadmin.WebAdminServer.WEBADMIN_PORT;
+
+import java.io.FileNotFoundException;
+import java.util.List;
+
+import org.apache.commons.configuration.ConfigurationException;
+import org.apache.james.lifecycle.api.Configurable;
+import org.apache.james.utils.ConfigurationPerformer;
+import org.apache.james.utils.GuiceProbe;
+import org.apache.james.utils.PropertiesProvider;
+import org.apache.james.utils.WebAdminGuiceProbe;
+import org.apache.james.webadmin.FixedPort;
+import org.apache.james.webadmin.Port;
+import org.apache.james.webadmin.Routes;
+import org.apache.james.webadmin.WebAdminServer;
+import org.apache.james.webadmin.routes.DomainRoutes;
+import org.apache.james.webadmin.routes.UserMailboxesRoutes;
+import org.apache.james.webadmin.routes.UserRoutes;
+import org.apache.james.webadmin.utils.JsonTransformer;
+
+import com.google.common.base.Throwables;
+import com.google.common.collect.ImmutableList;
+import com.google.inject.AbstractModule;
+import com.google.inject.Inject;
+import com.google.inject.Provides;
+import com.google.inject.Scopes;
+import com.google.inject.Singleton;
+import com.google.inject.multibindings.Multibinder;
+import com.google.inject.name.Named;
+
+public class WebAdminServerModule extends AbstractModule {
+
+    @Override
+    protected void configure() {
+        bind(JsonTransformer.class).in(Scopes.SINGLETON);
+        bind(WebAdminServer.class).in(Scopes.SINGLETON);
+
+        Multibinder<Routes> routesMultibinder = Multibinder.newSetBinder(binder(),
Routes.class);
+        routesMultibinder.addBinding().to(DomainRoutes.class);
+        routesMultibinder.addBinding().to(UserRoutes.class);
+        routesMultibinder.addBinding().to(UserMailboxesRoutes.class);
+
+        Multibinder.newSetBinder(binder(), ConfigurationPerformer.class).addBinding().to(WebAdminServerModuleConfigurationPerformer.class);
+        Multibinder.newSetBinder(binder(), GuiceProbe.class).addBinding().to(WebAdminGuiceProbe.class);
+    }
+
+    @Provides
+    @Named(WEBADMIN_PORT)
+    public Port provideWebAdminPort(PropertiesProvider propertiesProvider) throws Exception
{
+        try {
+            return new FixedPort(propertiesProvider.getConfiguration("webadmin").getInt("port",
WebAdminServer.DEFAULT_PORT));
+        } catch (FileNotFoundException e) {
+            return new FixedPort(WebAdminServer.DEFAULT_PORT);
+        }
+    }
+
+    @Provides
+    @Named(WEBADMIN_ENABLED)
+    public boolean provideWebAdminEnabled(PropertiesProvider propertiesProvider) throws Exception
{
+        try {
+            return propertiesProvider.getConfiguration("webadmin").getBoolean("enabled",
false);
+        } catch (FileNotFoundException e) {
+            return false;
+        }
+    }
+
+    @Singleton
+    public static class WebAdminServerModuleConfigurationPerformer implements ConfigurationPerformer
{
+
+        private final WebAdminServer webAdminServer;
+
+        @Inject
+        public WebAdminServerModuleConfigurationPerformer(WebAdminServer webAdminServer)
{
+            this.webAdminServer = webAdminServer;
+        }
+
+        @Override
+        public void initModule() {
+            try {
+                webAdminServer.configure(NO_CONFIGURATION);
+            } catch (ConfigurationException e) {
+                throw Throwables.propagate(e);
+            }
+        }
+
+        @Override
+        public List<Class<? extends Configurable>> forClasses() {
+            return ImmutableList.of(WebAdminServer.class);
+        }
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/6cc8ed09/server/container/guice/protocols/webadmin/src/main/java/org/apache/james/utils/WebAdminGuiceProbe.java
----------------------------------------------------------------------
diff --git a/server/container/guice/protocols/webadmin/src/main/java/org/apache/james/utils/WebAdminGuiceProbe.java
b/server/container/guice/protocols/webadmin/src/main/java/org/apache/james/utils/WebAdminGuiceProbe.java
new file mode 100644
index 0000000..a68155c
--- /dev/null
+++ b/server/container/guice/protocols/webadmin/src/main/java/org/apache/james/utils/WebAdminGuiceProbe.java
@@ -0,0 +1,37 @@
+/****************************************************************
+ * 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.utils;
+
+import javax.inject.Inject;
+
+import org.apache.james.webadmin.WebAdminServer;
+
+public class WebAdminGuiceProbe implements GuiceProbe {
+    private final WebAdminServer webAdminServer;
+
+    @Inject
+    public WebAdminGuiceProbe(WebAdminServer webAdminServer) {
+        this.webAdminServer = webAdminServer;
+    }
+
+    public int getWebAdminPort() {
+        return webAdminServer.getPort().toInt();
+    }
+}


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