You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by bt...@apache.org on 2017/07/31 07:45:31 UTC
[1/7] james-project git commit: JAMES-2099 Add more dependency for
swagger modules
Repository: james-project
Updated Branches:
refs/heads/master b4f432a97 -> 9ed12378a
JAMES-2099 Add more dependency for swagger modules
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/f697263c
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/f697263c
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/f697263c
Branch: refs/heads/master
Commit: f697263c0e498f8fa8b4c675b4dc0908a5a31c46
Parents: 7ce7371
Author: quynhn <qn...@linagora.com>
Authored: Tue Jul 25 10:53:18 2017 +0700
Committer: quynhn <qn...@linagora.com>
Committed: Mon Jul 31 10:35:46 2017 +0700
----------------------------------------------------------------------
server/container/guice/cassandra-guice/pom.xml | 4 ++++
.../java/org/apache/james/CassandraJamesServerMain.java | 6 ++++--
server/container/guice/pom.xml | 8 +++++++-
server/pom.xml | 6 ++++++
server/protocols/webadmin/webadmin-core/pom.xml | 10 ++++++++++
5 files changed, 31 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/f697263c/server/container/guice/cassandra-guice/pom.xml
----------------------------------------------------------------------
diff --git a/server/container/guice/cassandra-guice/pom.xml b/server/container/guice/cassandra-guice/pom.xml
index 3238500..67d4889 100644
--- a/server/container/guice/cassandra-guice/pom.xml
+++ b/server/container/guice/cassandra-guice/pom.xml
@@ -310,6 +310,10 @@
<artifactId>james-server-guice-webadmin-mailbox</artifactId>
</dependency>
<dependency>
+ <groupId>org.apache.james</groupId>
+ <artifactId>james-server-guice-webadmin-swagger</artifactId>
+ </dependency>
+ <dependency>
<groupId>${project.groupId}</groupId>
<artifactId>james-server-jmap-integration-testing</artifactId>
<type>test-jar</type>
http://git-wip-us.apache.org/repos/asf/james-project/blob/f697263c/server/container/guice/cassandra-guice/src/main/java/org/apache/james/CassandraJamesServerMain.java
----------------------------------------------------------------------
diff --git a/server/container/guice/cassandra-guice/src/main/java/org/apache/james/CassandraJamesServerMain.java b/server/container/guice/cassandra-guice/src/main/java/org/apache/james/CassandraJamesServerMain.java
index c04664b..411bee3 100644
--- a/server/container/guice/cassandra-guice/src/main/java/org/apache/james/CassandraJamesServerMain.java
+++ b/server/container/guice/cassandra-guice/src/main/java/org/apache/james/CassandraJamesServerMain.java
@@ -42,6 +42,7 @@ import org.apache.james.modules.server.DataRoutesModules;
import org.apache.james.modules.server.ESMetricReporterModule;
import org.apache.james.modules.server.JMXServerModule;
import org.apache.james.modules.server.MailboxRoutesModule;
+import org.apache.james.modules.server.SwaggerRoutesModules;
import org.apache.james.modules.server.WebAdminServerModule;
import com.google.inject.Module;
@@ -59,8 +60,9 @@ public class CassandraJamesServerMain {
new WebAdminServerModule(),
new DataRoutesModules(),
new MailboxRoutesModule(),
- new CassandraRoutesModule());
-
+ new CassandraRoutesModule(),
+ new SwaggerRoutesModules());
+
public static final Module cassandraServerModule = Modules.combine(
new JMAPServerModule(),
new CassandraUsersRepositoryModule(),
http://git-wip-us.apache.org/repos/asf/james-project/blob/f697263c/server/container/guice/pom.xml
----------------------------------------------------------------------
diff --git a/server/container/guice/pom.xml b/server/container/guice/pom.xml
index 381a2d6..ea7abfe 100644
--- a/server/container/guice/pom.xml
+++ b/server/container/guice/pom.xml
@@ -112,6 +112,11 @@
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
+ <artifactId>james-server-guice-webadmin-swagger</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
<artifactId>james-server-jpa-common-guice</artifactId>
<version>${project.version}</version>
</dependency>
@@ -140,8 +145,9 @@
<module>protocols/smtp</module>
<module>protocols/webadmin</module>
<module>protocols/webadmin-cassandra</module>
- <module>protocols/webadmin-mailbox</module>
<module>protocols/webadmin-data</module>
+ <module>protocols/webadmin-mailbox</module>
+ <module>protocols/webadmin-swagger</module>
</modules>
</project>
http://git-wip-us.apache.org/repos/asf/james-project/blob/f697263c/server/pom.xml
----------------------------------------------------------------------
diff --git a/server/pom.xml b/server/pom.xml
index 2f90850..6e98a77 100644
--- a/server/pom.xml
+++ b/server/pom.xml
@@ -106,6 +106,7 @@
<module>protocols/webadmin/webadmin-core</module>
<module>protocols/webadmin/webadmin-data</module>
<module>protocols/webadmin/webadmin-mailbox</module>
+ <module>protocols/webadmin/webadmin-swagger</module>
<module>protocols/webadmin-integration-test</module>
<module>queue/queue-api</module>
@@ -699,6 +700,11 @@
<version>${project.version}</version>
</dependency>
<dependency>
+ <groupId>org.apache.james</groupId>
+ <artifactId>james-server-webadmin-swagger</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
<groupId>org.apache.james.protocols</groupId>
<artifactId>protocols-smtp</artifactId>
<version>${project.version}</version>
http://git-wip-us.apache.org/repos/asf/james-project/blob/f697263c/server/protocols/webadmin/webadmin-core/pom.xml
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/webadmin-core/pom.xml b/server/protocols/webadmin/webadmin-core/pom.xml
index f73cb99..7bd6d8b 100644
--- a/server/protocols/webadmin/webadmin-core/pom.xml
+++ b/server/protocols/webadmin/webadmin-core/pom.xml
@@ -190,6 +190,16 @@
<version>2.5.5</version>
</dependency>
<dependency>
+ <groupId>io.swagger</groupId>
+ <artifactId>swagger-jaxrs</artifactId>
+ <version>1.5.8</version>
+ </dependency>
+ <dependency>
+ <groupId>javax.ws.rs</groupId>
+ <artifactId>javax.ws.rs-api</artifactId>
+ <version>2.0.1</version>
+ </dependency>
+ <dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
</dependency>
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[4/7] james-project git commit: JAMES-2099 Integration Test for
swagger API
Posted by bt...@apache.org.
JAMES-2099 Integration Test for swagger API
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/80dae302
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/80dae302
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/80dae302
Branch: refs/heads/master
Commit: 80dae3025c8aaa99bc5fa88f00e34d37596144b7
Parents: f697263
Author: quynhn <qn...@linagora.com>
Authored: Tue Jul 25 10:54:17 2017 +0700
Committer: quynhn <qn...@linagora.com>
Committed: Mon Jul 31 10:56:08 2017 +0700
----------------------------------------------------------------------
.../WebAdminServerIntegrationTest.java | 26 +++++++++++++++++---
.../webadmin/WebAdminConfigurationTest.java | 24 ++++++++++++++++++
2 files changed, 47 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/80dae302/server/protocols/webadmin-integration-test/src/test/java/org/apache/james/webadmin/integration/WebAdminServerIntegrationTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin-integration-test/src/test/java/org/apache/james/webadmin/integration/WebAdminServerIntegrationTest.java b/server/protocols/webadmin-integration-test/src/test/java/org/apache/james/webadmin/integration/WebAdminServerIntegrationTest.java
index afd47d4..4a1205d 100644
--- a/server/protocols/webadmin-integration-test/src/test/java/org/apache/james/webadmin/integration/WebAdminServerIntegrationTest.java
+++ b/server/protocols/webadmin-integration-test/src/test/java/org/apache/james/webadmin/integration/WebAdminServerIntegrationTest.java
@@ -24,7 +24,11 @@ import static com.jayway.restassured.config.EncoderConfig.encoderConfig;
import static com.jayway.restassured.config.RestAssuredConfig.newConfig;
import static org.apache.james.webadmin.Constants.SEPARATOR;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.hamcrest.Matchers.contains;
+import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.notNullValue;
+import static org.hamcrest.Matchers.stringContainsInOrder;
import org.apache.james.CassandraJmapTestRule;
import org.apache.james.GuiceJamesServer;
@@ -36,7 +40,7 @@ import org.apache.james.utils.WebAdminGuiceProbe;
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.service.CassandraMigrationService;
+import org.apache.james.webadmin.swagger.routes.SwaggerRoutes;
import org.junit.After;
import org.junit.Before;
@@ -44,8 +48,6 @@ import org.junit.Rule;
import org.junit.Test;
import com.google.common.base.Charsets;
-import com.google.inject.AbstractModule;
-import com.google.inject.name.Names;
import com.jayway.restassured.RestAssured;
import com.jayway.restassured.builder.RequestSpecBuilder;
import com.jayway.restassured.http.ContentType;
@@ -250,4 +252,22 @@ public class WebAdminServerIntegrationTest {
.statusCode(200)
.body(is("{\"version\":" + CassandraSchemaVersionManager.MAX_VERSION + "}"));
}
+
+ @Test
+ public void getSwaggerShouldReturnJsonDataForSwagger() throws Exception {
+ given()
+ .port(webAdminGuiceProbe.getWebAdminPort())
+ .when()
+ .get(SwaggerRoutes.SWAGGER_ENDPOINT)
+ .then()
+ .statusCode(200)
+ .body(containsString("\"swagger\":\"2.0\""))
+ .body(containsString("\"info\":{\"description\":\"All the web administration API for JAMES\",\"version\":\"V1.0\",\"title\":\"JAMES Web Admin API\"}"))
+ .body(containsString("\"tags\":[\"User's Mailbox\"]"))
+ .body(containsString("\"tags\":[\"GlobalQuota\"]"))
+ .body(containsString("\"tags\":[\"Domains\"]"))
+ .body(containsString("\"tags\":[\"Users\"]"))
+ ;
+ }
+
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/80dae302/server/protocols/webadmin/webadmin-core/src/test/java/org/apache/james/webadmin/WebAdminConfigurationTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/webadmin-core/src/test/java/org/apache/james/webadmin/WebAdminConfigurationTest.java b/server/protocols/webadmin/webadmin-core/src/test/java/org/apache/james/webadmin/WebAdminConfigurationTest.java
index 1030dcf..ab0649f 100644
--- a/server/protocols/webadmin/webadmin-core/src/test/java/org/apache/james/webadmin/WebAdminConfigurationTest.java
+++ b/server/protocols/webadmin/webadmin-core/src/test/java/org/apache/james/webadmin/WebAdminConfigurationTest.java
@@ -174,6 +174,30 @@ public class WebAdminConfigurationTest {
}
@Test
+ public void builderShouldDefineHostWithDefault() {
+ assertThat(
+ WebAdminConfiguration.builder()
+ .enabled()
+ .port(PORT)
+ .build())
+ .extracting(WebAdminConfiguration::getHost)
+ .containsExactly(WebAdminConfiguration.DEFAULT_HOST);
+ }
+
+ @Test
+ public void builderShouldDefineHostWithSetting() {
+ String host = "any.host";
+ assertThat(
+ WebAdminConfiguration.builder()
+ .enabled()
+ .port(PORT)
+ .host(host)
+ .build())
+ .extracting(WebAdminConfiguration::getHost)
+ .containsExactly(host);
+ }
+
+ @Test
public void shouldMatchBeanContract() {
EqualsVerifier.forClass(WebAdminConfiguration.class).verify();
}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[5/7] james-project git commit: JAMES-2099 Swagger API for UserMaibox
and GlobalQuota
Posted by bt...@apache.org.
JAMES-2099 Swagger API for UserMaibox and GlobalQuota
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/9cd602f1
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/9cd602f1
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/9cd602f1
Branch: refs/heads/master
Commit: 9cd602f10506932f550169852be0bd27b0799db7
Parents: 80dae30
Author: quynhn <qn...@linagora.com>
Authored: Tue Jul 25 18:02:47 2017 +0700
Committer: quynhn <qn...@linagora.com>
Committed: Mon Jul 31 10:56:17 2017 +0700
----------------------------------------------------------------------
.../webadmin/routes/GlobalQuotaRoutes.java | 181 +++++++++++++++----
.../webadmin/routes/UserMailboxesRoutes.java | 133 ++++++++++++--
2 files changed, 264 insertions(+), 50 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/9cd602f1/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/routes/GlobalQuotaRoutes.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/routes/GlobalQuotaRoutes.java b/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/routes/GlobalQuotaRoutes.java
index eeca83a..d53608a 100644
--- a/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/routes/GlobalQuotaRoutes.java
+++ b/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/routes/GlobalQuotaRoutes.java
@@ -20,6 +20,11 @@
package org.apache.james.webadmin.routes;
import javax.inject.Inject;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
import org.apache.james.mailbox.model.Quota;
import org.apache.james.mailbox.quota.MaxQuotaManager;
@@ -30,11 +35,20 @@ import org.apache.james.webadmin.dto.QuotaRequest;
import org.apache.james.webadmin.utils.JsonExtractException;
import org.apache.james.webadmin.utils.JsonExtractor;
import org.apache.james.webadmin.utils.JsonTransformer;
+
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiImplicitParam;
+import io.swagger.annotations.ApiImplicitParams;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiResponse;
+import io.swagger.annotations.ApiResponses;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-
import spark.Service;
+@Api(tags = "GlobalQuota")
+@Path(GlobalQuotaRoutes.QUOTA_ENDPOINT)
+@Produces("application/json")
public class GlobalQuotaRoutes implements Routes {
public static final String QUOTA_ENDPOINT = "/quota";
@@ -45,6 +59,7 @@ public class GlobalQuotaRoutes implements Routes {
private final MaxQuotaManager maxQuotaManager;
private final JsonTransformer jsonTransformer;
private final JsonExtractor<QuotaDTO> jsonExtractor;
+ private Service service;
@Inject
public GlobalQuotaRoutes(MaxQuotaManager maxQuotaManager, JsonTransformer jsonTransformer) {
@@ -55,42 +70,96 @@ public class GlobalQuotaRoutes implements Routes {
@Override
public void define(Service service) {
- service.get(COUNT_ENDPOINT, (request, response) -> {
- long value = maxQuotaManager.getDefaultMaxMessage();
- response.status(200);
- return value;
- }, jsonTransformer);
+ this.service = service;
- service.delete(COUNT_ENDPOINT, (request, response) -> {
- maxQuotaManager.setDefaultMaxMessage(Quota.UNLIMITED);
- response.status(204);
- return Constants.EMPTY_BODY;
- });
+ defineGetQuotaCount();
- service.put(COUNT_ENDPOINT, (request, response) -> {
+ defineDeleteQuotaCount();
+
+ defineUpdateQuotaCount();
+
+ defineGetQuotaSize();
+
+ defineDeleteQuotaSize();
+
+ defineUpdateQuotaSize();
+
+ defineGetQuota();
+
+ defineUpdateQuota();
+ }
+
+ @PUT
+ @ApiOperation(value = "Updating count and size at the same time")
+ @ApiImplicitParams({
+ @ApiImplicitParam(required = true, dataType = "org.apache.james.webadmin.dto.QuotaDTO", paramType = "body")
+ })
+ @ApiResponses(value = {
+ @ApiResponse(code = 204, message = "OK. The value has been updated."),
+ @ApiResponse(code = 400, message = "The body is not a positive integer or not unlimited value (-1)."),
+ @ApiResponse(code = 500, message = "Internal server error - Something went bad on the server side.")
+ })
+ public void defineUpdateQuota() {
+ service.put(QUOTA_ENDPOINT, ((request, response) -> {
try {
- QuotaRequest quotaRequest = QuotaRequest.parse(request.body());
- maxQuotaManager.setDefaultMaxMessage(quotaRequest.getValue());
+ QuotaDTO quotaDTO = jsonExtractor.parse(request.body());
+ maxQuotaManager.setDefaultMaxMessage(quotaDTO.getCount());
+ maxQuotaManager.setDefaultMaxStorage(quotaDTO.getSize());
response.status(204);
+ } catch (JsonExtractException e) {
+ LOGGER.info("Malformed JSON", e);
+ response.status(400);
} catch (IllegalArgumentException e) {
- LOGGER.info("Invalid quota. Need to be an integer value greater than 0");
+ LOGGER.info("Quota should be positive or unlimited (-1)", e);
response.status(400);
}
return Constants.EMPTY_BODY;
- });
+ }));
+ }
- service.get(SIZE_ENDPOINT, (request, response) -> {
- long value = maxQuotaManager.getDefaultMaxStorage();
+ @GET
+ @ApiOperation(value = "Reading count and size at the same time")
+ @ApiResponses(value = {
+ @ApiResponse(code = 200, message = "OK", response = QuotaDTO.class),
+ @ApiResponse(code = 500, message = "Internal server error - Something went bad on the server side.")
+ })
+ public void defineGetQuota() {
+ service.get(QUOTA_ENDPOINT, (request, response) -> {
+ QuotaDTO quotaDTO = QuotaDTO.builder()
+ .count(maxQuotaManager.getDefaultMaxMessage())
+ .size(maxQuotaManager.getDefaultMaxStorage()).build();
response.status(200);
- return value;
+ return quotaDTO;
}, jsonTransformer);
+ }
+ @DELETE
+ @Path("/size")
+ @ApiOperation(value = "Removing per quotaroot mail size limitation by updating to unlimited value")
+ @ApiResponses(value = {
+ @ApiResponse(code = 204, message = "The value is updated to unlimited value."),
+ @ApiResponse(code = 500, message = "Internal server error - Something went bad on the server side.")
+ })
+ public void defineDeleteQuotaSize() {
service.delete(SIZE_ENDPOINT, (request, response) -> {
maxQuotaManager.setDefaultMaxStorage(Quota.UNLIMITED);
response.status(204);
return Constants.EMPTY_BODY;
});
+ }
+ @PUT
+ @Path("/size")
+ @ApiOperation(value = "Updating per quotaroot mail size limitation")
+ @ApiImplicitParams({
+ @ApiImplicitParam(required = true, dataType = "integer", paramType = "body")
+ })
+ @ApiResponses(value = {
+ @ApiResponse(code = 204, message = "OK. The value has been updated."),
+ @ApiResponse(code = 400, message = "The body is not a positive integer."),
+ @ApiResponse(code = 500, message = "Internal server error - Something went bad on the server side.")
+ })
+ public void defineUpdateQuotaSize() {
service.put(SIZE_ENDPOINT, (request, response) -> {
try {
QuotaRequest quotaRequest = QuotaRequest.parse(request.body());
@@ -102,29 +171,75 @@ public class GlobalQuotaRoutes implements Routes {
}
return Constants.EMPTY_BODY;
});
+ }
- service.get(QUOTA_ENDPOINT, (request, response) -> {
- QuotaDTO quotaDTO = QuotaDTO.builder()
- .count(maxQuotaManager.getDefaultMaxMessage())
- .size(maxQuotaManager.getDefaultMaxStorage()).build();
+ @GET
+ @Path("/size")
+ @ApiOperation(value = "Reading per quotaroot mail size limitation")
+ @ApiResponses(value = {
+ @ApiResponse(code = 200, message = "OK", response = Long.class),
+ @ApiResponse(code = 500, message = "Internal server error - Something went bad on the server side.")
+ })
+ public void defineGetQuotaSize() {
+ service.get(SIZE_ENDPOINT, (request, response) -> {
+ long value = maxQuotaManager.getDefaultMaxStorage();
response.status(200);
- return quotaDTO;
+ return value;
}, jsonTransformer);
+ }
- service.put(QUOTA_ENDPOINT, ((request, response) -> {
+ @DELETE
+ @Path("/count")
+ @ApiOperation(value = "Removing per quotaroot mail count limitation by updating to unlimited value")
+ @ApiResponses(value = {
+ @ApiResponse(code = 204, message = "The value is updated to unlimited value."),
+ @ApiResponse(code = 500, message = "Internal server error - Something went bad on the server side.")
+ })
+ public void defineDeleteQuotaCount() {
+ service.delete(COUNT_ENDPOINT, (request, response) -> {
+ maxQuotaManager.setDefaultMaxMessage(Quota.UNLIMITED);
+ response.status(204);
+ return Constants.EMPTY_BODY;
+ });
+ }
+
+ @PUT
+ @Path("/count")
+ @ApiOperation(value = "Updating per quotaroot mail count limitation")
+ @ApiImplicitParams({
+ @ApiImplicitParam(required = true, dataType = "integer", paramType = "body")
+ })
+ @ApiResponses(value = {
+ @ApiResponse(code = 204, message = "OK. The value has been updated."),
+ @ApiResponse(code = 400, message = "The body is not a positive integer."),
+ @ApiResponse(code = 500, message = "Internal server error - Something went bad on the server side.")
+ })
+ public void defineUpdateQuotaCount() {
+ service.put(COUNT_ENDPOINT, (request, response) -> {
try {
- QuotaDTO quotaDTO = jsonExtractor.parse(request.body());
- maxQuotaManager.setDefaultMaxMessage(quotaDTO.getCount());
- maxQuotaManager.setDefaultMaxStorage(quotaDTO.getSize());
+ QuotaRequest quotaRequest = QuotaRequest.parse(request.body());
+ maxQuotaManager.setDefaultMaxMessage(quotaRequest.getValue());
response.status(204);
- } catch (JsonExtractException e) {
- LOGGER.info("Malformed JSON", e);
- response.status(400);
} catch (IllegalArgumentException e) {
- LOGGER.info("Quota should be positive or unlimited (-1)", e);
+ LOGGER.info("Invalid quota. Need to be an integer value greater than 0");
response.status(400);
}
return Constants.EMPTY_BODY;
- }));
+ });
+ }
+
+ @GET
+ @Path("/count")
+ @ApiOperation(value = "Reading per quotaroot mail count limitation")
+ @ApiResponses(value = {
+ @ApiResponse(code = 200, message = "OK", response = Long.class),
+ @ApiResponse(code = 500, message = "Internal server error - Something went bad on the server side.")
+ })
+ public void defineGetQuotaCount() {
+ service.get(COUNT_ENDPOINT, (request, response) -> {
+ long value = maxQuotaManager.getDefaultMaxMessage();
+ response.status(200);
+ return value;
+ }, jsonTransformer);
}
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/9cd602f1/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/routes/UserMailboxesRoutes.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/routes/UserMailboxesRoutes.java b/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/routes/UserMailboxesRoutes.java
index 79a6915..1b218f5 100644
--- a/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/routes/UserMailboxesRoutes.java
+++ b/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/routes/UserMailboxesRoutes.java
@@ -20,6 +20,11 @@
package org.apache.james.webadmin.routes;
import javax.inject.Inject;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
import org.apache.james.webadmin.Constants;
import org.apache.james.webadmin.Routes;
@@ -27,11 +32,20 @@ import org.apache.james.webadmin.service.UserMailboxesService;
import org.apache.james.webadmin.utils.JsonTransformer;
import org.apache.james.webadmin.utils.MailboxHaveChildrenException;
import org.apache.james.webadmin.validation.MailboxName;
+
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiImplicitParam;
+import io.swagger.annotations.ApiImplicitParams;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiResponse;
+import io.swagger.annotations.ApiResponses;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-
import spark.Service;
+@Api(tags = "User's Mailbox")
+@Path("/users/{username}/mailboxes")
+@Produces("application/json")
public class UserMailboxesRoutes implements Routes {
private static final Logger LOGGER = LoggerFactory.getLogger(UserMailboxesRoutes.class);
@@ -45,6 +59,7 @@ public class UserMailboxesRoutes implements Routes {
private final UserMailboxesService userMailboxesService;
private final JsonTransformer jsonTransformer;
+ private Service service;
@Inject
public UserMailboxesRoutes(UserMailboxesService userMailboxesService, JsonTransformer jsonTransformer) {
@@ -54,21 +69,58 @@ public class UserMailboxesRoutes implements Routes {
@Override
public void define(Service service) {
+ this.service = service;
- service.put(SPECIFIC_MAILBOX, (request, response) -> {
+ defineMailboxExists();
+
+ defineGetUserMailboxes();
+
+ defineCreateUserMailbox();
+
+ defineDeleteUserMailbox();
+
+ defineDeleteUserMailboxes();
+ }
+
+ @GET
+ @ApiImplicitParams({
+ @ApiImplicitParam(required = true, dataType = "string", name = "username", paramType = "path")
+ })
+ @ApiOperation(value = "Listing all mailboxes of user.")
+ @ApiResponses(value = {
+ @ApiResponse(code = 204, message = "The list of mailboxes", response = String.class),
+ @ApiResponse(code = 401, message = "Unauthorized. The user is not authenticated on the platform", response = String.class),
+ @ApiResponse(code = 404, message = "The user name does not exist."),
+ @ApiResponse(code = 500, message = "Internal server error - Something went bad on the server side.")
+ })
+ public void defineGetUserMailboxes() {
+ service.get(USER_MAILBOXES_BASE, (request, response) -> {
+ response.status(200);
try {
- userMailboxesService.createMailbox(request.params(USER_NAME), new MailboxName(request.params(MAILBOX_NAME)));
- response.status(204);
+ return userMailboxesService.listMailboxes(request.params(USER_NAME));
} catch (IllegalStateException e) {
- LOGGER.info("Invalid put on user mailbox", e);
+ LOGGER.info("Invalid get on user mailboxes", e);
response.status(404);
- } catch (IllegalArgumentException e) {
- LOGGER.info("Attempt to create an invalid mailbox");
- response.status(400);
+ return Constants.EMPTY_BODY;
}
- return Constants.EMPTY_BODY;
- });
+ }, jsonTransformer);
+ }
+ @DELETE
+ @Path("/{mailboxName}")
+ @ApiImplicitParams({
+ @ApiImplicitParam(required = true, dataType = "string", name = "username", paramType = "path"),
+ @ApiImplicitParam(required = true, dataType = "string", name = "mailboxName", paramType = "path")
+ })
+ @ApiOperation(value = "Deleting a mailbox and its children")
+ @ApiResponses(value = {
+ @ApiResponse(code = 204, message = "The mailbox now does not exist on the server", response = String.class),
+ @ApiResponse(code = 400, message = "Invalid mailbox name"),
+ @ApiResponse(code = 401, message = "Unauthorized. The user is not authenticated on the platform"),
+ @ApiResponse(code = 404, message = "The user name does not exist."),
+ @ApiResponse(code = 500, message = "Internal server error - Something went bad on the server side.")
+ })
+ public void defineDeleteUserMailbox() {
service.delete(SPECIFIC_MAILBOX, (request, response) -> {
try {
userMailboxesService.deleteMailbox(request.params(USER_NAME), new MailboxName(request.params(MAILBOX_NAME)));
@@ -85,7 +137,20 @@ public class UserMailboxesRoutes implements Routes {
}
return Constants.EMPTY_BODY;
});
+ }
+ @DELETE
+ @ApiImplicitParams({
+ @ApiImplicitParam(required = true, dataType = "string", name = "username", paramType = "path")
+ })
+ @ApiOperation(value = "Deleting user mailboxes.")
+ @ApiResponses(value = {
+ @ApiResponse(code = 204, message = "The user does not have any mailbox", response = String.class),
+ @ApiResponse(code = 401, message = "Unauthorized. The user is not authenticated on the platform"),
+ @ApiResponse(code = 404, message = "The user name does not exist."),
+ @ApiResponse(code = 500, message = "Internal server error - Something went bad on the server side.")
+ })
+ public void defineDeleteUserMailboxes() {
service.delete(USER_MAILBOXES_BASE, (request, response) -> {
try {
userMailboxesService.deleteMailboxes(request.params(USER_NAME));
@@ -96,7 +161,23 @@ public class UserMailboxesRoutes implements Routes {
}
return Constants.EMPTY_BODY;
});
+ }
+ @GET
+ @Path("/{mailboxName}")
+ @ApiImplicitParams({
+ @ApiImplicitParam(required = true, dataType = "string", name = "username", paramType = "path"),
+ @ApiImplicitParam(required = true, dataType = "string", name = "mailboxName", paramType = "path")
+ })
+ @ApiOperation(value = "Testing existence of a mailbox.")
+ @ApiResponses(value = {
+ @ApiResponse(code = 204, message = "The mailbox exists", response = String.class),
+ @ApiResponse(code = 400, message = "Invalid mailbox name"),
+ @ApiResponse(code = 401, message = "Unauthorized. The user is not authenticated on the platform"),
+ @ApiResponse(code = 404, message = "The user name does not exist."),
+ @ApiResponse(code = 500, message = "Internal server error - Something went bad on the server side.")
+ })
+ public void defineMailboxExists() {
service.get(SPECIFIC_MAILBOX, (request, response) -> {
try {
if (userMailboxesService.testMailboxExists(request.params(USER_NAME), new MailboxName(request.params(MAILBOX_NAME)))) {
@@ -113,17 +194,35 @@ public class UserMailboxesRoutes implements Routes {
}
return Constants.EMPTY_BODY;
});
+ }
- service.get(USER_MAILBOXES_BASE, (request, response) -> {
- response.status(200);
+ @PUT
+ @Path("/{mailboxName}")
+ @ApiOperation(value = "Create a mailbox of the selected user.", nickname = "CreateUserMailbox")
+ @ApiImplicitParams({
+ @ApiImplicitParam(required = true, dataType = "string", name = "username", paramType = "path"),
+ @ApiImplicitParam(required = true, dataType = "string", name = "mailboxName", paramType = "path")
+ })
+ @ApiResponses(value = {
+ @ApiResponse(code = 204, message = "OK. The mailbox now exists on the server.", response = String.class),
+ @ApiResponse(code = 400, message = "Invalid mailbox name"),
+ @ApiResponse(code = 401, message = "Unauthorized. The user is not authenticated on the platform"),
+ @ApiResponse(code = 404, message = "The user name does not exist."),
+ @ApiResponse(code = 500, message = "Internal server error - Something went bad on the server side.")
+ })
+ public void defineCreateUserMailbox() {
+ service.put(SPECIFIC_MAILBOX, (request, response) -> {
try {
- return userMailboxesService.listMailboxes(request.params(USER_NAME));
+ userMailboxesService.createMailbox(request.params(USER_NAME), new MailboxName(request.params(MAILBOX_NAME)));
+ response.status(204);
} catch (IllegalStateException e) {
- LOGGER.info("Invalid get on user mailboxes", e);
+ LOGGER.info("Invalid put on user mailbox", e);
response.status(404);
- return Constants.EMPTY_BODY;
+ } catch (IllegalArgumentException e) {
+ LOGGER.info("Attempt to create an invalid mailbox");
+ response.status(400);
}
- }, jsonTransformer);
-
+ return Constants.EMPTY_BODY;
+ });
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[2/7] james-project git commit: JAMES-2099 Guice module binding for
swagger routes
Posted by bt...@apache.org.
JAMES-2099 Guice module binding for swagger routes
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/7ce7371d
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/7ce7371d
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/7ce7371d
Branch: refs/heads/master
Commit: 7ce7371d05e503df9a40b7633b16b4171d85470a
Parents: 4363f0a
Author: quynhn <qn...@linagora.com>
Authored: Tue Jul 25 10:50:51 2017 +0700
Committer: quynhn <qn...@linagora.com>
Committed: Mon Jul 31 10:35:46 2017 +0700
----------------------------------------------------------------------
.../guice/protocols/webadmin-swagger/pom.xml | 206 +++++++++++++++++++
.../modules/server/SwaggerRoutesModules.java | 35 ++++
2 files changed, 241 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/7ce7371d/server/container/guice/protocols/webadmin-swagger/pom.xml
----------------------------------------------------------------------
diff --git a/server/container/guice/protocols/webadmin-swagger/pom.xml b/server/container/guice/protocols/webadmin-swagger/pom.xml
new file mode 100644
index 0000000..b291856
--- /dev/null
+++ b/server/container/guice/protocols/webadmin-swagger/pom.xml
@@ -0,0 +1,206 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<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.1.0-SNAPSHOT</version>
+ <relativePath>../../pom.xml</relativePath>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+
+ <artifactId>james-server-guice-webadmin-swagger</artifactId>
+
+ <name>Apache James :: Server :: Guice :: Webadmin :: Swagger</name>
+ <description>Webadmin swagger 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-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.james</groupId>
+ <artifactId>james-server-webadmin-swagger</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/7ce7371d/server/container/guice/protocols/webadmin-swagger/src/main/java/org/apache/james/modules/server/SwaggerRoutesModules.java
----------------------------------------------------------------------
diff --git a/server/container/guice/protocols/webadmin-swagger/src/main/java/org/apache/james/modules/server/SwaggerRoutesModules.java b/server/container/guice/protocols/webadmin-swagger/src/main/java/org/apache/james/modules/server/SwaggerRoutesModules.java
new file mode 100644
index 0000000..a633c4f
--- /dev/null
+++ b/server/container/guice/protocols/webadmin-swagger/src/main/java/org/apache/james/modules/server/SwaggerRoutesModules.java
@@ -0,0 +1,35 @@
+/****************************************************************
+ * 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 org.apache.james.webadmin.Routes;
+import org.apache.james.webadmin.swagger.routes.SwaggerRoutes;
+
+import com.google.inject.AbstractModule;
+import com.google.inject.multibindings.Multibinder;
+
+public class SwaggerRoutesModules extends AbstractModule {
+
+ @Override
+ protected void configure() {
+ Multibinder<Routes> routesMultibinder = Multibinder.newSetBinder(binder(), Routes.class);
+ routesMultibinder.addBinding().to(SwaggerRoutes.class);
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[3/7] james-project git commit: JAMES-2099 Add James REST API to
expose the swagger API
Posted by bt...@apache.org.
JAMES-2099 Add James REST API to expose the swagger API
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/4363f0a2
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/4363f0a2
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/4363f0a2
Branch: refs/heads/master
Commit: 4363f0a24e426abe76d55ae009eb9db3e752c3f8
Parents: b4f432a
Author: quynhn <qn...@linagora.com>
Authored: Tue Jul 25 10:49:35 2017 +0700
Committer: quynhn <qn...@linagora.com>
Committed: Mon Jul 31 10:35:46 2017 +0700
----------------------------------------------------------------------
.../protocols/webadmin/webadmin-swagger/pom.xml | 212 +++++++++++++++++++
.../james/webadmin/swagger/SwaggerParser.java | 84 ++++++++
.../webadmin/swagger/routes/SwaggerRoutes.java | 48 +++++
3 files changed, 344 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/4363f0a2/server/protocols/webadmin/webadmin-swagger/pom.xml
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/webadmin-swagger/pom.xml b/server/protocols/webadmin/webadmin-swagger/pom.xml
new file mode 100644
index 0000000..81e654c
--- /dev/null
+++ b/server/protocols/webadmin/webadmin-swagger/pom.xml
@@ -0,0 +1,212 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<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/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <artifactId>james-server</artifactId>
+ <groupId>org.apache.james</groupId>
+ <version>3.1.0-SNAPSHOT</version>
+ <relativePath>../../../pom.xml</relativePath>
+ </parent>
+
+ <artifactId>james-server-webadmin-swagger</artifactId>
+ <packaging>jar</packaging>
+
+ <name>Apache James :: Server :: Web Admin :: Swagger</name>
+
+ <profiles>
+ <profile>
+ <id>noTest</id>
+ <activation>
+ <os>
+ <family>windows</family>
+ </os>
+ </activation>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <skipTests>true</skipTests>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+ <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>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.james</groupId>
+ <artifactId>james-server-webadmin-core</artifactId>
+ </dependency>
+ </dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-assembly-plugin</artifactId>
+ <configuration>
+ <archive>
+ <manifest>
+ <mainClass>fully.qualified.MainClass</mainClass>
+ </manifest>
+ </archive>
+ <descriptorRefs>
+ <descriptorRef>jar-with-dependencies</descriptorRef>
+ </descriptorRefs>
+ </configuration>
+ </plugin>
+ <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>
+ </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/4363f0a2/server/protocols/webadmin/webadmin-swagger/src/main/java/org/apache/james/webadmin/swagger/SwaggerParser.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/webadmin-swagger/src/main/java/org/apache/james/webadmin/swagger/SwaggerParser.java b/server/protocols/webadmin/webadmin-swagger/src/main/java/org/apache/james/webadmin/swagger/SwaggerParser.java
new file mode 100644
index 0000000..8ebd303
--- /dev/null
+++ b/server/protocols/webadmin/webadmin-swagger/src/main/java/org/apache/james/webadmin/swagger/SwaggerParser.java
@@ -0,0 +1,84 @@
+/****************************************************************
+ * 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.webadmin.swagger;
+
+import javax.inject.Inject;
+
+import org.apache.james.webadmin.WebAdminConfiguration;
+
+import com.fasterxml.jackson.annotation.JsonInclude.Include;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+import io.swagger.annotations.Api;
+import io.swagger.annotations.SwaggerDefinition;
+import io.swagger.jaxrs.Reader;
+import io.swagger.jaxrs.config.BeanConfig;
+import io.swagger.models.Swagger;
+import org.reflections.Reflections;
+
+@SwaggerDefinition
+public class SwaggerParser {
+ private static final String[] SCHEMES = new String[]{SwaggerDefinition.Scheme.HTTP.name(), SwaggerDefinition.Scheme.HTTPS.name()};
+ private static final String JSON_TYPE = "application/json";
+ private static final String API_DOC_VERSION = "V1.0";
+ private static final String API_DOC_TITLE = "JAMES Web Admin API";
+ private static final String API_DOC_DESCRIPTION = "All the web administration API for JAMES";
+ private static final String JAMES_WEBADMIN_HOST = "localhost:";
+
+ @Inject
+ public static String getSwaggerJson(String packageName, WebAdminConfiguration configuration) throws JsonProcessingException {
+ return swaggerToJson(getSwagger(packageName, configuration));
+ }
+
+ private static Swagger getSwagger(String packageName, WebAdminConfiguration configuration) {
+ return new Reader(getSwagger(getBeanConfig(packageName, configuration)))
+ .read(new Reflections(packageName)
+ .getTypesAnnotatedWith(Api.class));
+ }
+
+ private static Swagger getSwagger(BeanConfig beanConfig) {
+ Swagger swagger = beanConfig.getSwagger();
+
+ swagger.addConsumes(JSON_TYPE);
+ swagger.addProduces(JSON_TYPE);
+ return swagger;
+ }
+
+ private static BeanConfig getBeanConfig(String packageName, WebAdminConfiguration configuration) {
+ BeanConfig beanConfig = new BeanConfig();
+ beanConfig.setResourcePackage(packageName);
+ beanConfig.setVersion(API_DOC_VERSION);
+ beanConfig.setTitle(API_DOC_TITLE);
+ beanConfig.setDescription(API_DOC_DESCRIPTION);
+ beanConfig.setHost(JAMES_WEBADMIN_HOST + configuration.getPort().toInt());
+ beanConfig.setSchemes(SCHEMES);
+ beanConfig.setScan(true);
+ beanConfig.scanAndRead();
+ return beanConfig;
+ }
+
+ public static String swaggerToJson(Swagger swagger) throws JsonProcessingException {
+ ObjectMapper objectMapper = new ObjectMapper();
+ objectMapper.setSerializationInclusion(Include.NON_EMPTY);
+ return objectMapper.writeValueAsString(swagger);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/4363f0a2/server/protocols/webadmin/webadmin-swagger/src/main/java/org/apache/james/webadmin/swagger/routes/SwaggerRoutes.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/webadmin-swagger/src/main/java/org/apache/james/webadmin/swagger/routes/SwaggerRoutes.java b/server/protocols/webadmin/webadmin-swagger/src/main/java/org/apache/james/webadmin/swagger/routes/SwaggerRoutes.java
new file mode 100644
index 0000000..d6d364e
--- /dev/null
+++ b/server/protocols/webadmin/webadmin-swagger/src/main/java/org/apache/james/webadmin/swagger/routes/SwaggerRoutes.java
@@ -0,0 +1,48 @@
+/****************************************************************
+ * 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.webadmin.swagger.routes;
+
+
+import javax.inject.Inject;
+
+import org.apache.james.webadmin.Routes;
+import org.apache.james.webadmin.WebAdminConfiguration;
+import org.apache.james.webadmin.swagger.SwaggerParser;
+
+import spark.Service;
+
+public class SwaggerRoutes implements Routes {
+ public static final String SWAGGER_ENDPOINT = "/james-swagger";
+ private static final String APP_PACKAGE = "org.apache.james.webadmin.routes";
+ private final WebAdminConfiguration webAdminConfiguration;
+
+ @Inject
+ public SwaggerRoutes(WebAdminConfiguration webAdminConfiguration) {
+ this.webAdminConfiguration = webAdminConfiguration;
+ }
+
+ @Override
+ public void define(Service service) {
+ service.get(SWAGGER_ENDPOINT, (request, response) -> {
+ response.status(200);
+ return SwaggerParser.getSwaggerJson(APP_PACKAGE, webAdminConfiguration);
+ });
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[6/7] james-project git commit: JAMES-2099 Add admin configuration
for host which should be used on swagger
Posted by bt...@apache.org.
JAMES-2099 Add admin configuration for host which should be used on swagger
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/5c2baa7b
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/5c2baa7b
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/5c2baa7b
Branch: refs/heads/master
Commit: 5c2baa7beddadd67473dfc1ec5240665ac5554f4
Parents: 9cd602f
Author: quynhn <qn...@linagora.com>
Authored: Wed Jul 26 12:06:01 2017 +0700
Committer: quynhn <qn...@linagora.com>
Committed: Mon Jul 31 10:57:04 2017 +0700
----------------------------------------------------------------------
.../etc/james/templates/webadmin.properties | 1 +
.../destination/conf/webadmin.properties | 1 +
.../destination/conf/webadmin.properties | 1 +
.../sample-configuration/webadmin.properties | 3 ++-
.../modules/server/WebAdminServerModule.java | 1 +
.../src/test/resources/webadmin.properties | 3 ++-
.../james/webadmin/WebAdminConfiguration.java | 24 ++++++++++++++++----
.../james/webadmin/swagger/SwaggerParser.java | 4 ++--
8 files changed, 30 insertions(+), 8 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/5c2baa7b/dockerfiles/packaging/debian/package/etc/james/templates/webadmin.properties
----------------------------------------------------------------------
diff --git a/dockerfiles/packaging/debian/package/etc/james/templates/webadmin.properties b/dockerfiles/packaging/debian/package/etc/james/templates/webadmin.properties
index 38e2ba0..36b6f1e 100644
--- a/dockerfiles/packaging/debian/package/etc/james/templates/webadmin.properties
+++ b/dockerfiles/packaging/debian/package/etc/james/templates/webadmin.properties
@@ -20,6 +20,7 @@
enabled=true
port=8000
+host=localhost
# Defaults to false
https.enabled=false
http://git-wip-us.apache.org/repos/asf/james-project/blob/5c2baa7b/dockerfiles/run/guice/cassandra-ldap/destination/conf/webadmin.properties
----------------------------------------------------------------------
diff --git a/dockerfiles/run/guice/cassandra-ldap/destination/conf/webadmin.properties b/dockerfiles/run/guice/cassandra-ldap/destination/conf/webadmin.properties
index 38e2ba0..36b6f1e 100644
--- a/dockerfiles/run/guice/cassandra-ldap/destination/conf/webadmin.properties
+++ b/dockerfiles/run/guice/cassandra-ldap/destination/conf/webadmin.properties
@@ -20,6 +20,7 @@
enabled=true
port=8000
+host=localhost
# Defaults to false
https.enabled=false
http://git-wip-us.apache.org/repos/asf/james-project/blob/5c2baa7b/dockerfiles/run/guice/cassandra/destination/conf/webadmin.properties
----------------------------------------------------------------------
diff --git a/dockerfiles/run/guice/cassandra/destination/conf/webadmin.properties b/dockerfiles/run/guice/cassandra/destination/conf/webadmin.properties
index 38e2ba0..36b6f1e 100644
--- a/dockerfiles/run/guice/cassandra/destination/conf/webadmin.properties
+++ b/dockerfiles/run/guice/cassandra/destination/conf/webadmin.properties
@@ -20,6 +20,7 @@
enabled=true
port=8000
+host=localhost
# Defaults to false
https.enabled=false
http://git-wip-us.apache.org/repos/asf/james-project/blob/5c2baa7b/server/container/guice/memory-guice/sample-configuration/webadmin.properties
----------------------------------------------------------------------
diff --git a/server/container/guice/memory-guice/sample-configuration/webadmin.properties b/server/container/guice/memory-guice/sample-configuration/webadmin.properties
index 70a6cb9..a9b5cc2 100644
--- a/server/container/guice/memory-guice/sample-configuration/webadmin.properties
+++ b/server/container/guice/memory-guice/sample-configuration/webadmin.properties
@@ -19,4 +19,5 @@
# DO NOT USE IT AS SUCH AND ADAPT IT TO YOUR NEEDS
enabled=true
-port=8000
\ No newline at end of file
+port=8000
+host=localhost
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/james-project/blob/5c2baa7b/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
index c7820cc..88c1cd6 100644
--- 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
@@ -86,6 +86,7 @@ public class WebAdminServerModule extends AbstractModule {
.tls(readHttpsConfiguration(configurationFile))
.enableCORS(configurationFile.getBoolean("cors.enable", DEFAULT_CORS_DISABLED))
.urlCORSOrigin(configurationFile.getString("cors.origin", DEFAULT_NO_CORS_ORIGIN))
+ .host(configurationFile.getString("host", WebAdminConfiguration.DEFAULT_HOST))
.build();
} catch (FileNotFoundException e) {
LOGGER.info("No webadmin.properties file. Disabling WebAdmin interface.");
http://git-wip-us.apache.org/repos/asf/james-project/blob/5c2baa7b/server/protocols/webadmin-integration-test/src/test/resources/webadmin.properties
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin-integration-test/src/test/resources/webadmin.properties b/server/protocols/webadmin-integration-test/src/test/resources/webadmin.properties
index 09f46dd..475d655 100644
--- a/server/protocols/webadmin-integration-test/src/test/resources/webadmin.properties
+++ b/server/protocols/webadmin-integration-test/src/test/resources/webadmin.properties
@@ -1,2 +1,3 @@
enabled=true
-port=8000
\ No newline at end of file
+port=8000
+host=localhost
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/james-project/blob/5c2baa7b/server/protocols/webadmin/webadmin-core/src/main/java/org/apache/james/webadmin/WebAdminConfiguration.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/webadmin-core/src/main/java/org/apache/james/webadmin/WebAdminConfiguration.java b/server/protocols/webadmin/webadmin-core/src/main/java/org/apache/james/webadmin/WebAdminConfiguration.java
index 716645c..b7608cf 100644
--- a/server/protocols/webadmin/webadmin-core/src/main/java/org/apache/james/webadmin/WebAdminConfiguration.java
+++ b/server/protocols/webadmin/webadmin-core/src/main/java/org/apache/james/webadmin/WebAdminConfiguration.java
@@ -30,6 +30,7 @@ public class WebAdminConfiguration {
public static final boolean DEFAULT_CORS_DISABLED = false;
public static final String CORS_ALL_ORIGINS = "*";
+ public static final String DEFAULT_HOST = "localhost";
public static WebAdminConfiguration testingConfiguration() {
return WebAdminConfiguration.builder()
@@ -52,6 +53,7 @@ public class WebAdminConfiguration {
private Optional<Boolean> enableCORS = Optional.empty();
private Optional<TlsConfiguration> tlsConfiguration = Optional.empty();
private Optional<String> urlCORSOrigin = Optional.empty();
+ private Optional<String> host = Optional.empty();
public Builder tls(TlsConfiguration tlsConfiguration) {
this.tlsConfiguration = Optional.of(tlsConfiguration);
@@ -98,6 +100,11 @@ public class WebAdminConfiguration {
return enableCORS(false);
}
+ public Builder host(String host) {
+ this.host = Optional.ofNullable(host);
+ return this;
+ }
+
public WebAdminConfiguration build() {
Preconditions.checkState(enabled.isPresent(), "You need to explicitly enable or disable WebAdmin server");
Preconditions.checkState(!enabled.get() || port.isPresent(), "You need to specify a port for WebAdminConfiguration");
@@ -105,7 +112,8 @@ public class WebAdminConfiguration {
port,
tlsConfiguration,
enableCORS.orElse(DEFAULT_CORS_DISABLED),
- urlCORSOrigin.orElse(CORS_ALL_ORIGINS));
+ urlCORSOrigin.orElse(CORS_ALL_ORIGINS),
+ host.orElse(DEFAULT_HOST));
}
}
@@ -114,14 +122,17 @@ public class WebAdminConfiguration {
private final Optional<TlsConfiguration> tlsConfiguration;
private final boolean enableCORS;
private final String urlCORSOrigin;
+ private final String host;
@VisibleForTesting
- WebAdminConfiguration(boolean enabled, Optional<Port> port, Optional<TlsConfiguration> tlsConfiguration, boolean enableCORS, String urlCORSOrigin) {
+ WebAdminConfiguration(boolean enabled, Optional<Port> port, Optional<TlsConfiguration> tlsConfiguration,
+ boolean enableCORS, String urlCORSOrigin, String host) {
this.enabled = enabled;
this.port = port;
this.tlsConfiguration = tlsConfiguration;
this.enableCORS = enableCORS;
this.urlCORSOrigin = urlCORSOrigin;
+ this.host = host;
}
public boolean isEnabled() {
@@ -148,6 +159,10 @@ public class WebAdminConfiguration {
return tlsConfiguration.isPresent();
}
+ public String getHost() {
+ return host;
+ }
+
@Override
public final boolean equals(Object o) {
if (o instanceof WebAdminConfiguration) {
@@ -157,13 +172,14 @@ public class WebAdminConfiguration {
&& Objects.equals(this.port, that.port)
&& Objects.equals(this.tlsConfiguration, that.tlsConfiguration)
&& Objects.equals(this.enableCORS, that.enableCORS)
- && Objects.equals(this.urlCORSOrigin, that.urlCORSOrigin);
+ && Objects.equals(this.urlCORSOrigin, that.urlCORSOrigin)
+ && Objects.equals(this.host, that.host);
}
return false;
}
@Override
public final int hashCode() {
- return Objects.hash(enabled, port, tlsConfiguration, enableCORS, urlCORSOrigin);
+ return Objects.hash(enabled, port, tlsConfiguration, enableCORS, urlCORSOrigin, host);
}
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/5c2baa7b/server/protocols/webadmin/webadmin-swagger/src/main/java/org/apache/james/webadmin/swagger/SwaggerParser.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/webadmin-swagger/src/main/java/org/apache/james/webadmin/swagger/SwaggerParser.java b/server/protocols/webadmin/webadmin-swagger/src/main/java/org/apache/james/webadmin/swagger/SwaggerParser.java
index 8ebd303..7bdec19 100644
--- a/server/protocols/webadmin/webadmin-swagger/src/main/java/org/apache/james/webadmin/swagger/SwaggerParser.java
+++ b/server/protocols/webadmin/webadmin-swagger/src/main/java/org/apache/james/webadmin/swagger/SwaggerParser.java
@@ -41,7 +41,7 @@ public class SwaggerParser {
private static final String API_DOC_VERSION = "V1.0";
private static final String API_DOC_TITLE = "JAMES Web Admin API";
private static final String API_DOC_DESCRIPTION = "All the web administration API for JAMES";
- private static final String JAMES_WEBADMIN_HOST = "localhost:";
+ public static final String HOST_PORT_SEPARATOR = ":";
@Inject
public static String getSwaggerJson(String packageName, WebAdminConfiguration configuration) throws JsonProcessingException {
@@ -68,7 +68,7 @@ public class SwaggerParser {
beanConfig.setVersion(API_DOC_VERSION);
beanConfig.setTitle(API_DOC_TITLE);
beanConfig.setDescription(API_DOC_DESCRIPTION);
- beanConfig.setHost(JAMES_WEBADMIN_HOST + configuration.getPort().toInt());
+ beanConfig.setHost(configuration.getHost() + HOST_PORT_SEPARATOR + configuration.getPort().toInt());
beanConfig.setSchemes(SCHEMES);
beanConfig.setScan(true);
beanConfig.scanAndRead();
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[7/7] james-project git commit: JAMES-2099 Swagger API for User and
Domains
Posted by bt...@apache.org.
JAMES-2099 Swagger API for User and Domains
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/9ed12378
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/9ed12378
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/9ed12378
Branch: refs/heads/master
Commit: 9ed12378ac12f5318cf5a3b5daa215023fb37930
Parents: 5c2baa7
Author: quynhn <qn...@linagora.com>
Authored: Wed Jul 26 15:21:20 2017 +0700
Committer: quynhn <qn...@linagora.com>
Committed: Mon Jul 31 10:57:08 2017 +0700
----------------------------------------------------------------------
.../james/webadmin/routes/DomainRoutes.java | 83 ++++++++++++++++++--
.../james/webadmin/routes/UserRoutes.java | 69 +++++++++++++++-
2 files changed, 143 insertions(+), 9 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/9ed12378/server/protocols/webadmin/webadmin-data/src/main/java/org/apache/james/webadmin/routes/DomainRoutes.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/webadmin-data/src/main/java/org/apache/james/webadmin/routes/DomainRoutes.java b/server/protocols/webadmin/webadmin-data/src/main/java/org/apache/james/webadmin/routes/DomainRoutes.java
index 2008278..60c8952 100644
--- a/server/protocols/webadmin/webadmin-data/src/main/java/org/apache/james/webadmin/routes/DomainRoutes.java
+++ b/server/protocols/webadmin/webadmin-data/src/main/java/org/apache/james/webadmin/routes/DomainRoutes.java
@@ -21,13 +21,26 @@ package org.apache.james.webadmin.routes;
import static org.apache.james.webadmin.Constants.SEPARATOR;
+import java.util.List;
import javax.inject.Inject;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
import org.apache.james.domainlist.api.DomainList;
import org.apache.james.domainlist.api.DomainListException;
import org.apache.james.webadmin.Constants;
import org.apache.james.webadmin.Routes;
import org.apache.james.webadmin.utils.JsonTransformer;
+
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiImplicitParam;
+import io.swagger.annotations.ApiImplicitParams;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiResponse;
+import io.swagger.annotations.ApiResponses;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -38,6 +51,9 @@ import spark.Request;
import spark.Response;
import spark.Service;
+@Api(tags = "Domains")
+@Path(DomainRoutes.DOMAINS)
+@Produces("application/json")
public class DomainRoutes implements Routes {
private static final String DOMAIN_NAME = ":domainName";
@@ -50,6 +66,7 @@ public class DomainRoutes implements Routes {
private final DomainList domainList;
private final JsonTransformer jsonTransformer;
+ private Service service;
@Inject
public DomainRoutes(DomainList domainList, JsonTransformer jsonTransformer) {
@@ -59,17 +76,73 @@ public class DomainRoutes implements Routes {
@Override
public void define(Service service) {
- service.get(DOMAINS,
- (request, response) -> domainList.getDomains(),
- jsonTransformer);
+ this.service = service;
- service.get(SPECIFIC_DOMAIN, this::exists);
+ defineGetDomains();
- service.put(SPECIFIC_DOMAIN, this::addDomain);
+ defineDomainExists();
+
+ defineAddDomain();
+ defineDeleteDomain();
+ }
+
+ @DELETE
+ @Path("/{domainName}")
+ @ApiOperation(value = "Deleting a domain")
+ @ApiImplicitParams({
+ @ApiImplicitParam(required = true, dataType = "string", name = "domainName", paramType = "path")
+ })
+ @ApiResponses(value = {
+ @ApiResponse(code = 204, message = "OK. Domain is removed."),
+ @ApiResponse(code = 500, message = "Internal server error - Something went bad on the server side.")
+ })
+ public void defineDeleteDomain() {
service.delete(SPECIFIC_DOMAIN, this::removeDomain);
}
+ @PUT
+ @Path("/{domainName}")
+ @ApiOperation(value = "Creating new domain")
+ @ApiImplicitParams({
+ @ApiImplicitParam(required = true, dataType = "string", name = "domainName", paramType = "path")
+ })
+ @ApiResponses(value = {
+ @ApiResponse(code = 204, message = "OK. New domain is created."),
+ @ApiResponse(code = 400, message = "Invalid request for domain creation"),
+ @ApiResponse(code = 500, message = "Internal server error - Something went bad on the server side.")
+ })
+ public void defineAddDomain() {
+ service.put(SPECIFIC_DOMAIN, this::addDomain);
+ }
+
+ @GET
+ @Path("/{domainName}")
+ @ApiImplicitParams({
+ @ApiImplicitParam(required = true, dataType = "string", name = "domainName", paramType = "path")
+ })
+ @ApiOperation(value = "Testing existence of a domain.")
+ @ApiResponses(value = {
+ @ApiResponse(code = 204, message = "The domain exists", response = String.class),
+ @ApiResponse(code = 404, message = "The domain does not exist."),
+ @ApiResponse(code = 500, message = "Internal server error - Something went bad on the server side.")
+ })
+ public void defineDomainExists() {
+ service.get(SPECIFIC_DOMAIN, this::exists);
+ }
+
+ @GET
+ @ApiOperation(value = "Getting all domains")
+ @ApiResponses(value = {
+ @ApiResponse(code = 204, message = "OK", response = List.class),
+ @ApiResponse(code = 500, message = "Internal server error - Something went bad on the server side.")
+ })
+ public void defineGetDomains() {
+ service.get(DOMAINS,
+ (request, response) -> domainList.getDomains(),
+ jsonTransformer);
+ }
+
private String removeDomain(Request request, Response response) {
try {
String domain = request.params(DOMAIN_NAME);
http://git-wip-us.apache.org/repos/asf/james-project/blob/9ed12378/server/protocols/webadmin/webadmin-data/src/main/java/org/apache/james/webadmin/routes/UserRoutes.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/webadmin-data/src/main/java/org/apache/james/webadmin/routes/UserRoutes.java b/server/protocols/webadmin/webadmin-data/src/main/java/org/apache/james/webadmin/routes/UserRoutes.java
index 0ead90a..9c73542 100644
--- a/server/protocols/webadmin/webadmin-data/src/main/java/org/apache/james/webadmin/routes/UserRoutes.java
+++ b/server/protocols/webadmin/webadmin-data/src/main/java/org/apache/james/webadmin/routes/UserRoutes.java
@@ -22,15 +22,28 @@ package org.apache.james.webadmin.routes;
import static org.apache.james.webadmin.Constants.SEPARATOR;
import javax.inject.Inject;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
import org.apache.james.user.api.UsersRepositoryException;
import org.apache.james.webadmin.Constants;
import org.apache.james.webadmin.Routes;
import org.apache.james.webadmin.dto.AddUserRequest;
+import org.apache.james.webadmin.dto.UserResponse;
import org.apache.james.webadmin.service.UserService;
import org.apache.james.webadmin.utils.JsonExtractException;
import org.apache.james.webadmin.utils.JsonExtractor;
import org.apache.james.webadmin.utils.JsonTransformer;
+
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiImplicitParam;
+import io.swagger.annotations.ApiImplicitParams;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiResponse;
+import io.swagger.annotations.ApiResponses;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -38,6 +51,9 @@ import spark.Request;
import spark.Response;
import spark.Service;
+@Api(tags = "Users")
+@Path(UserRoutes.USERS)
+@Produces("application/json")
public class UserRoutes implements Routes {
private static final String USER_NAME = ":userName";
@@ -49,6 +65,8 @@ public class UserRoutes implements Routes {
private final JsonTransformer jsonTransformer;
private final JsonExtractor<AddUserRequest> jsonExtractor;
+ private Service service;
+
@Inject
public UserRoutes(UserService userService, JsonTransformer jsonTransformer) {
this.userService = userService;
@@ -58,15 +76,58 @@ public class UserRoutes implements Routes {
@Override
public void define(Service service) {
- service.get(USERS,
- (request, response) -> userService.getUsers(),
- jsonTransformer);
+ this.service = service;
- service.put(USERS + SEPARATOR + USER_NAME, this::upsertUser);
+ defineGetUsers();
+
+ defineCreateUser();
+
+ defineDeleteUser();
+ }
+ @DELETE
+ @Path("/{username}")
+ @ApiOperation(value = "Deleting an user")
+ @ApiImplicitParams({
+ @ApiImplicitParam(required = true, dataType = "string", name = "username", paramType = "path")
+ })
+ @ApiResponses(value = {
+ @ApiResponse(code = 204, message = "OK. User is removed."),
+ @ApiResponse(code = 400, message = "Invalid input user."),
+ @ApiResponse(code = 500, message = "Internal server error - Something went bad on the server side.")
+ })
+ public void defineDeleteUser() {
service.delete(USERS + SEPARATOR + USER_NAME, this::removeUser);
}
+ @PUT
+ @Path("/{username}")
+ @ApiOperation(value = "Creating an user")
+ @ApiImplicitParams({
+ @ApiImplicitParam(required = true, dataType = "string", name = "username", paramType = "path"),
+ @ApiImplicitParam(required = true, dataType = "org.apache.james.webadmin.dto.AddUserRequest", paramType = "body")
+ })
+ @ApiResponses(value = {
+ @ApiResponse(code = 204, message = "OK. New user is added."),
+ @ApiResponse(code = 400, message = "Invalid input user."),
+ @ApiResponse(code = 500, message = "Internal server error - Something went bad on the server side.")
+ })
+ public void defineCreateUser() {
+ service.put(USERS + SEPARATOR + USER_NAME, this::upsertUser);
+ }
+
+ @GET
+ @ApiOperation(value = "Getting all users")
+ @ApiResponses(value = {
+ @ApiResponse(code = 204, message = "OK.", response = UserResponse.class),
+ @ApiResponse(code = 500, message = "Internal server error - Something went bad on the server side.")
+ })
+ public void defineGetUsers() {
+ service.get(USERS,
+ (request, response) -> userService.getUsers(),
+ jsonTransformer);
+ }
+
private String removeUser(Request request, Response response) {
String username = request.params(USER_NAME);
try {
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org