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/12/06 02:10:51 UTC

[1/5] james-project git commit: JAMES-2233 WebAdmin update document with error message in case of error

Repository: james-project
Updated Branches:
  refs/heads/master 16410ae2d -> 21188d00e


JAMES-2233 WebAdmin update document with error message in case of error


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

Branch: refs/heads/master
Commit: 1787c9c96411f0659b04f0549923e3d710feb255
Parents: bde6bdb
Author: quynhn <qn...@linagora.com>
Authored: Mon Dec 4 14:15:58 2017 +0700
Committer: benwa <bt...@linagora.com>
Committed: Wed Dec 6 09:10:07 2017 +0700

----------------------------------------------------------------------
 src/site/markdown/server/manage-webadmin.md | 8 ++++++++
 1 file changed, 8 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/1787c9c9/src/site/markdown/server/manage-webadmin.md
----------------------------------------------------------------------
diff --git a/src/site/markdown/server/manage-webadmin.md b/src/site/markdown/server/manage-webadmin.md
index 8f3f7e0..1484d21 100644
--- a/src/site/markdown/server/manage-webadmin.md
+++ b/src/site/markdown/server/manage-webadmin.md
@@ -7,6 +7,14 @@ The web administration supports for now the CRUD operations on the domains,the u
 
 Please also note **webadmin** is only enabled with **Guice**. You can not use it when using James with **Spring**, as the required injections are not implemented.
 
+In case of any error, the system will return an error message which is json format like this:
+{
+    statusCode: <error_code>,
+    type: <error_type>,
+    message: <the_error_message>
+    cause: <the_detail_message_from_throwable>
+}
+
 ## Administrating domains
 
 ### Create a domain


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


[5/5] james-project git commit: JAMES-2233 uniformize HttpResponse code constant in Webadmin

Posted by bt...@apache.org.
JAMES-2233 uniformize HttpResponse code constant in Webadmin


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

Branch: refs/heads/master
Commit: 21188d00e37d425289b77da4b2ab650991c656bc
Parents: 1787c9c
Author: Luc DUZAN <ld...@linagora.com>
Authored: Mon Dec 4 15:16:25 2017 +0100
Committer: benwa <bt...@linagora.com>
Committed: Wed Dec 6 09:10:16 2017 +0700

----------------------------------------------------------------------
 .../integration/JwtFilterIntegrationTest.java   |   7 +-
 .../WebAdminServerIntegrationTest.java          |  31 ++--
 .../routes/CassandraMigrationRoutes.java        |  31 ++--
 .../routes/CassandraMigrationRoutesTest.java    |  25 +--
 .../webadmin/authentication/JwtFilter.java      |   7 +-
 .../james/webadmin/utils/ErrorResponder.java    |   2 +-
 .../webadmin/authentication/JwtFilterTest.java  |   3 +-
 .../webadmin/utils/ErrorResponderTest.java      |  35 ++--
 .../james/webadmin/routes/DomainsRoutes.java    |  28 ++--
 .../james/webadmin/routes/GroupsRoutes.java     |  33 ++--
 .../james/webadmin/routes/UserRoutes.java       |  21 +--
 .../james/webadmin/service/UserService.java     |   5 +-
 .../webadmin/routes/DomainsRoutesTest.java      |  51 +++---
 .../james/webadmin/routes/GroupsRoutesTest.java |  16 +-
 .../james/webadmin/routes/UsersRoutesTest.java  |  59 +++----
 .../webadmin/routes/GlobalQuotaRoutes.java      |  56 ++++---
 .../webadmin/routes/UserMailboxesRoutes.java    |  56 +++----
 .../webadmin/routes/GlobalQuotaRoutesTest.java  |  46 +++---
 .../routes/UserMailboxesRoutesTest.java         | 159 ++++++++++---------
 .../webadmin/swagger/routes/SwaggerRoutes.java  |   3 +-
 20 files changed, 348 insertions(+), 326 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/21188d00/server/protocols/webadmin-integration-test/src/test/java/org/apache/james/webadmin/integration/JwtFilterIntegrationTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin-integration-test/src/test/java/org/apache/james/webadmin/integration/JwtFilterIntegrationTest.java b/server/protocols/webadmin-integration-test/src/test/java/org/apache/james/webadmin/integration/JwtFilterIntegrationTest.java
index 97e6deb..429db13 100644
--- a/server/protocols/webadmin-integration-test/src/test/java/org/apache/james/webadmin/integration/JwtFilterIntegrationTest.java
+++ b/server/protocols/webadmin-integration-test/src/test/java/org/apache/james/webadmin/integration/JwtFilterIntegrationTest.java
@@ -37,6 +37,7 @@ import org.apache.james.utils.WebAdminGuiceProbe;
 import org.apache.james.webadmin.authentication.AuthenticationFilter;
 import org.apache.james.webadmin.authentication.JwtFilter;
 import org.apache.james.webadmin.routes.DomainsRoutes;
+import org.eclipse.jetty.http.HttpStatus;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.ClassRule;
@@ -108,7 +109,7 @@ public class JwtFilterIntegrationTest {
         .when()
             .put(SPECIFIC_DOMAIN)
         .then()
-            .statusCode(204);
+            .statusCode(HttpStatus.NO_CONTENT_204);
 
         assertThat(dataProbe.listDomains())
             .contains(DOMAIN);
@@ -122,7 +123,7 @@ public class JwtFilterIntegrationTest {
         .when()
             .put(SPECIFIC_DOMAIN)
         .then()
-            .statusCode(401);
+            .statusCode(HttpStatus.UNAUTHORIZED_401);
 
         assertThat(dataProbe.listDomains())
             .doesNotContain(DOMAIN);
@@ -136,7 +137,7 @@ public class JwtFilterIntegrationTest {
         .when()
             .put(SPECIFIC_DOMAIN)
         .then()
-            .statusCode(401);
+            .statusCode(HttpStatus.UNAUTHORIZED_401);
 
         assertThat(dataProbe.listDomains())
             .doesNotContain(DOMAIN);

http://git-wip-us.apache.org/repos/asf/james-project/blob/21188d00/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 30c810d..d468ddb 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
@@ -42,6 +42,7 @@ import org.apache.james.webadmin.routes.DomainsRoutes;
 import org.apache.james.webadmin.routes.UserMailboxesRoutes;
 import org.apache.james.webadmin.routes.UserRoutes;
 import org.apache.james.webadmin.swagger.routes.SwaggerRoutes;
+import org.eclipse.jetty.http.HttpStatus;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.ClassRule;
@@ -103,7 +104,7 @@ public class WebAdminServerIntegrationTest {
         .when()
             .put(SPECIFIC_DOMAIN)
         .then()
-            .statusCode(204);
+            .statusCode(HttpStatus.NO_CONTENT_204);
 
         assertThat(dataProbe.listDomains()).contains(DOMAIN);
     }
@@ -117,7 +118,7 @@ public class WebAdminServerIntegrationTest {
         .when()
             .delete(SPECIFIC_DOMAIN)
         .then()
-            .statusCode(204);
+            .statusCode(HttpStatus.NO_CONTENT_204);
 
         assertThat(dataProbe.listDomains()).doesNotContain(DOMAIN);
     }
@@ -132,7 +133,7 @@ public class WebAdminServerIntegrationTest {
         .when()
             .put(SPECIFIC_USER)
         .then()
-            .statusCode(204);
+            .statusCode(HttpStatus.NO_CONTENT_204);
 
         assertThat(dataProbe.listUsers()).contains(USERNAME);
     }
@@ -148,7 +149,7 @@ public class WebAdminServerIntegrationTest {
         .when()
             .delete(SPECIFIC_USER)
         .then()
-            .statusCode(204);
+            .statusCode(HttpStatus.NO_CONTENT_204);
 
         assertThat(dataProbe.listUsers()).doesNotContain(USERNAME);
     }
@@ -163,7 +164,7 @@ public class WebAdminServerIntegrationTest {
         .when()
             .get(UserRoutes.USERS)
         .then()
-            .statusCode(200)
+            .statusCode(HttpStatus.OK_200)
             .contentType(JSON_CONTENT_TYPE)
             .body(is("[{\"username\":\"username@domain\"}]"));
     }
@@ -178,7 +179,7 @@ public class WebAdminServerIntegrationTest {
         .when()
             .put(SPECIFIC_MAILBOX)
         .then()
-            .statusCode(204);
+            .statusCode(HttpStatus.NO_CONTENT_204);
 
         assertThat(guiceJamesServer.getProbe(MailboxProbeImpl.class).listUserMailboxes(USERNAME)).containsExactly(MAILBOX);
     }
@@ -194,7 +195,7 @@ public class WebAdminServerIntegrationTest {
         .when()
             .delete(SPECIFIC_MAILBOX)
         .then()
-            .statusCode(204);
+            .statusCode(HttpStatus.NO_CONTENT_204);
 
         assertThat(guiceJamesServer.getProbe(MailboxProbeImpl.class).listUserMailboxes(USERNAME)).isEmpty();
     }
@@ -206,7 +207,7 @@ public class WebAdminServerIntegrationTest {
         .when()
             .get(VERSION)
         .then()
-            .statusCode(200)
+            .statusCode(HttpStatus.OK_200)
             .contentType(JSON_CONTENT_TYPE)
             .body(is("{\"version\":null}"));
     }
@@ -218,7 +219,7 @@ public class WebAdminServerIntegrationTest {
         .when()
             .get(VERSION_LATEST)
         .then()
-            .statusCode(200)
+            .statusCode(HttpStatus.OK_200)
             .contentType(JSON_CONTENT_TYPE)
             .body(is("{\"version\":" + CassandraSchemaVersionManager.MAX_VERSION + "}"));
     }
@@ -231,14 +232,14 @@ public class WebAdminServerIntegrationTest {
         .when()
             .post(UPGRADE_VERSION)
         .then()
-            .statusCode(204);
+            .statusCode(HttpStatus.NO_CONTENT_204);
 
         given()
             .port(webAdminGuiceProbe.getWebAdminPort())
         .when()
             .get(VERSION)
         .then()
-            .statusCode(200)
+            .statusCode(HttpStatus.OK_200)
             .contentType(JSON_CONTENT_TYPE)
             .body(is("{\"version\":" + CassandraSchemaVersionManager.MAX_VERSION + "}"));
     }
@@ -250,14 +251,14 @@ public class WebAdminServerIntegrationTest {
         .when()
             .post(UPGRADE_TO_LATEST_VERSION)
         .then()
-            .statusCode(200);
+            .statusCode(HttpStatus.OK_200);
 
         given()
             .port(webAdminGuiceProbe.getWebAdminPort())
         .when()
             .get(VERSION)
         .then()
-            .statusCode(200)
+            .statusCode(HttpStatus.OK_200)
             .contentType(JSON_CONTENT_TYPE)
             .body(is("{\"version\":" + CassandraSchemaVersionManager.MAX_VERSION + "}"));
     }
@@ -272,7 +273,7 @@ public class WebAdminServerIntegrationTest {
             .when()
             .get("/address/groups/group@domain.com")
             .then()
-            .statusCode(200)
+            .statusCode(HttpStatus.OK_200)
             .contentType(JSON_CONTENT_TYPE)
             .extract()
             .jsonPath()
@@ -287,7 +288,7 @@ public class WebAdminServerIntegrationTest {
         .when()
             .get(SwaggerRoutes.SWAGGER_ENDPOINT)
         .then()
-            .statusCode(200)
+            .statusCode(HttpStatus.OK_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\"]"))

http://git-wip-us.apache.org/repos/asf/james-project/blob/21188d00/server/protocols/webadmin/webadmin-cassandra/src/main/java/org/apache/james/webadmin/routes/CassandraMigrationRoutes.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/webadmin-cassandra/src/main/java/org/apache/james/webadmin/routes/CassandraMigrationRoutes.java b/server/protocols/webadmin/webadmin-cassandra/src/main/java/org/apache/james/webadmin/routes/CassandraMigrationRoutes.java
index ff08bea..3a42657 100644
--- a/server/protocols/webadmin/webadmin-cassandra/src/main/java/org/apache/james/webadmin/routes/CassandraMigrationRoutes.java
+++ b/server/protocols/webadmin/webadmin-cassandra/src/main/java/org/apache/james/webadmin/routes/CassandraMigrationRoutes.java
@@ -43,11 +43,14 @@ public class CassandraMigrationRoutes implements Routes {
     private static final String VERSION_BASE_LATEST = VERSION_BASE + "/latest";
     private static final String VERSION_UPGRADE_BASE = VERSION_BASE + "/upgrade";
     private static final String VERSION_UPGRADE_TO_LATEST_BASE = VERSION_UPGRADE_BASE + "/latest";
-    private static final int NO_CONTENT = 204;
 
     private final CassandraMigrationService cassandraMigrationService;
     private final JsonTransformer jsonTransformer;
 
+    public static String INVALID_VERSION_UPGRADE_REQUEST = "Invalid request for version upgrade";
+    public static String MIGRATION_REQUEST_CAN_NOT_BE_DONE = "The migration requested can not be performed";
+    public static String PARTIAL_MIGRATION_PROCESS = "An error lead to partial migration process";
+
     @Inject
     public CassandraMigrationRoutes(CassandraMigrationService cassandraMigrationService, JsonTransformer jsonTransformer) {
         this.cassandraMigrationService = cassandraMigrationService;
@@ -69,29 +72,29 @@ public class CassandraMigrationRoutes implements Routes {
             try {
                 CassandraVersionRequest cassandraVersionRequest = CassandraVersionRequest.parse(request.body());
                 cassandraMigrationService.upgradeToVersion(cassandraVersionRequest.getValue());
-                response.status(NO_CONTENT);
+                response.status(HttpStatus.NO_CONTENT_204);
             } catch (NullPointerException | IllegalArgumentException e) {
-                LOGGER.info("Invalid request for version upgrade");
+                LOGGER.info(INVALID_VERSION_UPGRADE_REQUEST);
                 throw ErrorResponder.builder()
                     .statusCode(HttpStatus.BAD_REQUEST_400)
                     .type(ErrorType.INVALID_ARGUMENT)
-                    .message("Invalid request for version upgrade")
+                    .message(INVALID_VERSION_UPGRADE_REQUEST)
                     .cause(e)
                     .haltError();
             } catch (IllegalStateException e) {
-                LOGGER.info("The migration requested can not be performed.", e);
+                LOGGER.info(MIGRATION_REQUEST_CAN_NOT_BE_DONE, e);
                 throw ErrorResponder.builder()
-                    .statusCode(HttpStatus.GONE_410)
+                    .statusCode(HttpStatus.CONFLICT_409)
                     .type(ErrorType.WRONG_STATE)
-                    .message("The migration requested can not be performed")
+                    .message(MIGRATION_REQUEST_CAN_NOT_BE_DONE)
                     .cause(e)
                     .haltError();
             } catch (MigrationException e) {
-                LOGGER.error("An error lead to partial migration process", e);
+                LOGGER.error(PARTIAL_MIGRATION_PROCESS, e);
                 throw ErrorResponder.builder()
                     .statusCode(HttpStatus.INTERNAL_SERVER_ERROR_500)
                     .type(ErrorType.SERVER_ERROR)
-                    .message("An error lead to partial migration process")
+                    .message(PARTIAL_MIGRATION_PROCESS)
                     .cause(e)
                     .haltError();
             }
@@ -102,19 +105,19 @@ public class CassandraMigrationRoutes implements Routes {
             try {
                 cassandraMigrationService.upgradeToLastVersion();
             } catch (IllegalStateException e) {
-                LOGGER.info("The migration requested can not be performed.", e);
+                LOGGER.info(MIGRATION_REQUEST_CAN_NOT_BE_DONE, e);
                 throw ErrorResponder.builder()
-                    .statusCode(HttpStatus.GONE_410)
+                    .statusCode(HttpStatus.CONFLICT_409)
                     .type(ErrorType.WRONG_STATE)
-                    .message("The migration requested can not be performed")
+                    .message(MIGRATION_REQUEST_CAN_NOT_BE_DONE)
                     .cause(e)
                     .haltError();
             } catch (MigrationException e) {
-                LOGGER.error("An error lead to partial migration process", e);
+                LOGGER.error(PARTIAL_MIGRATION_PROCESS, e);
                 throw ErrorResponder.builder()
                     .statusCode(HttpStatus.INTERNAL_SERVER_ERROR_500)
                     .type(ErrorType.SERVER_ERROR)
-                    .message("An error lead to partial migration process")
+                    .message(PARTIAL_MIGRATION_PROCESS)
                     .cause(e)
                     .haltError();
             }

http://git-wip-us.apache.org/repos/asf/james-project/blob/21188d00/server/protocols/webadmin/webadmin-cassandra/src/test/java/org/apache/james/webadmin/routes/CassandraMigrationRoutesTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/webadmin-cassandra/src/test/java/org/apache/james/webadmin/routes/CassandraMigrationRoutesTest.java b/server/protocols/webadmin/webadmin-cassandra/src/test/java/org/apache/james/webadmin/routes/CassandraMigrationRoutesTest.java
index a6d6c14..e475373 100644
--- a/server/protocols/webadmin/webadmin-cassandra/src/test/java/org/apache/james/webadmin/routes/CassandraMigrationRoutesTest.java
+++ b/server/protocols/webadmin/webadmin-cassandra/src/test/java/org/apache/james/webadmin/routes/CassandraMigrationRoutesTest.java
@@ -43,6 +43,7 @@ import org.apache.james.webadmin.WebAdminServer;
 import org.apache.james.webadmin.WebAdminUtils;
 import org.apache.james.webadmin.service.CassandraMigrationService;
 import org.apache.james.webadmin.utils.JsonTransformer;
+import org.eclipse.jetty.http.HttpStatus;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Ignore;
@@ -107,7 +108,7 @@ public class CassandraMigrationRoutesTest {
             when()
                 .get()
             .then()
-                .statusCode(200)
+                .statusCode(HttpStatus.OK_200)
                 .contentType(ContentType.JSON)
                 .extract()
                 .jsonPath()
@@ -123,7 +124,7 @@ public class CassandraMigrationRoutesTest {
             when()
                 .get("/latest")
             .then()
-                .statusCode(200)
+                .statusCode(HttpStatus.OK_200)
                 .contentType(ContentType.JSON)
                 .extract()
                 .jsonPath()
@@ -138,7 +139,7 @@ public class CassandraMigrationRoutesTest {
         when()
             .post("/upgrade")
         .then()
-            .statusCode(409);
+            .statusCode(HttpStatus.CONFLICT_409);
     }
 
     @Test
@@ -146,11 +147,11 @@ public class CassandraMigrationRoutesTest {
         when(schemaVersionDAO.getCurrentSchemaVersion()).thenReturn(CompletableFuture.completedFuture(Optional.of(OLDER_VERSION)));
 
         Map<String, Object> errors = given()
-            .body(String.valueOf("NonInt"))
+            .body("NonInt")
         .with()
             .post("/upgrade")
         .then()
-            .statusCode(400)
+            .statusCode(HttpStatus.BAD_REQUEST_400)
             .contentType(ContentType.JSON)
             .extract()
             .body()
@@ -158,7 +159,7 @@ public class CassandraMigrationRoutesTest {
             .getMap(".");
 
         assertThat(errors)
-            .containsEntry("statusCode", 400)
+            .containsEntry("statusCode", HttpStatus.BAD_REQUEST_400)
             .containsEntry("type", "InvalidArgument")
             .containsEntry("message", "Invalid request for version upgrade")
             .containsEntry("cause", "For input string: \"NonInt\"");
@@ -175,7 +176,7 @@ public class CassandraMigrationRoutesTest {
         .with()
             .post("/upgrade")
         .then()
-            .statusCode(204);
+            .statusCode(HttpStatus.NO_CONTENT_204);
 
         verify(schemaVersionDAO, times(1)).getCurrentSchemaVersion();
         verify(schemaVersionDAO, times(1)).updateVersion(eq(CURRENT_VERSION));
@@ -191,7 +192,7 @@ public class CassandraMigrationRoutesTest {
         .with()
             .post("/upgrade")
         .then()
-            .statusCode(410)
+            .statusCode(HttpStatus.CONFLICT_409)
             .contentType(ContentType.JSON)
             .extract()
             .body()
@@ -199,7 +200,7 @@ public class CassandraMigrationRoutesTest {
             .getMap(".");
 
         assertThat(errors)
-            .containsEntry("statusCode", 410)
+            .containsEntry("statusCode", HttpStatus.CONFLICT_409)
             .containsEntry("type", "WrongState")
             .containsEntry("message", "The migration requested can not be performed")
             .containsEntry("cause", "Current version is already up to date");
@@ -215,7 +216,7 @@ public class CassandraMigrationRoutesTest {
         when()
             .post("/upgrade/latest")
         .then()
-            .statusCode(200);
+            .statusCode(HttpStatus.OK_200);
 
         verify(schemaVersionDAO, times(1)).getCurrentSchemaVersion();
         verify(schemaVersionDAO, times(1)).updateVersion(eq(CURRENT_VERSION));
@@ -230,7 +231,7 @@ public class CassandraMigrationRoutesTest {
         Map<String, Object> errors = when()
             .post("/upgrade/latest")
         .then()
-            .statusCode(410)
+            .statusCode(HttpStatus.CONFLICT_409)
             .contentType(ContentType.JSON)
             .extract()
             .body()
@@ -238,7 +239,7 @@ public class CassandraMigrationRoutesTest {
             .getMap(".");
 
         assertThat(errors)
-            .containsEntry("statusCode", 410)
+            .containsEntry("statusCode", HttpStatus.CONFLICT_409)
             .containsEntry("type", "WrongState")
             .containsEntry("message", "The migration requested can not be performed")
             .containsEntry("cause", "Current version is already up to date");

http://git-wip-us.apache.org/repos/asf/james-project/blob/21188d00/server/protocols/webadmin/webadmin-core/src/main/java/org/apache/james/webadmin/authentication/JwtFilter.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/webadmin-core/src/main/java/org/apache/james/webadmin/authentication/JwtFilter.java b/server/protocols/webadmin/webadmin-core/src/main/java/org/apache/james/webadmin/authentication/JwtFilter.java
index 494ee6e..3dda17b 100644
--- a/server/protocols/webadmin/webadmin-core/src/main/java/org/apache/james/webadmin/authentication/JwtFilter.java
+++ b/server/protocols/webadmin/webadmin-core/src/main/java/org/apache/james/webadmin/authentication/JwtFilter.java
@@ -27,6 +27,7 @@ import javax.inject.Inject;
 
 import org.apache.james.jwt.JwtTokenVerifier;
 
+import org.eclipse.jetty.http.HttpStatus;
 import spark.Request;
 import spark.Response;
 
@@ -60,19 +61,19 @@ public class JwtFilter implements AuthenticationFilter {
 
     private void checkHeaderPresent(Optional<String> bearer) {
         if (!bearer.isPresent()) {
-            halt(401, "No Bearer header.");
+            halt(HttpStatus.UNAUTHORIZED_401, "No Bearer header.");
         }
     }
 
     private void checkValidSignature(Optional<String> bearer) {
         if (!jwtTokenVerifier.verify(bearer.get())) {
-            halt(401, "Invalid Bearer header.");
+            halt(HttpStatus.UNAUTHORIZED_401, "Invalid Bearer header.");
         }
     }
 
     private void checkIsAdmin(Optional<String> bearer) {
         if (!jwtTokenVerifier.hasAttribute("admin", true, bearer.get())) {
-            halt(401, "Non authorized user.");
+            halt(HttpStatus.UNAUTHORIZED_401, "Non authorized user.");
         }
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/21188d00/server/protocols/webadmin/webadmin-core/src/main/java/org/apache/james/webadmin/utils/ErrorResponder.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/webadmin-core/src/main/java/org/apache/james/webadmin/utils/ErrorResponder.java b/server/protocols/webadmin/webadmin-core/src/main/java/org/apache/james/webadmin/utils/ErrorResponder.java
index 90642bb..c87f0f9 100644
--- a/server/protocols/webadmin/webadmin-core/src/main/java/org/apache/james/webadmin/utils/ErrorResponder.java
+++ b/server/protocols/webadmin/webadmin-core/src/main/java/org/apache/james/webadmin/utils/ErrorResponder.java
@@ -88,7 +88,7 @@ public class ErrorResponder {
             return halt(statusCode, new JsonTransformer().render(new ErrorDetail(statusCode,
                 type.getType(),
                 message,
-                cause.map(e -> Optional.of(e.getMessage())).orElse(Optional.empty()))));
+                cause.map(e -> Optional.ofNullable(e.getMessage())).orElse(Optional.empty()))));
         } catch (JsonProcessingException e) {
             return halt(statusCode);
         }

http://git-wip-us.apache.org/repos/asf/james-project/blob/21188d00/server/protocols/webadmin/webadmin-core/src/test/java/org/apache/james/webadmin/authentication/JwtFilterTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/webadmin-core/src/test/java/org/apache/james/webadmin/authentication/JwtFilterTest.java b/server/protocols/webadmin/webadmin-core/src/test/java/org/apache/james/webadmin/authentication/JwtFilterTest.java
index 6512ddb..0c4b3df 100644
--- a/server/protocols/webadmin/webadmin-core/src/test/java/org/apache/james/webadmin/authentication/JwtFilterTest.java
+++ b/server/protocols/webadmin/webadmin-core/src/test/java/org/apache/james/webadmin/authentication/JwtFilterTest.java
@@ -23,6 +23,7 @@ import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
 import org.apache.james.jwt.JwtTokenVerifier;
+import org.eclipse.jetty.http.HttpStatus;
 import org.hamcrest.BaseMatcher;
 import org.hamcrest.Description;
 import org.hamcrest.Matcher;
@@ -44,7 +45,7 @@ public class JwtFilterTest {
         public boolean matches(Object o) {
             if (o instanceof HaltException) {
                 HaltException haltException = (HaltException) o;
-                return haltException.statusCode() == 401;
+                return haltException.statusCode() == HttpStatus.UNAUTHORIZED_401;
             }
             return false;
         }

http://git-wip-us.apache.org/repos/asf/james-project/blob/21188d00/server/protocols/webadmin/webadmin-core/src/test/java/org/apache/james/webadmin/utils/ErrorResponderTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/webadmin-core/src/test/java/org/apache/james/webadmin/utils/ErrorResponderTest.java b/server/protocols/webadmin/webadmin-core/src/test/java/org/apache/james/webadmin/utils/ErrorResponderTest.java
index 3e98aae..46f2997 100644
--- a/server/protocols/webadmin/webadmin-core/src/test/java/org/apache/james/webadmin/utils/ErrorResponderTest.java
+++ b/server/protocols/webadmin/webadmin-core/src/test/java/org/apache/james/webadmin/utils/ErrorResponderTest.java
@@ -24,6 +24,7 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy;
 import java.util.Objects;
 import java.util.Optional;
 
+import org.eclipse.jetty.http.HttpStatus;
 import org.junit.Test;
 
 import com.jayway.jsonpath.DocumentContext;
@@ -45,7 +46,7 @@ public class ErrorResponderTest {
     @Test
     public void haltErrorShouldThrowWhenNoType() throws Exception {
         assertThatThrownBy(() -> ErrorResponder.builder()
-            .statusCode(400)
+            .statusCode(HttpStatus.BAD_REQUEST_400)
             .haltError())
             .isInstanceOf(NullPointerException.class);
     }
@@ -53,7 +54,7 @@ public class ErrorResponderTest {
     @Test
     public void haltErrorShouldThrowWhenNoMessage() throws Exception {
         assertThatThrownBy(() -> ErrorResponder.builder()
-            .statusCode(400)
+            .statusCode(HttpStatus.BAD_REQUEST_400)
             .type(ErrorResponder.ErrorType.INVALID_ARGUMENT)
             .haltError())
             .isInstanceOf(NullPointerException.class);
@@ -62,63 +63,63 @@ public class ErrorResponderTest {
     @Test
     public void haltErrorShouldReturnBodyWithStatusCodeWhenSetting() throws Exception {
         assertThatThrownBy(() -> ErrorResponder.builder()
-                .statusCode(404)
+                .statusCode(HttpStatus.NOT_FOUND_404)
                 .type(ErrorResponder.ErrorType.INVALID_ARGUMENT)
                 .message("Error")
                 .haltError())
             .isInstanceOf(HaltException.class)
-            .matches(e -> hasStatus(e, 404))
-            .matches(e -> bodyHasErrorDetail(e, new ErrorResponder.ErrorDetail(404, "InvalidArgument", "Error", NO_CAUSE)));
+            .matches(e -> hasStatus(e, HttpStatus.NOT_FOUND_404))
+            .matches(e -> bodyHasErrorDetail(e, new ErrorResponder.ErrorDetail(HttpStatus.NOT_FOUND_404, "InvalidArgument", "Error", NO_CAUSE)));
     }
 
     @Test
     public void haltErrorShouldReturnBodyWithErrorTypeWhenSetting() throws Exception {
         assertThatThrownBy(() -> ErrorResponder.builder()
-                .statusCode(400)
+                .statusCode(HttpStatus.BAD_REQUEST_400)
                 .type(ErrorResponder.ErrorType.WRONG_STATE)
                 .message("Error")
                 .haltError())
             .isInstanceOf(HaltException.class)
-            .matches(e -> hasStatus(e, 400))
-            .matches(e -> bodyHasErrorDetail(e, new ErrorResponder.ErrorDetail(400, "WrongState", "Error", NO_CAUSE)));
+            .matches(e -> hasStatus(e, HttpStatus.BAD_REQUEST_400))
+            .matches(e -> bodyHasErrorDetail(e, new ErrorResponder.ErrorDetail(HttpStatus.BAD_REQUEST_400, "WrongState", "Error", NO_CAUSE)));
     }
 
     @Test
     public void haltErrorShouldReturnBodyWithErrorMessageWhenSetting() throws Exception {
         assertThatThrownBy(() -> ErrorResponder.builder()
-                .statusCode(400)
+                .statusCode(HttpStatus.BAD_REQUEST_400)
                 .type(ErrorResponder.ErrorType.INVALID_ARGUMENT)
                 .message("It has error")
                 .haltError())
             .isInstanceOf(HaltException.class)
-            .matches(e -> hasStatus(e, 400))
-            .matches(e -> bodyHasErrorDetail(e, new ErrorResponder.ErrorDetail(400, "InvalidArgument", "It has error", NO_CAUSE)));
+            .matches(e -> hasStatus(e, HttpStatus.BAD_REQUEST_400))
+            .matches(e -> bodyHasErrorDetail(e, new ErrorResponder.ErrorDetail(HttpStatus.BAD_REQUEST_400, "InvalidArgument", "It has error", NO_CAUSE)));
     }
 
     @Test
     public void haltErrorShouldReturnBodyWithCauseTypeWhenSetting() throws Exception {
         assertThatThrownBy(() -> ErrorResponder.builder()
-                .statusCode(400)
+                .statusCode(HttpStatus.BAD_REQUEST_400)
                 .type(ErrorResponder.ErrorType.INVALID_ARGUMENT)
                 .message("Error")
                 .cause(new IllegalArgumentException("The input data is invalid"))
                 .haltError())
             .isInstanceOf(HaltException.class)
-            .matches(e -> hasStatus(e, 400))
-            .matches(e -> bodyHasErrorDetail(e, new ErrorResponder.ErrorDetail(400, "InvalidArgument", "Error", Optional.of("The input data is invalid"))));
+            .matches(e -> hasStatus(e, HttpStatus.BAD_REQUEST_400))
+            .matches(e -> bodyHasErrorDetail(e, new ErrorResponder.ErrorDetail(HttpStatus.BAD_REQUEST_400, "InvalidArgument", "Error", Optional.of("The input data is invalid"))));
     }
 
     @Test
     public void haltErrorShouldReturnBodyWithErrorDetail() throws Exception {
         assertThatThrownBy(() -> ErrorResponder.builder()
-                .statusCode(400)
+                .statusCode(HttpStatus.BAD_REQUEST_400)
                 .type(ErrorResponder.ErrorType.INVALID_ARGUMENT)
                 .message("Error")
                 .cause(new IllegalArgumentException("The input data is invalid"))
             .haltError())
             .isInstanceOf(HaltException.class)
-            .matches(e -> hasStatus(e, 400))
-            .matches(e -> bodyHasErrorDetail(e, new ErrorResponder.ErrorDetail(400, "InvalidArgument", "Error", Optional.of("The input data is invalid"))));
+            .matches(e -> hasStatus(e, HttpStatus.BAD_REQUEST_400))
+            .matches(e -> bodyHasErrorDetail(e, new ErrorResponder.ErrorDetail(HttpStatus.BAD_REQUEST_400, "InvalidArgument", "Error", Optional.of("The input data is invalid"))));
     }
 
     private boolean hasStatus(Throwable throwable, int status) {

http://git-wip-us.apache.org/repos/asf/james-project/blob/21188d00/server/protocols/webadmin/webadmin-data/src/main/java/org/apache/james/webadmin/routes/DomainsRoutes.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/webadmin-data/src/main/java/org/apache/james/webadmin/routes/DomainsRoutes.java b/server/protocols/webadmin/webadmin-data/src/main/java/org/apache/james/webadmin/routes/DomainsRoutes.java
index 0864a8a..8438279 100644
--- a/server/protocols/webadmin/webadmin-data/src/main/java/org/apache/james/webadmin/routes/DomainsRoutes.java
+++ b/server/protocols/webadmin/webadmin-data/src/main/java/org/apache/james/webadmin/routes/DomainsRoutes.java
@@ -97,8 +97,9 @@ public class DomainsRoutes implements Routes {
             @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.")
+            @ApiResponse(code = HttpStatus.NO_CONTENT_204, message = "OK. Domain is removed."),
+            @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500,
+                message = "Internal server error - Something went bad on the server side.")
     })
     public void defineDeleteDomain() {
         service.delete(SPECIFIC_DOMAIN, this::removeDomain);
@@ -111,9 +112,10 @@ public class DomainsRoutes implements Routes {
             @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.")
+            @ApiResponse(code = HttpStatus.NO_CONTENT_204, message = "OK. New domain is created."),
+            @ApiResponse(code = HttpStatus.BAD_REQUEST_400, message = "Invalid request for domain creation"),
+            @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500,
+                message = "Internal server error - Something went bad on the server side.")
     })
     public void defineAddDomain() {
         service.put(SPECIFIC_DOMAIN, this::addDomain);
@@ -126,9 +128,10 @@ public class DomainsRoutes implements Routes {
     })
     @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.")
+            @ApiResponse(code = HttpStatus.NO_CONTENT_204, message = "The domain exists", response = String.class),
+            @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "The domain does not exist."),
+            @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500,
+                message = "Internal server error - Something went bad on the server side.")
     })
     public void defineDomainExists() {
         service.get(SPECIFIC_DOMAIN, this::exists);
@@ -137,8 +140,9 @@ public class DomainsRoutes implements Routes {
     @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.")
+            @ApiResponse(code = HttpStatus.NO_CONTENT_204, message = "OK", response = List.class),
+            @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500,
+                message = "Internal server error - Something went bad on the server side.")
     })
     public void defineGetDomains() {
         service.get(DOMAINS,
@@ -153,7 +157,7 @@ public class DomainsRoutes implements Routes {
         } catch (DomainListException e) {
             LOGGER.info("{} did not exists", request.params(DOMAIN_NAME));
         }
-        response.status(204);
+        response.status(HttpStatus.NO_CONTENT_204);
         return Constants.EMPTY_BODY;
     }
 
@@ -203,7 +207,7 @@ public class DomainsRoutes implements Routes {
                 .message("The domain list does not contain: " + domainName)
                 .haltError();
         } else {
-            response.status(204);
+            response.status(HttpStatus.NO_CONTENT_204);
         }
         return Constants.EMPTY_BODY;
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/21188d00/server/protocols/webadmin/webadmin-data/src/main/java/org/apache/james/webadmin/routes/GroupsRoutes.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/webadmin-data/src/main/java/org/apache/james/webadmin/routes/GroupsRoutes.java b/server/protocols/webadmin/webadmin-data/src/main/java/org/apache/james/webadmin/routes/GroupsRoutes.java
index b2c6399..63ec39a 100644
--- a/server/protocols/webadmin/webadmin-data/src/main/java/org/apache/james/webadmin/routes/GroupsRoutes.java
+++ b/server/protocols/webadmin/webadmin-data/src/main/java/org/apache/james/webadmin/routes/GroupsRoutes.java
@@ -117,8 +117,9 @@ public class GroupsRoutes implements Routes {
     @Path(ROOT_PATH)
     @ApiOperation(value = "getting groups list")
     @ApiResponses(value = {
-        @ApiResponse(code = 200, message = "OK", response = List.class),
-        @ApiResponse(code = 500, message = "Internal server error - Something went bad on the server side.")
+        @ApiResponse(code = HttpStatus.OK_200, message = "OK", response = List.class),
+        @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500,
+            message = "Internal server error - Something went bad on the server side.")
     })
     public Set<String> listGroups(Request request, Response response) throws RecipientRewriteTableException {
         return Optional.ofNullable(recipientRewriteTable.getAllMappings())
@@ -143,11 +144,12 @@ public class GroupsRoutes implements Routes {
                 MAILADDRESS_ASCII_DISCLAIMER)
     })
     @ApiResponses(value = {
-        @ApiResponse(code = 200, message = "OK", response = List.class),
-        @ApiResponse(code = 400, message = GROUP_ADDRESS + " or group structure format is not valid"),
-        @ApiResponse(code = 403, message = "server doesn't own the domain"),
-        @ApiResponse(code = 409, message = "requested group address is already used for another purpose"),
-        @ApiResponse(code = 500, message = "Internal server error - Something went bad on the server side.")
+        @ApiResponse(code = HttpStatus.OK_200, message = "OK", response = List.class),
+        @ApiResponse(code = HttpStatus.BAD_REQUEST_400, message = GROUP_ADDRESS + " or group structure format is not valid"),
+        @ApiResponse(code = HttpStatus.FORBIDDEN_403, message = "server doesn't own the domain"),
+        @ApiResponse(code = HttpStatus.CONFLICT_409, message = "requested group address is already used for another purpose"),
+        @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500,
+            message = "Internal server error - Something went bad on the server side.")
     })
     public HaltException addToGroup(Request request, Response response) throws JsonExtractException, AddressException, RecipientRewriteTableException, UsersRepositoryException, DomainListException {
         MailAddress groupAddress = parseMailAddress(request.params(GROUP_ADDRESS));
@@ -187,9 +189,11 @@ public class GroupsRoutes implements Routes {
         @ApiImplicitParam(required = true, dataType = "string", name = USER_ADDRESS, paramType = "path")
     })
     @ApiResponses(value = {
-        @ApiResponse(code = 200, message = "OK", response = List.class),
-        @ApiResponse(code = 400, message = GROUP_ADDRESS + " or group structure format is not valid"),
-        @ApiResponse(code = 500, message = "Internal server error - Something went bad on the server side.")
+        @ApiResponse(code = HttpStatus.OK_200, message = "OK", response = List.class),
+        @ApiResponse(code = HttpStatus.BAD_REQUEST_400,
+            message = GROUP_ADDRESS + " or group structure format is not valid"),
+        @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500,
+            message = "Internal server error - Something went bad on the server side.")
     })
     public HaltException removeFromGroup(Request request, Response response) throws JsonExtractException, AddressException, RecipientRewriteTableException {
         MailAddress groupAddress = parseMailAddress(request.params(GROUP_ADDRESS));
@@ -205,10 +209,11 @@ public class GroupsRoutes implements Routes {
         @ApiImplicitParam(required = true, dataType = "string", name = GROUP_ADDRESS, paramType = "path")
     })
     @ApiResponses(value = {
-        @ApiResponse(code = 200, message = "OK", response = List.class),
-        @ApiResponse(code = 400, message = "The group is not an address"),
-        @ApiResponse(code = 404, message = "The group does not exist"),
-        @ApiResponse(code = 500, message = "Internal server error - Something went bad on the server side.")
+        @ApiResponse(code = HttpStatus.OK_200, message = "OK", response = List.class),
+        @ApiResponse(code = HttpStatus.BAD_REQUEST_400, message = "The group is not an address"),
+        @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "The group does not exist"),
+        @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500,
+            message = "Internal server error - Something went bad on the server side.")
     })
     public ImmutableSortedSet<String> listGroupMembers(Request request, Response response) throws RecipientRewriteTable.ErrorMappingException, RecipientRewriteTableException {
         MailAddress groupAddress = parseMailAddress(request.params(GROUP_ADDRESS));

http://git-wip-us.apache.org/repos/asf/james-project/blob/21188d00/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 e540d96..dc16425 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
@@ -94,9 +94,10 @@ public class UserRoutes implements Routes {
             @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.")
+            @ApiResponse(code = HttpStatus.NO_CONTENT_204, message = "OK. User is removed."),
+            @ApiResponse(code = HttpStatus.BAD_REQUEST_400, message = "Invalid input user."),
+            @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500,
+                message = "Internal server error - Something went bad on the server side.")
     })
     public void defineDeleteUser() {
         service.delete(USERS + SEPARATOR + USER_NAME, this::removeUser);
@@ -110,9 +111,10 @@ public class UserRoutes implements Routes {
             @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.")
+            @ApiResponse(code = HttpStatus.NO_CONTENT_204, message = "OK. New user is added."),
+            @ApiResponse(code = HttpStatus.BAD_REQUEST_400, message = "Invalid input user."),
+            @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500,
+                message = "Internal server error - Something went bad on the server side.")
     })
     public void defineCreateUser() {
         service.put(USERS + SEPARATOR + USER_NAME, this::upsertUser);
@@ -121,8 +123,9 @@ public class UserRoutes implements Routes {
     @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.")
+            @ApiResponse(code = HttpStatus.NO_CONTENT_204, message = "OK.", response = UserResponse.class),
+            @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500,
+                message = "Internal server error - Something went bad on the server side.")
     })
     public void defineGetUsers() {
         service.get(USERS,
@@ -134,7 +137,7 @@ public class UserRoutes implements Routes {
         String username = request.params(USER_NAME);
         try {
             userService.removeUser(username);
-            response.status(204);
+            response.status(HttpStatus.NO_CONTENT_204);
             return Constants.EMPTY_BODY;
         } catch (UsersRepositoryException e) {
             throw ErrorResponder.builder()

http://git-wip-us.apache.org/repos/asf/james-project/blob/21188d00/server/protocols/webadmin/webadmin-data/src/main/java/org/apache/james/webadmin/service/UserService.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/webadmin-data/src/main/java/org/apache/james/webadmin/service/UserService.java b/server/protocols/webadmin/webadmin-data/src/main/java/org/apache/james/webadmin/service/UserService.java
index ee0952d..3b09e4b 100644
--- a/server/protocols/webadmin/webadmin-data/src/main/java/org/apache/james/webadmin/service/UserService.java
+++ b/server/protocols/webadmin/webadmin-data/src/main/java/org/apache/james/webadmin/service/UserService.java
@@ -30,6 +30,7 @@ import org.apache.james.user.api.UsersRepositoryException;
 import org.apache.james.user.api.model.User;
 import org.apache.james.util.streams.Iterators;
 import org.apache.james.webadmin.dto.UserResponse;
+import org.eclipse.jetty.http.HttpStatus;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -70,10 +71,10 @@ public class UserService {
         User user = usersRepository.getUserByName(username);
         try {
             upsert(user, username, password);
-            response.status(204);
+            response.status(HttpStatus.NO_CONTENT_204);
         } catch (UsersRepositoryException e) {
             LOGGER.info("Error creating or updating user : {}", e.getMessage());
-            response.status(409);
+            response.status(HttpStatus.CONFLICT_409);
         }
         return EMPTY_BODY;
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/21188d00/server/protocols/webadmin/webadmin-data/src/test/java/org/apache/james/webadmin/routes/DomainsRoutesTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/webadmin-data/src/test/java/org/apache/james/webadmin/routes/DomainsRoutesTest.java b/server/protocols/webadmin/webadmin-data/src/test/java/org/apache/james/webadmin/routes/DomainsRoutesTest.java
index a403b5c..1de056d 100644
--- a/server/protocols/webadmin/webadmin-data/src/test/java/org/apache/james/webadmin/routes/DomainsRoutesTest.java
+++ b/server/protocols/webadmin/webadmin-data/src/test/java/org/apache/james/webadmin/routes/DomainsRoutesTest.java
@@ -27,8 +27,6 @@ import static com.jayway.restassured.config.RestAssuredConfig.newConfig;
 import static org.apache.james.webadmin.Constants.SEPARATOR;
 import static org.apache.james.webadmin.WebAdminServer.NO_CONFIGURATION;
 import static org.assertj.core.api.Assertions.assertThat;
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.CoreMatchers.startsWith;
 import static org.mockito.Matchers.any;
 import static org.mockito.Mockito.doThrow;
 import static org.mockito.Mockito.mock;
@@ -47,6 +45,7 @@ import org.apache.james.metrics.logger.DefaultMetricFactory;
 import org.apache.james.webadmin.WebAdminServer;
 import org.apache.james.webadmin.WebAdminUtils;
 import org.apache.james.webadmin.utils.JsonTransformer;
+import org.eclipse.jetty.http.HttpStatus;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
@@ -105,7 +104,7 @@ public class DomainsRoutesTest {
                 given()
                     .get()
                 .then()
-                    .statusCode(200)
+                    .statusCode(HttpStatus.OK_200)
                     .contentType(ContentType.JSON)
                     .extract()
                     .body()
@@ -120,7 +119,7 @@ public class DomainsRoutesTest {
             given()
                 .put(SEPARATOR)
             .then()
-                .statusCode(404);
+                .statusCode(HttpStatus.NOT_FOUND_404);
         }
 
         @Test
@@ -128,7 +127,7 @@ public class DomainsRoutesTest {
             given()
                 .delete(SEPARATOR)
             .then()
-                .statusCode(404);
+                .statusCode(HttpStatus.NOT_FOUND_404);
         }
 
         @Test
@@ -136,7 +135,7 @@ public class DomainsRoutesTest {
             given()
                 .put(DOMAIN)
             .then()
-                .statusCode(204);
+                .statusCode(HttpStatus.NO_CONTENT_204);
         }
 
         @Test
@@ -149,7 +148,7 @@ public class DomainsRoutesTest {
                     .get()
                 .then()
                     .contentType(ContentType.JSON)
-                    .statusCode(200)
+                    .statusCode(HttpStatus.OK_200)
                     .extract()
                     .body()
                     .jsonPath()
@@ -163,7 +162,7 @@ public class DomainsRoutesTest {
             Map<String, Object> errors = when()
                 .put(DOMAIN + "@" + DOMAIN)
             .then()
-                .statusCode(400)
+                .statusCode(HttpStatus.BAD_REQUEST_400)
                 .contentType(ContentType.JSON)
                 .extract()
                 .body()
@@ -171,7 +170,7 @@ public class DomainsRoutesTest {
                 .getMap(".");
 
             assertThat(errors)
-                .containsEntry("statusCode", 400)
+                .containsEntry("statusCode", HttpStatus.BAD_REQUEST_400)
                 .containsEntry("type", "InvalidArgument")
                 .containsEntry("message", "Invalid request for domain creation domain@domain");
         }
@@ -181,7 +180,7 @@ public class DomainsRoutesTest {
             when()
                 .put(DOMAIN + "/" + DOMAIN)
             .then()
-                .statusCode(404);
+                .statusCode(HttpStatus.NOT_FOUND_404);
         }
 
         @Test
@@ -191,7 +190,7 @@ public class DomainsRoutesTest {
                     "0123456789.0123456789.0123456789.0123456789.0123456789.0123456789.0123456789.0123456789.0123456789.0123456789." +
                     "0123456789.0123456789.0123456789.")
             .then()
-                .statusCode(400)
+                .statusCode(HttpStatus.BAD_REQUEST_400)
                 .contentType(ContentType.JSON)
                 .extract()
                 .body()
@@ -199,7 +198,7 @@ public class DomainsRoutesTest {
                 .getMap(".");
 
             assertThat(errors)
-                .containsEntry("statusCode", 400)
+                .containsEntry("statusCode", HttpStatus.BAD_REQUEST_400)
                 .containsEntry("type", "InvalidArgument");
         }
 
@@ -211,7 +210,7 @@ public class DomainsRoutesTest {
             when()
                 .put(DOMAIN)
             .then()
-                .statusCode(204);
+                .statusCode(HttpStatus.NO_CONTENT_204);
         }
 
         @Test
@@ -222,14 +221,14 @@ public class DomainsRoutesTest {
             when()
                 .delete(DOMAIN)
             .then()
-                .statusCode(204);
+                .statusCode(HttpStatus.NO_CONTENT_204);
 
             List<String> domains =
                 when()
                     .get()
                 .then()
                     .contentType(ContentType.JSON)
-                    .statusCode(200)
+                    .statusCode(HttpStatus.OK_200)
                     .extract()
                     .body()
                     .jsonPath()
@@ -243,7 +242,7 @@ public class DomainsRoutesTest {
             given()
                 .delete(DOMAIN)
             .then()
-                .statusCode(204);
+                .statusCode(HttpStatus.NO_CONTENT_204);
         }
 
         @Test
@@ -254,7 +253,7 @@ public class DomainsRoutesTest {
             when()
                 .get(DOMAIN)
             .then()
-                .statusCode(204);
+                .statusCode(HttpStatus.NO_CONTENT_204);
         }
 
         @Test
@@ -262,7 +261,7 @@ public class DomainsRoutesTest {
             given()
                 .get(DOMAIN)
             .then()
-                .statusCode(404);
+                .statusCode(HttpStatus.NOT_FOUND_404);
         }
 
     }
@@ -286,7 +285,7 @@ public class DomainsRoutesTest {
             when()
                 .delete(DOMAIN)
             .then()
-                .statusCode(500);
+                .statusCode(HttpStatus.INTERNAL_SERVER_ERROR_500);
         }
 
         @Test
@@ -296,7 +295,7 @@ public class DomainsRoutesTest {
             when()
                 .put(DOMAIN)
             .then()
-                .statusCode(500);
+                .statusCode(HttpStatus.INTERNAL_SERVER_ERROR_500);
         }
 
         @Test
@@ -306,7 +305,7 @@ public class DomainsRoutesTest {
             when()
                 .get(DOMAIN)
             .then()
-                .statusCode(500);
+                .statusCode(HttpStatus.INTERNAL_SERVER_ERROR_500);
         }
 
         @Test
@@ -316,7 +315,7 @@ public class DomainsRoutesTest {
             when()
                 .get()
             .then()
-                .statusCode(500);
+                .statusCode(HttpStatus.INTERNAL_SERVER_ERROR_500);
         }
 
         @Test
@@ -326,7 +325,7 @@ public class DomainsRoutesTest {
             when()
                 .delete(DOMAIN)
             .then()
-                .statusCode(204);
+                .statusCode(HttpStatus.NO_CONTENT_204);
         }
 
         @Test
@@ -336,7 +335,7 @@ public class DomainsRoutesTest {
             when()
                 .put(DOMAIN)
             .then()
-                .statusCode(204);
+                .statusCode(HttpStatus.NO_CONTENT_204);
         }
 
         @Test
@@ -346,7 +345,7 @@ public class DomainsRoutesTest {
             when()
                 .get(DOMAIN)
             .then()
-                .statusCode(500);
+                .statusCode(HttpStatus.INTERNAL_SERVER_ERROR_500);
         }
 
         @Test
@@ -356,7 +355,7 @@ public class DomainsRoutesTest {
             when()
                 .get()
             .then()
-                .statusCode(500);
+                .statusCode(HttpStatus.INTERNAL_SERVER_ERROR_500);
         }
 
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/21188d00/server/protocols/webadmin/webadmin-data/src/test/java/org/apache/james/webadmin/routes/GroupsRoutesTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/webadmin-data/src/test/java/org/apache/james/webadmin/routes/GroupsRoutesTest.java b/server/protocols/webadmin/webadmin-data/src/test/java/org/apache/james/webadmin/routes/GroupsRoutesTest.java
index ff357e8..a0eae10 100644
--- a/server/protocols/webadmin/webadmin-data/src/test/java/org/apache/james/webadmin/routes/GroupsRoutesTest.java
+++ b/server/protocols/webadmin/webadmin-data/src/test/java/org/apache/james/webadmin/routes/GroupsRoutesTest.java
@@ -162,7 +162,7 @@ public class GroupsRoutesTest {
                 .getMap(".");
 
             assertThat(errors)
-                .containsEntry("statusCode", 404)
+                .containsEntry("statusCode", HttpStatus.NOT_FOUND_404)
                 .containsEntry("type", "InvalidArgument")
                 .containsEntry("message", "The group does not exist");
         }
@@ -300,7 +300,7 @@ public class GroupsRoutesTest {
                 .getMap(".");
 
             assertThat(errors)
-                .containsEntry("statusCode", 403)
+                .containsEntry("statusCode", HttpStatus.FORBIDDEN_403)
                 .containsEntry("type", "InvalidArgument")
                 .containsEntry("message", "Server doesn't own the domain: unregisteredDomain");
         }
@@ -321,7 +321,7 @@ public class GroupsRoutesTest {
                 .getMap(".");
 
             assertThat(errors)
-                .containsEntry("statusCode", 409)
+                .containsEntry("statusCode", HttpStatus.CONFLICT_409)
                 .containsEntry("type", "InvalidArgument")
                 .containsEntry("message", "Requested group address is already used for another purpose");
         }
@@ -412,7 +412,7 @@ public class GroupsRoutesTest {
                 .getMap(".");
 
             assertThat(errors)
-                .containsEntry("statusCode", 400)
+                .containsEntry("statusCode", HttpStatus.BAD_REQUEST_400)
                 .containsEntry("type", "InvalidArgument")
                 .containsEntry("message", "The group is not an email address")
                 .containsEntry("cause", "Out of data at position 1 in 'not-an-address'");
@@ -431,7 +431,7 @@ public class GroupsRoutesTest {
                 .getMap(".");
 
             assertThat(errors)
-                .containsEntry("statusCode", 400)
+                .containsEntry("statusCode", HttpStatus.BAD_REQUEST_400)
                 .containsEntry("type", "InvalidArgument")
                 .containsEntry("message", "The group is not an email address")
                 .containsEntry("cause", "Out of data at position 1 in 'not-an-address'");
@@ -468,7 +468,7 @@ public class GroupsRoutesTest {
                 .getMap(".");
 
             assertThat(errors)
-                .containsEntry("statusCode", 400)
+                .containsEntry("statusCode", HttpStatus.BAD_REQUEST_400)
                 .containsEntry("type", "InvalidArgument")
                 .containsEntry("message", "The group is not an email address")
                 .containsEntry("cause", "Out of data at position 1 in 'not-an-address'");
@@ -496,7 +496,7 @@ public class GroupsRoutesTest {
                 .getMap(".");
 
             assertThat(errors)
-                .containsEntry("statusCode", 400)
+                .containsEntry("statusCode", HttpStatus.BAD_REQUEST_400)
                 .containsEntry("type", "InvalidArgument")
                 .containsEntry("message", "The group is not an email address")
                 .containsEntry("cause", "Out of data at position 1 in 'not-an-address'");
@@ -515,7 +515,7 @@ public class GroupsRoutesTest {
                 .getMap(".");
 
             assertThat(errors)
-                .containsEntry("statusCode", 400)
+                .containsEntry("statusCode", HttpStatus.BAD_REQUEST_400)
                 .containsEntry("type", "InvalidArgument")
                 .containsEntry("message", "The group is not an email address")
                 .containsEntry("cause", "Out of data at position 1 in 'not-an-address'");

http://git-wip-us.apache.org/repos/asf/james-project/blob/21188d00/server/protocols/webadmin/webadmin-data/src/test/java/org/apache/james/webadmin/routes/UsersRoutesTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/webadmin-data/src/test/java/org/apache/james/webadmin/routes/UsersRoutesTest.java b/server/protocols/webadmin/webadmin-data/src/test/java/org/apache/james/webadmin/routes/UsersRoutesTest.java
index a073b57..c2874db 100644
--- a/server/protocols/webadmin/webadmin-data/src/test/java/org/apache/james/webadmin/routes/UsersRoutesTest.java
+++ b/server/protocols/webadmin/webadmin-data/src/test/java/org/apache/james/webadmin/routes/UsersRoutesTest.java
@@ -45,6 +45,7 @@ import org.apache.james.webadmin.WebAdminServer;
 import org.apache.james.webadmin.WebAdminUtils;
 import org.apache.james.webadmin.service.UserService;
 import org.apache.james.webadmin.utils.JsonTransformer;
+import org.eclipse.jetty.http.HttpStatus;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
@@ -104,7 +105,7 @@ public class UsersRoutesTest {
                 when()
                     .get()
                 .then()
-                    .statusCode(200)
+                    .statusCode(HttpStatus.OK_200)
                     .contentType(ContentType.JSON)
                     .extract()
                     .body()
@@ -119,7 +120,7 @@ public class UsersRoutesTest {
             when()
                 .put(USERNAME)
             .then()
-                .statusCode(400);
+                .statusCode(HttpStatus.BAD_REQUEST_400);
         }
 
         @Test
@@ -129,7 +130,7 @@ public class UsersRoutesTest {
             .when()
                 .put(USERNAME)
             .then()
-                .statusCode(400);
+                .statusCode(HttpStatus.BAD_REQUEST_400);
         }
 
         @Test
@@ -139,7 +140,7 @@ public class UsersRoutesTest {
             .when()
                 .put(USERNAME)
             .then()
-                .statusCode(400);
+                .statusCode(HttpStatus.BAD_REQUEST_400);
         }
 
         @Test
@@ -149,7 +150,7 @@ public class UsersRoutesTest {
             .when()
                 .put(USERNAME)
             .then()
-                .statusCode(204);
+                .statusCode(HttpStatus.NO_CONTENT_204);
         }
 
         @Test
@@ -159,7 +160,7 @@ public class UsersRoutesTest {
             .when()
                 .put(USERNAME)
             .then()
-                .statusCode(400);
+                .statusCode(HttpStatus.BAD_REQUEST_400);
         }
 
         @Test
@@ -172,7 +173,7 @@ public class UsersRoutesTest {
                 when()
                     .get()
                 .then()
-                    .statusCode(200)
+                    .statusCode(HttpStatus.OK_200)
                     .contentType(ContentType.JSON)
                     .extract()
                     .body()
@@ -195,14 +196,14 @@ public class UsersRoutesTest {
             .when()
                 .put(USERNAME)
             .then()
-                .statusCode(204);
+                .statusCode(HttpStatus.NO_CONTENT_204);
 
             // Then
             List<Map<String, String>> users =
                 when()
                     .get()
                 .then()
-                    .statusCode(200)
+                    .statusCode(HttpStatus.OK_200)
                     .contentType(ContentType.JSON)
                     .extract()
                     .body()
@@ -217,7 +218,7 @@ public class UsersRoutesTest {
             when()
                 .delete(USERNAME)
             .then()
-                .statusCode(204);
+                .statusCode(HttpStatus.NO_CONTENT_204);
         }
 
         @Test
@@ -225,7 +226,7 @@ public class UsersRoutesTest {
             when()
                 .delete("/")
             .then()
-                .statusCode(404);
+                .statusCode(HttpStatus.NOT_FOUND_404);
         }
 
         @Test
@@ -235,7 +236,7 @@ public class UsersRoutesTest {
                     "0123456789.0123456789.0123456789.0123456789.0123456789.0123456789.0123456789.0123456789.0123456789.0123456789." +
                     "0123456789.0123456789.0123456789.")
             .then()
-                .statusCode(400);
+                .statusCode(HttpStatus.BAD_REQUEST_400);
         }
 
         @Test
@@ -245,7 +246,7 @@ public class UsersRoutesTest {
             .when()
                 .put(USERNAME + "/" + USERNAME)
             .then()
-                .statusCode(404);
+                .statusCode(HttpStatus.NOT_FOUND_404);
         }
 
         @Test
@@ -255,7 +256,7 @@ public class UsersRoutesTest {
             .when()
                 .put("/")
             .then()
-                .statusCode(404);
+                .statusCode(HttpStatus.NOT_FOUND_404);
         }
 
         @Test
@@ -267,7 +268,7 @@ public class UsersRoutesTest {
                     "0123456789.0123456789.0123456789.0123456789.0123456789.0123456789.0123456789.0123456789.0123456789.0123456789." +
                     "0123456789.0123456789.0123456789.")
             .then()
-                .statusCode(400);
+                .statusCode(HttpStatus.BAD_REQUEST_400);
         }
 
         @Test
@@ -277,7 +278,7 @@ public class UsersRoutesTest {
             .when()
                 .put(USERNAME + "/" + USERNAME)
             .then()
-                .statusCode(404);
+                .statusCode(HttpStatus.NOT_FOUND_404);
         }
 
         @Test
@@ -291,14 +292,14 @@ public class UsersRoutesTest {
             when()
                 .delete(USERNAME)
             .then()
-                .statusCode(204);
+                .statusCode(HttpStatus.NO_CONTENT_204);
 
             // Then
             List<Map<String, String>> users =
                 when()
                     .get()
                 .then()
-                    .statusCode(200)
+                    .statusCode(HttpStatus.OK_200)
                     .contentType(ContentType.JSON)
                     .extract()
                     .body()
@@ -315,7 +316,7 @@ public class UsersRoutesTest {
             .when()
                 .delete(USERNAME)
             .then()
-                .statusCode(204);
+                .statusCode(HttpStatus.NO_CONTENT_204);
         }
     }
 
@@ -340,7 +341,7 @@ public class UsersRoutesTest {
             when()
                 .delete(USERNAME)
             .then()
-                .statusCode(204);
+                .statusCode(HttpStatus.NO_CONTENT_204);
         }
 
         @Test
@@ -350,7 +351,7 @@ public class UsersRoutesTest {
             when()
                 .get()
             .then()
-                .statusCode(500);
+                .statusCode(HttpStatus.INTERNAL_SERVER_ERROR_500);
         }
 
         @Test
@@ -362,7 +363,7 @@ public class UsersRoutesTest {
             .when()
                 .put(USERNAME)
             .then()
-                .statusCode(500);
+                .statusCode(HttpStatus.INTERNAL_SERVER_ERROR_500);
         }
 
         @Test
@@ -375,7 +376,7 @@ public class UsersRoutesTest {
             .when()
                 .put(USERNAME)
             .then()
-                .statusCode(409);
+                .statusCode(HttpStatus.CONFLICT_409);
         }
 
         @Test
@@ -388,7 +389,7 @@ public class UsersRoutesTest {
             .when()
                 .put(USERNAME)
             .then()
-                .statusCode(409);
+                .statusCode(HttpStatus.CONFLICT_409);
         }
 
 
@@ -399,7 +400,7 @@ public class UsersRoutesTest {
             when()
                 .delete(USERNAME)
             .then()
-                .statusCode(500);
+                .statusCode(HttpStatus.INTERNAL_SERVER_ERROR_500);
         }
 
         @Test
@@ -409,7 +410,7 @@ public class UsersRoutesTest {
             when()
                 .get()
             .then()
-                .statusCode(500);
+                .statusCode(HttpStatus.INTERNAL_SERVER_ERROR_500);
         }
 
         @Test
@@ -421,7 +422,7 @@ public class UsersRoutesTest {
             .when()
                 .put(USERNAME)
             .then()
-                .statusCode(500);
+                .statusCode(HttpStatus.INTERNAL_SERVER_ERROR_500);
         }
 
         @Test
@@ -434,7 +435,7 @@ public class UsersRoutesTest {
             .when()
                 .put(USERNAME)
             .then()
-                .statusCode(500);
+                .statusCode(HttpStatus.INTERNAL_SERVER_ERROR_500);
         }
 
         @Test
@@ -447,7 +448,7 @@ public class UsersRoutesTest {
             .when()
                 .put(USERNAME)
             .then()
-                .statusCode(500);
+                .statusCode(HttpStatus.INTERNAL_SERVER_ERROR_500);
         }
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/21188d00/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 a45bff2..0c97839 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
@@ -19,8 +19,6 @@
 
 package org.apache.james.webadmin.routes;
 
-import static spark.Spark.halt;
-
 import javax.inject.Inject;
 import javax.ws.rs.DELETE;
 import javax.ws.rs.GET;
@@ -100,9 +98,9 @@ public class GlobalQuotaRoutes implements Routes {
             @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.")
+            @ApiResponse(code = HttpStatus.NO_CONTENT_204, message = "OK. The value has been updated."),
+            @ApiResponse(code = HttpStatus.BAD_REQUEST_400, message = "The body is not a positive integer or not unlimited value (-1)."),
+            @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "Internal server error - Something went bad on the server side.")
     })
     public void defineUpdateQuota() {
         service.put(QUOTA_ENDPOINT, ((request, response) -> {
@@ -110,7 +108,7 @@ public class GlobalQuotaRoutes implements Routes {
                 QuotaDTO quotaDTO = jsonExtractor.parse(request.body());
                 maxQuotaManager.setDefaultMaxMessage(quotaDTO.getCount());
                 maxQuotaManager.setDefaultMaxStorage(quotaDTO.getSize());
-                response.status(204);
+                response.status(HttpStatus.NO_CONTENT_204);
             } catch (JsonExtractException e) {
                 LOGGER.info("Malformed JSON", e);
                 throw ErrorResponder.builder()
@@ -138,15 +136,15 @@ public class GlobalQuotaRoutes implements Routes {
         notes = "If there is no limitation for count and/or size, the returned value will be -1"
 	)
     @ApiResponses(value = {
-            @ApiResponse(code = 200, message = "OK", response = QuotaDTO.class),
-            @ApiResponse(code = 500, message = "Internal server error - Something went bad on the server side.")
+            @ApiResponse(code = HttpStatus.OK_200, message = "OK", response = QuotaDTO.class),
+            @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_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);
+            response.status(HttpStatus.OK_200);
             return quotaDTO;
         }, jsonTransformer);
     }
@@ -155,13 +153,13 @@ public class GlobalQuotaRoutes implements Routes {
     @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.")
+            @ApiResponse(code = HttpStatus.NO_CONTENT_204, message = "The value is updated to unlimited value."),
+            @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_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);
+            response.status(HttpStatus.NO_CONTENT_204);
             return Constants.EMPTY_BODY;
         });
     }
@@ -173,16 +171,16 @@ public class GlobalQuotaRoutes implements Routes {
             @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.")
+            @ApiResponse(code = HttpStatus.NO_CONTENT_204, message = "OK. The value has been updated."),
+            @ApiResponse(code = HttpStatus.BAD_REQUEST_400, message = "The body is not a positive integer."),
+            @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_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());
                 maxQuotaManager.setDefaultMaxStorage(quotaRequest.getValue());
-                response.status(204);
+                response.status(HttpStatus.NO_CONTENT_204);
             } catch (IllegalArgumentException e) {
                 LOGGER.info("Invalid quota. Need to be an integer value greater than 0");
                 throw ErrorResponder.builder()
@@ -200,13 +198,13 @@ public class GlobalQuotaRoutes implements Routes {
     @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.")
+            @ApiResponse(code = HttpStatus.OK_200, message = "OK", response = Long.class),
+            @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_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);
+            response.status(HttpStatus.OK_200);
             return value;
         }, jsonTransformer);
     }
@@ -215,13 +213,13 @@ public class GlobalQuotaRoutes implements Routes {
     @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.")
+            @ApiResponse(code = HttpStatus.NO_CONTENT_204, message = "The value is updated to unlimited value."),
+            @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_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);
+            response.status(HttpStatus.NO_CONTENT_204);
             return Constants.EMPTY_BODY;
         });
     }
@@ -233,16 +231,16 @@ public class GlobalQuotaRoutes implements Routes {
             @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.")
+            @ApiResponse(code = HttpStatus.NO_CONTENT_204, message = "OK. The value has been updated."),
+            @ApiResponse(code = HttpStatus.BAD_REQUEST_400, message = "The body is not a positive integer."),
+            @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "Internal server error - Something went bad on the server side.")
     })
     public void defineUpdateQuotaCount() {
         service.put(COUNT_ENDPOINT, (request, response) -> {
             try {
                 QuotaRequest quotaRequest = QuotaRequest.parse(request.body());
                 maxQuotaManager.setDefaultMaxMessage(quotaRequest.getValue());
-                response.status(204);
+                response.status(HttpStatus.NO_CONTENT_204);
             } catch (IllegalArgumentException e) {
                 LOGGER.info("Invalid quota. Need to be an integer value greater than 0");
                 throw ErrorResponder.builder()
@@ -260,13 +258,13 @@ public class GlobalQuotaRoutes implements Routes {
     @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.")
+            @ApiResponse(code = HttpStatus.OK_200, message = "OK", response = Long.class),
+            @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_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);
+            response.status(HttpStatus.OK_200);
             return value;
         }, jsonTransformer);
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/21188d00/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 2867c20..0c3b30c 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
@@ -91,14 +91,14 @@ public class UserMailboxesRoutes implements Routes {
     })
     @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.")
+            @ApiResponse(code = HttpStatus.NO_CONTENT_204, message = "The list of mailboxes", response = String.class),
+            @ApiResponse(code = HttpStatus.UNAUTHORIZED_401, message = "Unauthorized. The user is not authenticated on the platform", response = String.class),
+            @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "The user name does not exist."),
+            @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_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);
+            response.status(HttpStatus.OK_200);
             try {
                 return userMailboxesService.listMailboxes(request.params(USER_NAME));
             } catch (IllegalStateException e) {
@@ -121,17 +121,17 @@ public class UserMailboxesRoutes implements Routes {
     })
     @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.")
+            @ApiResponse(code = HttpStatus.NO_CONTENT_204, message = "The mailbox now does not exist on the server", response = String.class),
+            @ApiResponse(code = HttpStatus.BAD_REQUEST_400, message = "Invalid mailbox name"),
+            @ApiResponse(code = HttpStatus.UNAUTHORIZED_401, message = "Unauthorized. The user is not authenticated on the platform"),
+            @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "The user name does not exist."),
+            @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_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)));
-                response.status(204);
+                response.status(HttpStatus.NO_CONTENT_204);
             } catch (IllegalStateException e) {
                 LOGGER.info("Invalid delete on user mailbox", e);
                 throw ErrorResponder.builder()
@@ -167,16 +167,16 @@ public class UserMailboxesRoutes implements Routes {
     })
     @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.")
+            @ApiResponse(code = HttpStatus.NO_CONTENT_204, message = "The user does not have any mailbox", response = String.class),
+            @ApiResponse(code = HttpStatus.UNAUTHORIZED_401, message = "Unauthorized. The user is not authenticated on the platform"),
+            @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "The user name does not exist."),
+            @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_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));
-                response.status(204);
+                response.status(HttpStatus.NO_CONTENT_204);
             } catch (IllegalStateException e) {
                 LOGGER.info("Invalid delete on user mailboxes", e);
                 throw ErrorResponder.builder()
@@ -198,17 +198,17 @@ public class UserMailboxesRoutes implements Routes {
     })
     @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.")
+            @ApiResponse(code = HttpStatus.NO_CONTENT_204, message = "The mailbox exists", response = String.class),
+            @ApiResponse(code = HttpStatus.BAD_REQUEST_400, message = "Invalid mailbox name"),
+            @ApiResponse(code = HttpStatus.UNAUTHORIZED_401, message = "Unauthorized. The user is not authenticated on the platform"),
+            @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "The user name does not exist."),
+            @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_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)))) {
-                    response.status(204);
+                    response.status(HttpStatus.NO_CONTENT_204);
                 } else {
                     throw ErrorResponder.builder()
                         .statusCode(HttpStatus.NOT_FOUND_404)
@@ -245,17 +245,17 @@ public class UserMailboxesRoutes implements Routes {
             @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.")
+            @ApiResponse(code = HttpStatus.NO_CONTENT_204, message = "OK. The mailbox now exists on the server.", response = String.class),
+            @ApiResponse(code = HttpStatus.BAD_REQUEST_400, message = "Invalid mailbox name"),
+            @ApiResponse(code = HttpStatus.UNAUTHORIZED_401, message = "Unauthorized. The user is not authenticated on the platform"),
+            @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "The user name does not exist."),
+            @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "Internal server error - Something went bad on the server side.")
     })
     public void defineCreateUserMailbox() {
         service.put(SPECIFIC_MAILBOX, (request, response) -> {
             try {
                 userMailboxesService.createMailbox(request.params(USER_NAME), new MailboxName(request.params(MAILBOX_NAME)));
-                response.status(204);
+                response.status(HttpStatus.NO_CONTENT_204);
             } catch (IllegalStateException e) {
                 LOGGER.info("Invalid put on user mailbox", e);
                 throw ErrorResponder.builder()


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


[2/5] james-project git commit: JAMES-2233 WebAdmin responses more details when error

Posted by bt...@apache.org.
http://git-wip-us.apache.org/repos/asf/james-project/blob/bde6bdb7/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/UserMailboxesRoutesTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/UserMailboxesRoutesTest.java b/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/UserMailboxesRoutesTest.java
index 1119083..729054f 100644
--- a/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/UserMailboxesRoutesTest.java
+++ b/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/UserMailboxesRoutesTest.java
@@ -27,6 +27,7 @@ import static org.apache.james.webadmin.Constants.SEPARATOR;
 import static org.apache.james.webadmin.WebAdminServer.NO_CONFIGURATION;
 import static org.apache.james.webadmin.routes.UserMailboxesRoutes.USERS_BASE;
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.hamcrest.CoreMatchers.containsString;
 import static org.hamcrest.CoreMatchers.is;
 import static org.mockito.Matchers.any;
 import static org.mockito.Mockito.doThrow;
@@ -113,170 +114,340 @@ public class UserMailboxesRoutesTest {
         public void getMailboxesShouldUserErrorFoundWithNonExistingUser() throws Exception {
             when(usersRepository.contains(USERNAME)).thenReturn(false);
 
-            when()
+            Map<String, Object> errors = when()
                 .get()
             .then()
-                .statusCode(404);
+                .statusCode(404)
+                .contentType(ContentType.JSON)
+                .extract()
+                .body()
+                .jsonPath()
+                .getMap(".");
+
+            assertThat(errors)
+                .containsEntry("statusCode", 404)
+                .containsEntry("type", "InvalidArgument")
+                .containsEntry("message", "Invalid get on user mailboxes");
         }
 
         @Test
         public void getShouldReturnNotFoundWithNonExistingUser() throws Exception {
             when(usersRepository.contains(USERNAME)).thenReturn(false);
 
-            when()
+            Map<String, Object> errors = when()
                 .get(MAILBOX_NAME)
             .then()
-                .statusCode(404);
+                .statusCode(404)
+                .contentType(ContentType.JSON)
+                .extract()
+                .body()
+                .jsonPath()
+                .getMap(".");
+
+            assertThat(errors)
+                .containsEntry("statusCode", 404)
+                .containsEntry("type", "InvalidArgument")
+                .containsEntry("message", "Invalid get on user mailboxes");
         }
 
         @Test
         public void putShouldReturnNotFoundWithNonExistingUser() throws Exception {
             when(usersRepository.contains(USERNAME)).thenReturn(false);
 
-            when()
+            Map<String, Object> errors = when()
                 .put(MAILBOX_NAME)
             .then()
-                .statusCode(404);
+                .statusCode(404)
+                .contentType(ContentType.JSON)
+                .extract()
+                .body()
+                .jsonPath()
+                .getMap(".");
+
+            assertThat(errors)
+                .containsEntry("statusCode", 404)
+                .containsEntry("type", "InvalidArgument")
+                .containsEntry("message", "Invalid get on user mailboxes");
         }
 
         @Test
         public void deleteShouldReturnNotFoundWithNonExistingUser() throws Exception {
             when(usersRepository.contains(USERNAME)).thenReturn(false);
 
-            when()
+            Map<String, Object> errors = when()
                 .put(MAILBOX_NAME)
             .then()
-                .statusCode(404);
+                .statusCode(404)
+                .contentType(ContentType.JSON)
+                .extract()
+                .body()
+                .jsonPath()
+                .getMap(".");
+
+            assertThat(errors)
+                .containsEntry("statusCode", 404)
+                .containsEntry("type", "InvalidArgument")
+                .containsEntry("message", "Invalid get on user mailboxes");
         }
 
         @Test
         public void getShouldReturnUserErrorWithInvalidWildcardMailboxName() throws Exception {
             when(usersRepository.contains(USERNAME)).thenReturn(false);
 
-            when()
+            Map<String, Object> errors = when()
                 .get(MAILBOX_NAME + "*")
             .then()
-                .statusCode(400);
+                .statusCode(400)
+                .contentType(ContentType.JSON)
+                .extract()
+                .body()
+                .jsonPath()
+                .getMap(".");
+
+            assertThat(errors)
+                .containsEntry("statusCode", 400)
+                .containsEntry("type", "InvalidArgument")
+                .containsEntry("message", "Attempt to create an invalid mailbox");
         }
 
         @Test
         public void putShouldReturnUserErrorWithInvalidWildcardMailboxName() throws Exception {
             when(usersRepository.contains(USERNAME)).thenReturn(false);
 
-            when()
+            Map<String, Object> errors = when()
                 .put(MAILBOX_NAME+ "*")
             .then()
-                .statusCode(400);
+                .statusCode(400)
+                .contentType(ContentType.JSON)
+                .extract()
+                .body()
+                .jsonPath()
+                .getMap(".");
+
+            assertThat(errors)
+                .containsEntry("statusCode", 400)
+                .containsEntry("type", "InvalidArgument")
+                .containsEntry("message", "Attempt to create an invalid mailbox");
         }
 
         @Test
         public void deleteShouldReturnUserErrorWithInvalidWildcardMailboxName() throws Exception {
             when(usersRepository.contains(USERNAME)).thenReturn(false);
 
-            when()
+            Map<String, Object> errors = when()
                 .put(MAILBOX_NAME + "*")
             .then()
-                .statusCode(400);
+                .statusCode(400)
+                .contentType(ContentType.JSON)
+                .extract()
+                .body()
+                .jsonPath()
+                .getMap(".");
+
+            assertThat(errors)
+                .containsEntry("statusCode", 400)
+                .containsEntry("type", "InvalidArgument")
+                .containsEntry("message", "Attempt to create an invalid mailbox");
         }
 
         @Test
         public void getShouldReturnUserErrorWithInvalidPercentMailboxName() throws Exception {
             when(usersRepository.contains(USERNAME)).thenReturn(false);
 
-            when()
+            Map<String, Object> errors = when()
                 .get(MAILBOX_NAME + "%")
             .then()
-                .statusCode(400);
+                .statusCode(400)
+                .contentType(ContentType.JSON)
+                .extract()
+                .body()
+                .jsonPath()
+                .getMap(".");
+
+            assertThat(errors)
+                .containsEntry("statusCode", 400)
+                .containsEntry("type", "InvalidArgument")
+                .containsEntry("message", "Attempt to create an invalid mailbox");
         }
 
         @Test
         public void putShouldReturnUserErrorWithInvalidPercentMailboxName() throws Exception {
             when(usersRepository.contains(USERNAME)).thenReturn(false);
 
-            when()
+            Map<String, Object> errors = when()
                 .put(MAILBOX_NAME+ "%")
             .then()
-                .statusCode(400);
+                .statusCode(400)
+                .contentType(ContentType.JSON)
+                .extract()
+                .body()
+                .jsonPath()
+                .getMap(".");
+
+            assertThat(errors)
+                .containsEntry("statusCode", 400)
+                .containsEntry("type", "InvalidArgument")
+                .containsEntry("message", "Attempt to create an invalid mailbox");
         }
 
         @Test
         public void deleteShouldReturnUserErrorWithInvalidPercentMailboxName() throws Exception {
             when(usersRepository.contains(USERNAME)).thenReturn(false);
 
-            when()
+            Map<String, Object> errors = when()
                 .put(MAILBOX_NAME + "%")
             .then()
-                .statusCode(400);
+                .statusCode(400)
+                .contentType(ContentType.JSON)
+                .extract()
+                .body()
+                .jsonPath()
+                .getMap(".");
+
+            assertThat(errors)
+                .containsEntry("statusCode", 400)
+                .containsEntry("type", "InvalidArgument")
+                .containsEntry("message", "Attempt to create an invalid mailbox");
         }
 
         @Test
         public void getShouldReturnUserErrorWithInvalidSharpMailboxName() throws Exception {
             when(usersRepository.contains(USERNAME)).thenReturn(false);
 
-            when()
+            Map<String, Object> errors = when()
                 .get(MAILBOX_NAME + "#")
             .then()
-                .statusCode(400);
+                .statusCode(400)
+                .contentType(ContentType.JSON)
+                .extract()
+                .body()
+                .jsonPath()
+                .getMap(".");
+
+            assertThat(errors)
+                .containsEntry("statusCode", 400)
+                .containsEntry("type", "InvalidArgument")
+                .containsEntry("message", "Attempt to create an invalid mailbox");
         }
 
         @Test
         public void putShouldReturnUserErrorWithInvalidSharpMailboxName() throws Exception {
             when(usersRepository.contains(USERNAME)).thenReturn(false);
 
-            when()
+            Map<String, Object> errors = when()
                 .put(MAILBOX_NAME+ "#")
             .then()
-                .statusCode(400);
+                .statusCode(400)
+                .contentType(ContentType.JSON)
+                .extract()
+                .body()
+                .jsonPath()
+                .getMap(".");
+
+            assertThat(errors)
+                .containsEntry("statusCode", 400)
+                .containsEntry("type", "InvalidArgument")
+                .containsEntry("message", "Attempt to create an invalid mailbox");
         }
 
         @Test
         public void deleteShouldReturnUserErrorWithInvalidSharpMailboxName() throws Exception {
             when(usersRepository.contains(USERNAME)).thenReturn(false);
 
-            when()
+            Map<String, Object> errors = when()
                 .put(MAILBOX_NAME + "#")
             .then()
-                .statusCode(400);
+                .statusCode(400)
+                .contentType(ContentType.JSON)
+                .extract()
+                .body()
+                .jsonPath()
+                .getMap(".");
+
+            assertThat(errors)
+                .containsEntry("statusCode", 400)
+                .containsEntry("type", "InvalidArgument")
+                .containsEntry("message", "Attempt to create an invalid mailbox");
         }
 
         @Test
         public void getShouldReturnUserErrorWithInvalidAndMailboxName() throws Exception {
             when(usersRepository.contains(USERNAME)).thenReturn(false);
 
-            when()
+            Map<String, Object> errors = when()
                 .get(MAILBOX_NAME + "&")
             .then()
-                .statusCode(400);
+                .statusCode(400)
+                .contentType(ContentType.JSON)
+                .extract()
+                .body()
+                .jsonPath()
+                .getMap(".");
+
+            assertThat(errors)
+                .containsEntry("statusCode", 400)
+                .containsEntry("type", "InvalidArgument")
+                .containsEntry("message", "Attempt to create an invalid mailbox");
         }
 
         @Test
         public void putShouldReturnUserErrorWithInvalidAndMailboxName() throws Exception {
             when(usersRepository.contains(USERNAME)).thenReturn(false);
 
-            when()
+            Map<String, Object> errors = when()
                 .put(MAILBOX_NAME+ "&")
             .then()
-                .statusCode(400);
+                .statusCode(400)
+                .contentType(ContentType.JSON)
+                .extract()
+                .body()
+                .jsonPath()
+                .getMap(".");
+
+            assertThat(errors)
+                .containsEntry("statusCode", 400)
+                .containsEntry("type", "InvalidArgument")
+                .containsEntry("message", "Attempt to create an invalid mailbox");
         }
 
         @Test
         public void deleteShouldReturnUserErrorWithInvalidAndMailboxName() throws Exception {
             when(usersRepository.contains(USERNAME)).thenReturn(false);
 
-            when()
+            Map<String, Object> errors = when()
                 .put(MAILBOX_NAME + "&")
             .then()
-                .statusCode(400);
+                .statusCode(400)
+                .contentType(ContentType.JSON)
+                .extract()
+                .body()
+                .jsonPath()
+                .getMap(".");
+
+            assertThat(errors)
+                .containsEntry("statusCode", 400)
+                .containsEntry("type", "InvalidArgument")
+                .containsEntry("message", "Attempt to create an invalid mailbox");
         }
 
         @Test
         public void deleteMailboxesShouldReturnUserErrorWithNonExistingUser() throws Exception {
             when(usersRepository.contains(USERNAME)).thenReturn(false);
 
-            when()
+            Map<String, Object> errors = when()
                 .delete()
             .then()
-                .statusCode(404);
+                .statusCode(404)
+                .contentType(ContentType.JSON)
+                .extract()
+                .body()
+                .jsonPath()
+                .getMap(".");
+
+            assertThat(errors)
+                .containsEntry("statusCode", 404)
+                .containsEntry("type", "InvalidArgument")
+                .containsEntry("message", "Invalid delete on user mailboxes");
         }
 
         @Test
@@ -300,7 +471,8 @@ public class UserMailboxesRoutesTest {
             when()
                 .put()
             .then()
-                .statusCode(404);
+                .statusCode(404)
+                .body(containsString("404 Not found"));
         }
 
         @Test
@@ -308,7 +480,8 @@ public class UserMailboxesRoutesTest {
             when()
                 .put(SEPARATOR)
             .then()
-                .statusCode(404);
+                .statusCode(404)
+                .body(containsString("404 Not found"));
         }
 
         @Test
@@ -344,10 +517,20 @@ public class UserMailboxesRoutesTest {
 
         @Test
         public void getShouldReturnNotFoundWhenMailboxDoesNotExist() {
-            when()
+            Map<String, Object> errors = when()
                 .get(MAILBOX_NAME)
             .then()
-                .statusCode(404);
+                .statusCode(404)
+                .contentType(ContentType.JSON)
+                .extract()
+                .body()
+                .jsonPath()
+                .getMap(".");
+
+            assertThat(errors)
+                .containsEntry("statusCode", 404)
+                .containsEntry("type", "InvalidArgument")
+                .containsEntry("message", "Invalid get on user mailboxes");
         }
 
         @Test
@@ -388,10 +571,20 @@ public class UserMailboxesRoutesTest {
             with()
                 .delete(MAILBOX_NAME);
 
-            when()
+            Map<String, Object> errors = when()
                 .get(MAILBOX_NAME)
             .then()
-                .statusCode(404);
+                .statusCode(404)
+                .contentType(ContentType.JSON)
+                .extract()
+                .body()
+                .jsonPath()
+                .getMap(".");
+
+            assertThat(errors)
+                .containsEntry("statusCode", 404)
+                .containsEntry("type", "InvalidArgument")
+                .containsEntry("message", "Invalid get on user mailboxes");
         }
 
         @Test
@@ -562,7 +755,8 @@ public class UserMailboxesRoutesTest {
             when()
                 .put(MAILBOX_NAME)
             .then()
-                .statusCode(500);
+                .statusCode(500)
+                .body(containsString("500 Internal Server Error"));
         }
 
         @Test
@@ -572,7 +766,8 @@ public class UserMailboxesRoutesTest {
             when()
                 .put(MAILBOX_NAME)
             .then()
-                .statusCode(500);
+                .statusCode(500)
+                .body(containsString("500 Internal Server Error"));
         }
 
         @Test
@@ -598,7 +793,8 @@ public class UserMailboxesRoutesTest {
             when()
                 .delete(MAILBOX_NAME)
             .then()
-                .statusCode(500);
+                .statusCode(500)
+                .body(containsString("500 Internal Server Error"));
         }
 
         @Test
@@ -608,7 +804,8 @@ public class UserMailboxesRoutesTest {
             when()
                 .delete(MAILBOX_NAME)
             .then()
-                .statusCode(500);
+                .statusCode(500)
+                .body(containsString("500 Internal Server Error"));
         }
 
         @Test
@@ -623,7 +820,8 @@ public class UserMailboxesRoutesTest {
             when()
                 .delete(MAILBOX_NAME)
             .then()
-                .statusCode(500);
+                .statusCode(500)
+                .body(containsString("500 Internal Server Error"));
         }
 
         @Test
@@ -633,7 +831,8 @@ public class UserMailboxesRoutesTest {
             when()
                 .delete(MAILBOX_NAME)
             .then()
-                .statusCode(500);
+                .statusCode(500)
+                .body(containsString("500 Internal Server Error"));
         }
 
         @Test
@@ -653,7 +852,8 @@ public class UserMailboxesRoutesTest {
             when()
                 .delete()
             .then()
-                .statusCode(500);
+                .statusCode(500)
+                .body(containsString("500 Internal Server Error"));
         }
 
         @Test
@@ -663,7 +863,8 @@ public class UserMailboxesRoutesTest {
             when()
                 .delete()
                 .then()
-                .statusCode(500);
+                .statusCode(500)
+                .body(containsString("500 Internal Server Error"));
         }
 
 
@@ -679,7 +880,8 @@ public class UserMailboxesRoutesTest {
             when()
                 .delete()
             .then()
-                .statusCode(500);
+                .statusCode(500)
+                .body(containsString("500 Internal Server Error"));
         }
 
         @Test
@@ -707,7 +909,8 @@ public class UserMailboxesRoutesTest {
             when()
                 .delete()
             .then()
-                .statusCode(500);
+                .statusCode(500)
+                .body(containsString("500 Internal Server Error"));
         }
 
         @Test
@@ -717,7 +920,8 @@ public class UserMailboxesRoutesTest {
             when()
                 .get(MAILBOX_NAME)
             .then()
-                .statusCode(500);
+                .statusCode(500)
+                .body(containsString("500 Internal Server Error"));
         }
 
         @Test
@@ -727,7 +931,8 @@ public class UserMailboxesRoutesTest {
             when()
                 .get(MAILBOX_NAME)
             .then()
-                .statusCode(500);
+                .statusCode(500)
+                .body(containsString("500 Internal Server Error"));
         }
 
         @Test
@@ -737,7 +942,8 @@ public class UserMailboxesRoutesTest {
             when()
                 .get()
             .then()
-                .statusCode(500);
+                .statusCode(500)
+                .body(containsString("500 Internal Server Error"));
         }
 
         @Test
@@ -747,7 +953,8 @@ public class UserMailboxesRoutesTest {
             when()
                 .get()
             .then()
-                .statusCode(500);
+                .statusCode(500)
+                .body(containsString("500 Internal Server Error"));
         }
 
         @Test
@@ -757,7 +964,8 @@ public class UserMailboxesRoutesTest {
             when()
                 .get()
             .then()
-                .statusCode(500);
+                .statusCode(500)
+                .body(containsString("500 Internal Server Error"));
         }
 
         @Test
@@ -767,7 +975,8 @@ public class UserMailboxesRoutesTest {
             when()
                 .get(MAILBOX_NAME)
             .then()
-                .statusCode(500);
+                .statusCode(500)
+                .body(containsString("500 Internal Server Error"));
         }
 
         @Test
@@ -777,7 +986,8 @@ public class UserMailboxesRoutesTest {
             when()
                 .put(MAILBOX_NAME)
             .then()
-                .statusCode(500);
+                .statusCode(500)
+                .body(containsString("500 Internal Server Error"));
         }
 
         @Test
@@ -787,7 +997,8 @@ public class UserMailboxesRoutesTest {
             when()
                 .delete(MAILBOX_NAME)
             .then()
-                .statusCode(500);
+                .statusCode(500)
+                .body(containsString("500 Internal Server Error"));
         }
 
         @Test
@@ -797,7 +1008,8 @@ public class UserMailboxesRoutesTest {
             when()
                 .delete()
                 .then()
-                .statusCode(500);
+                .statusCode(500)
+                .body(containsString("500 Internal Server Error"));
         }
 
     }


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


[4/5] james-project git commit: JAMES-2233 uniformize HttpResponse code constant in Webadmin

Posted by bt...@apache.org.
http://git-wip-us.apache.org/repos/asf/james-project/blob/21188d00/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/GlobalQuotaRoutesTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/GlobalQuotaRoutesTest.java b/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/GlobalQuotaRoutesTest.java
index 5f79edf..67e8fd5 100644
--- a/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/GlobalQuotaRoutesTest.java
+++ b/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/GlobalQuotaRoutesTest.java
@@ -24,7 +24,6 @@ import static com.jayway.restassured.config.EncoderConfig.encoderConfig;
 import static com.jayway.restassured.config.RestAssuredConfig.newConfig;
 import static org.apache.james.webadmin.WebAdminServer.NO_CONFIGURATION;
 import static org.assertj.core.api.Assertions.assertThat;
-import static org.hamcrest.CoreMatchers.is;
 
 import java.util.Map;
 
@@ -34,6 +33,7 @@ import org.apache.james.metrics.logger.DefaultMetricFactory;
 import org.apache.james.webadmin.WebAdminServer;
 import org.apache.james.webadmin.WebAdminUtils;
 import org.apache.james.webadmin.utils.JsonTransformer;
+import org.eclipse.jetty.http.HttpStatus;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
@@ -77,7 +77,7 @@ public class GlobalQuotaRoutesTest {
             given()
                 .get(GlobalQuotaRoutes.COUNT_ENDPOINT)
             .then()
-                .statusCode(200)
+                .statusCode(HttpStatus.OK_200)
                 .contentType(ContentType.JSON)
                 .extract()
                 .as(Long.class);
@@ -94,7 +94,7 @@ public class GlobalQuotaRoutesTest {
             given()
                 .get(GlobalQuotaRoutes.COUNT_ENDPOINT)
             .then()
-                .statusCode(200)
+                .statusCode(HttpStatus.OK_200)
                 .contentType(ContentType.JSON)
                 .extract()
                 .as(Long.class);
@@ -108,7 +108,7 @@ public class GlobalQuotaRoutesTest {
             .body("invalid")
             .put(GlobalQuotaRoutes.COUNT_ENDPOINT)
         .then()
-            .statusCode(400)
+            .statusCode(HttpStatus.BAD_REQUEST_400)
             .contentType(ContentType.JSON)
             .extract()
             .body()
@@ -116,7 +116,7 @@ public class GlobalQuotaRoutesTest {
             .getMap(".");
 
         assertThat(errors)
-            .containsEntry("statusCode", 400)
+            .containsEntry("statusCode", HttpStatus.BAD_REQUEST_400)
             .containsEntry("type", "InvalidArgument")
             .containsEntry("message", "Invalid quota. Need to be an integer value greater than 0")
             .containsEntry("cause", "For input string: \"invalid\"");
@@ -128,7 +128,7 @@ public class GlobalQuotaRoutesTest {
             .body("-1")
             .put(GlobalQuotaRoutes.COUNT_ENDPOINT)
         .then()
-            .statusCode(400)
+            .statusCode(HttpStatus.BAD_REQUEST_400)
             .contentType(ContentType.JSON)
             .extract()
             .body()
@@ -136,7 +136,7 @@ public class GlobalQuotaRoutesTest {
             .getMap(".");
 
         assertThat(errors)
-            .containsEntry("statusCode", 400)
+            .containsEntry("statusCode", HttpStatus.BAD_REQUEST_400)
             .containsEntry("type", "InvalidArgument")
             .containsEntry("message", "Invalid quota. Need to be an integer value greater than 0");
     }
@@ -147,7 +147,7 @@ public class GlobalQuotaRoutesTest {
             .body("42")
             .put(GlobalQuotaRoutes.COUNT_ENDPOINT)
         .then()
-            .statusCode(204);
+            .statusCode(HttpStatus.NO_CONTENT_204);
 
         assertThat(maxQuotaManager.getDefaultMaxMessage()).isEqualTo(42);
     }
@@ -159,7 +159,7 @@ public class GlobalQuotaRoutesTest {
         given()
             .delete(GlobalQuotaRoutes.COUNT_ENDPOINT)
         .then()
-            .statusCode(204);
+            .statusCode(HttpStatus.NO_CONTENT_204);
 
         assertThat(maxQuotaManager.getDefaultMaxMessage()).isEqualTo(Quota.UNLIMITED);
     }
@@ -170,7 +170,7 @@ public class GlobalQuotaRoutesTest {
             given()
                 .get(GlobalQuotaRoutes.SIZE_ENDPOINT)
             .then()
-                .statusCode(200)
+                .statusCode(HttpStatus.OK_200)
                 .contentType(ContentType.JSON)
                 .extract()
                 .as(Long.class);
@@ -188,7 +188,7 @@ public class GlobalQuotaRoutesTest {
             given()
                 .get(GlobalQuotaRoutes.SIZE_ENDPOINT)
             .then()
-                .statusCode(200)
+                .statusCode(HttpStatus.OK_200)
                 .contentType(ContentType.JSON)
                 .extract()
                 .as(Long.class);
@@ -202,7 +202,7 @@ public class GlobalQuotaRoutesTest {
             .body("invalid")
             .put(GlobalQuotaRoutes.SIZE_ENDPOINT)
         .then()
-            .statusCode(400)
+            .statusCode(HttpStatus.BAD_REQUEST_400)
             .contentType(ContentType.JSON)
             .extract()
             .body()
@@ -210,7 +210,7 @@ public class GlobalQuotaRoutesTest {
             .getMap(".");
 
         assertThat(errors)
-            .containsEntry("statusCode", 400)
+            .containsEntry("statusCode", HttpStatus.BAD_REQUEST_400)
             .containsEntry("type", "InvalidArgument")
             .containsEntry("message", "Invalid quota. Need to be an integer value greater than 0")
             .containsEntry("cause", "For input string: \"invalid\"");
@@ -222,7 +222,7 @@ public class GlobalQuotaRoutesTest {
             .body("-1")
             .put(GlobalQuotaRoutes.SIZE_ENDPOINT)
         .then()
-            .statusCode(400)
+            .statusCode(HttpStatus.BAD_REQUEST_400)
             .contentType(ContentType.JSON)
             .extract()
             .body()
@@ -230,7 +230,7 @@ public class GlobalQuotaRoutesTest {
             .getMap(".");
 
         assertThat(errors)
-            .containsEntry("statusCode", 400)
+            .containsEntry("statusCode", HttpStatus.BAD_REQUEST_400)
             .containsEntry("type", "InvalidArgument")
             .containsEntry("message", "Invalid quota. Need to be an integer value greater than 0");
     }
@@ -241,7 +241,7 @@ public class GlobalQuotaRoutesTest {
             .body("42")
             .put(GlobalQuotaRoutes.SIZE_ENDPOINT)
         .then()
-            .statusCode(204);
+            .statusCode(HttpStatus.NO_CONTENT_204);
 
         assertThat(maxQuotaManager.getDefaultMaxStorage()).isEqualTo(42);
     }
@@ -253,7 +253,7 @@ public class GlobalQuotaRoutesTest {
         given()
             .delete(GlobalQuotaRoutes.COUNT_ENDPOINT)
         .then()
-            .statusCode(204);
+            .statusCode(HttpStatus.NO_CONTENT_204);
 
         assertThat(maxQuotaManager.getDefaultMaxMessage()).isEqualTo(Quota.UNLIMITED);
     }
@@ -269,7 +269,7 @@ public class GlobalQuotaRoutesTest {
             given()
                 .get(GlobalQuotaRoutes.QUOTA_ENDPOINT)
             .then()
-                .statusCode(200)
+                .statusCode(HttpStatus.OK_200)
                 .contentType(ContentType.JSON)
                 .extract()
                 .jsonPath();
@@ -284,7 +284,7 @@ public class GlobalQuotaRoutesTest {
             given()
                 .get(GlobalQuotaRoutes.QUOTA_ENDPOINT)
             .then()
-                .statusCode(200)
+                .statusCode(HttpStatus.OK_200)
                 .contentType(ContentType.JSON)
                 .extract()
                 .jsonPath();
@@ -302,7 +302,7 @@ public class GlobalQuotaRoutesTest {
             given()
                 .get(GlobalQuotaRoutes.QUOTA_ENDPOINT)
             .then()
-                .statusCode(200)
+                .statusCode(HttpStatus.OK_200)
                 .contentType(ContentType.JSON)
                 .extract()
                 .jsonPath();
@@ -321,7 +321,7 @@ public class GlobalQuotaRoutesTest {
             given()
                 .get(GlobalQuotaRoutes.QUOTA_ENDPOINT)
                 .then()
-                .statusCode(200)
+                .statusCode(HttpStatus.OK_200)
                 .contentType(ContentType.JSON)
                 .extract()
                 .jsonPath();
@@ -336,7 +336,7 @@ public class GlobalQuotaRoutesTest {
             .body("{\"count\":52,\"size\":42}")
             .put(GlobalQuotaRoutes.QUOTA_ENDPOINT)
         .then()
-            .statusCode(204);
+            .statusCode(HttpStatus.NO_CONTENT_204);
 
         assertThat(maxQuotaManager.getDefaultMaxMessage()).isEqualTo(52);
         assertThat(maxQuotaManager.getDefaultMaxStorage()).isEqualTo(42);
@@ -348,7 +348,7 @@ public class GlobalQuotaRoutesTest {
             .body("{\"count\":-1,\"size\":-1}")
             .put(GlobalQuotaRoutes.QUOTA_ENDPOINT)
         .then()
-            .statusCode(204);
+            .statusCode(HttpStatus.NO_CONTENT_204);
 
         assertThat(maxQuotaManager.getDefaultMaxMessage()).isEqualTo(Quota.UNLIMITED);
         assertThat(maxQuotaManager.getDefaultMaxStorage()).isEqualTo(Quota.UNLIMITED);

http://git-wip-us.apache.org/repos/asf/james-project/blob/21188d00/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/UserMailboxesRoutesTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/UserMailboxesRoutesTest.java b/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/UserMailboxesRoutesTest.java
index 729054f..5d34e26 100644
--- a/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/UserMailboxesRoutesTest.java
+++ b/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/UserMailboxesRoutesTest.java
@@ -55,6 +55,7 @@ import org.apache.james.webadmin.WebAdminServer;
 import org.apache.james.webadmin.WebAdminUtils;
 import org.apache.james.webadmin.service.UserMailboxesService;
 import org.apache.james.webadmin.utils.JsonTransformer;
+import org.eclipse.jetty.http.HttpStatus;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
@@ -117,7 +118,7 @@ public class UserMailboxesRoutesTest {
             Map<String, Object> errors = when()
                 .get()
             .then()
-                .statusCode(404)
+                .statusCode(HttpStatus.NOT_FOUND_404)
                 .contentType(ContentType.JSON)
                 .extract()
                 .body()
@@ -125,7 +126,7 @@ public class UserMailboxesRoutesTest {
                 .getMap(".");
 
             assertThat(errors)
-                .containsEntry("statusCode", 404)
+                .containsEntry("statusCode", HttpStatus.NOT_FOUND_404)
                 .containsEntry("type", "InvalidArgument")
                 .containsEntry("message", "Invalid get on user mailboxes");
         }
@@ -137,7 +138,7 @@ public class UserMailboxesRoutesTest {
             Map<String, Object> errors = when()
                 .get(MAILBOX_NAME)
             .then()
-                .statusCode(404)
+                .statusCode(HttpStatus.NOT_FOUND_404)
                 .contentType(ContentType.JSON)
                 .extract()
                 .body()
@@ -145,7 +146,7 @@ public class UserMailboxesRoutesTest {
                 .getMap(".");
 
             assertThat(errors)
-                .containsEntry("statusCode", 404)
+                .containsEntry("statusCode", HttpStatus.NOT_FOUND_404)
                 .containsEntry("type", "InvalidArgument")
                 .containsEntry("message", "Invalid get on user mailboxes");
         }
@@ -157,7 +158,7 @@ public class UserMailboxesRoutesTest {
             Map<String, Object> errors = when()
                 .put(MAILBOX_NAME)
             .then()
-                .statusCode(404)
+                .statusCode(HttpStatus.NOT_FOUND_404)
                 .contentType(ContentType.JSON)
                 .extract()
                 .body()
@@ -165,7 +166,7 @@ public class UserMailboxesRoutesTest {
                 .getMap(".");
 
             assertThat(errors)
-                .containsEntry("statusCode", 404)
+                .containsEntry("statusCode", HttpStatus.NOT_FOUND_404)
                 .containsEntry("type", "InvalidArgument")
                 .containsEntry("message", "Invalid get on user mailboxes");
         }
@@ -177,7 +178,7 @@ public class UserMailboxesRoutesTest {
             Map<String, Object> errors = when()
                 .put(MAILBOX_NAME)
             .then()
-                .statusCode(404)
+                .statusCode(HttpStatus.NOT_FOUND_404)
                 .contentType(ContentType.JSON)
                 .extract()
                 .body()
@@ -185,7 +186,7 @@ public class UserMailboxesRoutesTest {
                 .getMap(".");
 
             assertThat(errors)
-                .containsEntry("statusCode", 404)
+                .containsEntry("statusCode", HttpStatus.NOT_FOUND_404)
                 .containsEntry("type", "InvalidArgument")
                 .containsEntry("message", "Invalid get on user mailboxes");
         }
@@ -197,7 +198,7 @@ public class UserMailboxesRoutesTest {
             Map<String, Object> errors = when()
                 .get(MAILBOX_NAME + "*")
             .then()
-                .statusCode(400)
+                .statusCode(HttpStatus.BAD_REQUEST_400)
                 .contentType(ContentType.JSON)
                 .extract()
                 .body()
@@ -205,7 +206,7 @@ public class UserMailboxesRoutesTest {
                 .getMap(".");
 
             assertThat(errors)
-                .containsEntry("statusCode", 400)
+                .containsEntry("statusCode", HttpStatus.BAD_REQUEST_400)
                 .containsEntry("type", "InvalidArgument")
                 .containsEntry("message", "Attempt to create an invalid mailbox");
         }
@@ -217,7 +218,7 @@ public class UserMailboxesRoutesTest {
             Map<String, Object> errors = when()
                 .put(MAILBOX_NAME+ "*")
             .then()
-                .statusCode(400)
+                .statusCode(HttpStatus.BAD_REQUEST_400)
                 .contentType(ContentType.JSON)
                 .extract()
                 .body()
@@ -225,7 +226,7 @@ public class UserMailboxesRoutesTest {
                 .getMap(".");
 
             assertThat(errors)
-                .containsEntry("statusCode", 400)
+                .containsEntry("statusCode", HttpStatus.BAD_REQUEST_400)
                 .containsEntry("type", "InvalidArgument")
                 .containsEntry("message", "Attempt to create an invalid mailbox");
         }
@@ -237,7 +238,7 @@ public class UserMailboxesRoutesTest {
             Map<String, Object> errors = when()
                 .put(MAILBOX_NAME + "*")
             .then()
-                .statusCode(400)
+                .statusCode(HttpStatus.BAD_REQUEST_400)
                 .contentType(ContentType.JSON)
                 .extract()
                 .body()
@@ -245,7 +246,7 @@ public class UserMailboxesRoutesTest {
                 .getMap(".");
 
             assertThat(errors)
-                .containsEntry("statusCode", 400)
+                .containsEntry("statusCode", HttpStatus.BAD_REQUEST_400)
                 .containsEntry("type", "InvalidArgument")
                 .containsEntry("message", "Attempt to create an invalid mailbox");
         }
@@ -257,7 +258,7 @@ public class UserMailboxesRoutesTest {
             Map<String, Object> errors = when()
                 .get(MAILBOX_NAME + "%")
             .then()
-                .statusCode(400)
+                .statusCode(HttpStatus.BAD_REQUEST_400)
                 .contentType(ContentType.JSON)
                 .extract()
                 .body()
@@ -265,7 +266,7 @@ public class UserMailboxesRoutesTest {
                 .getMap(".");
 
             assertThat(errors)
-                .containsEntry("statusCode", 400)
+                .containsEntry("statusCode", HttpStatus.BAD_REQUEST_400)
                 .containsEntry("type", "InvalidArgument")
                 .containsEntry("message", "Attempt to create an invalid mailbox");
         }
@@ -277,7 +278,7 @@ public class UserMailboxesRoutesTest {
             Map<String, Object> errors = when()
                 .put(MAILBOX_NAME+ "%")
             .then()
-                .statusCode(400)
+                .statusCode(HttpStatus.BAD_REQUEST_400)
                 .contentType(ContentType.JSON)
                 .extract()
                 .body()
@@ -285,7 +286,7 @@ public class UserMailboxesRoutesTest {
                 .getMap(".");
 
             assertThat(errors)
-                .containsEntry("statusCode", 400)
+                .containsEntry("statusCode", HttpStatus.BAD_REQUEST_400)
                 .containsEntry("type", "InvalidArgument")
                 .containsEntry("message", "Attempt to create an invalid mailbox");
         }
@@ -297,7 +298,7 @@ public class UserMailboxesRoutesTest {
             Map<String, Object> errors = when()
                 .put(MAILBOX_NAME + "%")
             .then()
-                .statusCode(400)
+                .statusCode(HttpStatus.BAD_REQUEST_400)
                 .contentType(ContentType.JSON)
                 .extract()
                 .body()
@@ -305,7 +306,7 @@ public class UserMailboxesRoutesTest {
                 .getMap(".");
 
             assertThat(errors)
-                .containsEntry("statusCode", 400)
+                .containsEntry("statusCode", HttpStatus.BAD_REQUEST_400)
                 .containsEntry("type", "InvalidArgument")
                 .containsEntry("message", "Attempt to create an invalid mailbox");
         }
@@ -317,7 +318,7 @@ public class UserMailboxesRoutesTest {
             Map<String, Object> errors = when()
                 .get(MAILBOX_NAME + "#")
             .then()
-                .statusCode(400)
+                .statusCode(HttpStatus.BAD_REQUEST_400)
                 .contentType(ContentType.JSON)
                 .extract()
                 .body()
@@ -325,7 +326,7 @@ public class UserMailboxesRoutesTest {
                 .getMap(".");
 
             assertThat(errors)
-                .containsEntry("statusCode", 400)
+                .containsEntry("statusCode", HttpStatus.BAD_REQUEST_400)
                 .containsEntry("type", "InvalidArgument")
                 .containsEntry("message", "Attempt to create an invalid mailbox");
         }
@@ -337,7 +338,7 @@ public class UserMailboxesRoutesTest {
             Map<String, Object> errors = when()
                 .put(MAILBOX_NAME+ "#")
             .then()
-                .statusCode(400)
+                .statusCode(HttpStatus.BAD_REQUEST_400)
                 .contentType(ContentType.JSON)
                 .extract()
                 .body()
@@ -345,7 +346,7 @@ public class UserMailboxesRoutesTest {
                 .getMap(".");
 
             assertThat(errors)
-                .containsEntry("statusCode", 400)
+                .containsEntry("statusCode", HttpStatus.BAD_REQUEST_400)
                 .containsEntry("type", "InvalidArgument")
                 .containsEntry("message", "Attempt to create an invalid mailbox");
         }
@@ -357,7 +358,7 @@ public class UserMailboxesRoutesTest {
             Map<String, Object> errors = when()
                 .put(MAILBOX_NAME + "#")
             .then()
-                .statusCode(400)
+                .statusCode(HttpStatus.BAD_REQUEST_400)
                 .contentType(ContentType.JSON)
                 .extract()
                 .body()
@@ -365,7 +366,7 @@ public class UserMailboxesRoutesTest {
                 .getMap(".");
 
             assertThat(errors)
-                .containsEntry("statusCode", 400)
+                .containsEntry("statusCode", HttpStatus.BAD_REQUEST_400)
                 .containsEntry("type", "InvalidArgument")
                 .containsEntry("message", "Attempt to create an invalid mailbox");
         }
@@ -377,7 +378,7 @@ public class UserMailboxesRoutesTest {
             Map<String, Object> errors = when()
                 .get(MAILBOX_NAME + "&")
             .then()
-                .statusCode(400)
+                .statusCode(HttpStatus.BAD_REQUEST_400)
                 .contentType(ContentType.JSON)
                 .extract()
                 .body()
@@ -385,7 +386,7 @@ public class UserMailboxesRoutesTest {
                 .getMap(".");
 
             assertThat(errors)
-                .containsEntry("statusCode", 400)
+                .containsEntry("statusCode", HttpStatus.BAD_REQUEST_400)
                 .containsEntry("type", "InvalidArgument")
                 .containsEntry("message", "Attempt to create an invalid mailbox");
         }
@@ -397,7 +398,7 @@ public class UserMailboxesRoutesTest {
             Map<String, Object> errors = when()
                 .put(MAILBOX_NAME+ "&")
             .then()
-                .statusCode(400)
+                .statusCode(HttpStatus.BAD_REQUEST_400)
                 .contentType(ContentType.JSON)
                 .extract()
                 .body()
@@ -405,7 +406,7 @@ public class UserMailboxesRoutesTest {
                 .getMap(".");
 
             assertThat(errors)
-                .containsEntry("statusCode", 400)
+                .containsEntry("statusCode", HttpStatus.BAD_REQUEST_400)
                 .containsEntry("type", "InvalidArgument")
                 .containsEntry("message", "Attempt to create an invalid mailbox");
         }
@@ -417,7 +418,7 @@ public class UserMailboxesRoutesTest {
             Map<String, Object> errors = when()
                 .put(MAILBOX_NAME + "&")
             .then()
-                .statusCode(400)
+                .statusCode(HttpStatus.BAD_REQUEST_400)
                 .contentType(ContentType.JSON)
                 .extract()
                 .body()
@@ -425,7 +426,7 @@ public class UserMailboxesRoutesTest {
                 .getMap(".");
 
             assertThat(errors)
-                .containsEntry("statusCode", 400)
+                .containsEntry("statusCode", HttpStatus.BAD_REQUEST_400)
                 .containsEntry("type", "InvalidArgument")
                 .containsEntry("message", "Attempt to create an invalid mailbox");
         }
@@ -437,7 +438,7 @@ public class UserMailboxesRoutesTest {
             Map<String, Object> errors = when()
                 .delete()
             .then()
-                .statusCode(404)
+                .statusCode(HttpStatus.NOT_FOUND_404)
                 .contentType(ContentType.JSON)
                 .extract()
                 .body()
@@ -445,7 +446,7 @@ public class UserMailboxesRoutesTest {
                 .getMap(".");
 
             assertThat(errors)
-                .containsEntry("statusCode", 404)
+                .containsEntry("statusCode", HttpStatus.NOT_FOUND_404)
                 .containsEntry("type", "InvalidArgument")
                 .containsEntry("message", "Invalid delete on user mailboxes");
         }
@@ -456,7 +457,7 @@ public class UserMailboxesRoutesTest {
                 when()
                     .get()
                 .then()
-                    .statusCode(200)
+                    .statusCode(HttpStatus.OK_200)
                     .contentType(ContentType.JSON)
                     .extract()
                     .body()
@@ -471,8 +472,8 @@ public class UserMailboxesRoutesTest {
             when()
                 .put()
             .then()
-                .statusCode(404)
-                .body(containsString("404 Not found"));
+                .statusCode(HttpStatus.NOT_FOUND_404)
+                .body(containsString(HttpStatus.NOT_FOUND_404 + " Not found"));
         }
 
         @Test
@@ -480,8 +481,8 @@ public class UserMailboxesRoutesTest {
             when()
                 .put(SEPARATOR)
             .then()
-                .statusCode(404)
-                .body(containsString("404 Not found"));
+                .statusCode(HttpStatus.NOT_FOUND_404)
+                .body(containsString(HttpStatus.NOT_FOUND_404 + " Not found"));
         }
 
         @Test
@@ -489,7 +490,7 @@ public class UserMailboxesRoutesTest {
             when()
                 .put(MAILBOX_NAME)
             .then()
-                .statusCode(204);
+                .statusCode(HttpStatus.NO_CONTENT_204);
         }
 
         @Test
@@ -500,7 +501,7 @@ public class UserMailboxesRoutesTest {
             when()
                 .put(MAILBOX_NAME)
             .then()
-                .statusCode(204);
+                .statusCode(HttpStatus.NO_CONTENT_204);
         }
 
         @Test
@@ -511,7 +512,7 @@ public class UserMailboxesRoutesTest {
             when()
                 .get()
             .then()
-                .statusCode(200)
+                .statusCode(HttpStatus.OK_200)
                 .body(is("[{\"mailboxName\":\"myMailboxName\"}]"));
         }
 
@@ -520,7 +521,7 @@ public class UserMailboxesRoutesTest {
             Map<String, Object> errors = when()
                 .get(MAILBOX_NAME)
             .then()
-                .statusCode(404)
+                .statusCode(HttpStatus.NOT_FOUND_404)
                 .contentType(ContentType.JSON)
                 .extract()
                 .body()
@@ -528,7 +529,7 @@ public class UserMailboxesRoutesTest {
                 .getMap(".");
 
             assertThat(errors)
-                .containsEntry("statusCode", 404)
+                .containsEntry("statusCode", HttpStatus.NOT_FOUND_404)
                 .containsEntry("type", "InvalidArgument")
                 .containsEntry("message", "Invalid get on user mailboxes");
         }
@@ -541,7 +542,7 @@ public class UserMailboxesRoutesTest {
             when()
                 .get(MAILBOX_NAME)
             .then()
-                .statusCode(204);
+                .statusCode(HttpStatus.NO_CONTENT_204);
         }
 
         @Test
@@ -549,7 +550,7 @@ public class UserMailboxesRoutesTest {
             when()
                 .delete(MAILBOX_NAME)
             .then()
-                .statusCode(204);
+                .statusCode(HttpStatus.NO_CONTENT_204);
         }
 
         @Test
@@ -560,7 +561,7 @@ public class UserMailboxesRoutesTest {
             when()
                 .delete(MAILBOX_NAME)
             .then()
-                .statusCode(204);
+                .statusCode(HttpStatus.NO_CONTENT_204);
         }
 
         @Test
@@ -574,7 +575,7 @@ public class UserMailboxesRoutesTest {
             Map<String, Object> errors = when()
                 .get(MAILBOX_NAME)
             .then()
-                .statusCode(404)
+                .statusCode(HttpStatus.NOT_FOUND_404)
                 .contentType(ContentType.JSON)
                 .extract()
                 .body()
@@ -582,7 +583,7 @@ public class UserMailboxesRoutesTest {
                 .getMap(".");
 
             assertThat(errors)
-                .containsEntry("statusCode", 404)
+                .containsEntry("statusCode", HttpStatus.NOT_FOUND_404)
                 .containsEntry("type", "InvalidArgument")
                 .containsEntry("message", "Invalid get on user mailboxes");
         }
@@ -592,7 +593,7 @@ public class UserMailboxesRoutesTest {
             when()
                 .delete()
             .then()
-                .statusCode(204);
+                .statusCode(HttpStatus.NO_CONTENT_204);
         }
 
         @Test
@@ -603,7 +604,7 @@ public class UserMailboxesRoutesTest {
             when()
                 .delete()
                 .then()
-                .statusCode(204);
+                .statusCode(HttpStatus.NO_CONTENT_204);
         }
 
         @Test
@@ -621,7 +622,7 @@ public class UserMailboxesRoutesTest {
                 when()
                     .get()
                 .then()
-                    .statusCode(200)
+                    .statusCode(HttpStatus.OK_200)
                     .contentType(ContentType.JSON)
                     .extract()
                     .body()
@@ -642,7 +643,7 @@ public class UserMailboxesRoutesTest {
             when()
                 .delete(MAILBOX_NAME)
             .then()
-                .statusCode(204);
+                .statusCode(HttpStatus.NO_CONTENT_204);
         }
 
         @Test
@@ -660,7 +661,7 @@ public class UserMailboxesRoutesTest {
                 when()
                     .get()
                 .then()
-                    .statusCode(200)
+                    .statusCode(HttpStatus.OK_200)
                     .contentType(ContentType.JSON)
                     .extract()
                     .body()
@@ -686,7 +687,7 @@ public class UserMailboxesRoutesTest {
                 when()
                     .get()
                 .then()
-                    .statusCode(200)
+                    .statusCode(HttpStatus.OK_200)
                     .contentType(ContentType.JSON)
                     .extract()
                     .body()
@@ -707,7 +708,7 @@ public class UserMailboxesRoutesTest {
             when()
                 .delete(MAILBOX_NAME + ".child")
             .then()
-                .statusCode(204);
+                .statusCode(HttpStatus.NO_CONTENT_204);
         }
 
         @Test
@@ -725,7 +726,7 @@ public class UserMailboxesRoutesTest {
                 when()
                     .get()
                 .then()
-                    .statusCode(200)
+                    .statusCode(HttpStatus.OK_200)
                     .contentType(ContentType.JSON)
                     .extract()
                     .body()
@@ -755,7 +756,7 @@ public class UserMailboxesRoutesTest {
             when()
                 .put(MAILBOX_NAME)
             .then()
-                .statusCode(500)
+                .statusCode(HttpStatus.INTERNAL_SERVER_ERROR_500)
                 .body(containsString("500 Internal Server Error"));
         }
 
@@ -766,7 +767,7 @@ public class UserMailboxesRoutesTest {
             when()
                 .put(MAILBOX_NAME)
             .then()
-                .statusCode(500)
+                .statusCode(HttpStatus.INTERNAL_SERVER_ERROR_500)
                 .body(containsString("500 Internal Server Error"));
         }
 
@@ -777,7 +778,7 @@ public class UserMailboxesRoutesTest {
             when()
                 .put(MAILBOX_NAME)
             .then()
-                .statusCode(204);
+                .statusCode(HttpStatus.NO_CONTENT_204);
         }
 
         @Test
@@ -793,7 +794,7 @@ public class UserMailboxesRoutesTest {
             when()
                 .delete(MAILBOX_NAME)
             .then()
-                .statusCode(500)
+                .statusCode(HttpStatus.INTERNAL_SERVER_ERROR_500)
                 .body(containsString("500 Internal Server Error"));
         }
 
@@ -804,7 +805,7 @@ public class UserMailboxesRoutesTest {
             when()
                 .delete(MAILBOX_NAME)
             .then()
-                .statusCode(500)
+                .statusCode(HttpStatus.INTERNAL_SERVER_ERROR_500)
                 .body(containsString("500 Internal Server Error"));
         }
 
@@ -820,7 +821,7 @@ public class UserMailboxesRoutesTest {
             when()
                 .delete(MAILBOX_NAME)
             .then()
-                .statusCode(500)
+                .statusCode(HttpStatus.INTERNAL_SERVER_ERROR_500)
                 .body(containsString("500 Internal Server Error"));
         }
 
@@ -831,7 +832,7 @@ public class UserMailboxesRoutesTest {
             when()
                 .delete(MAILBOX_NAME)
             .then()
-                .statusCode(500)
+                .statusCode(HttpStatus.INTERNAL_SERVER_ERROR_500)
                 .body(containsString("500 Internal Server Error"));
         }
 
@@ -842,7 +843,7 @@ public class UserMailboxesRoutesTest {
             when()
                 .delete(MAILBOX_NAME)
             .then()
-                .statusCode(204);
+                .statusCode(HttpStatus.NO_CONTENT_204);
         }
 
         @Test
@@ -852,7 +853,7 @@ public class UserMailboxesRoutesTest {
             when()
                 .delete()
             .then()
-                .statusCode(500)
+                .statusCode(HttpStatus.INTERNAL_SERVER_ERROR_500)
                 .body(containsString("500 Internal Server Error"));
         }
 
@@ -863,7 +864,7 @@ public class UserMailboxesRoutesTest {
             when()
                 .delete()
                 .then()
-                .statusCode(500)
+                .statusCode(HttpStatus.INTERNAL_SERVER_ERROR_500)
                 .body(containsString("500 Internal Server Error"));
         }
 
@@ -880,7 +881,7 @@ public class UserMailboxesRoutesTest {
             when()
                 .delete()
             .then()
-                .statusCode(500)
+                .statusCode(HttpStatus.INTERNAL_SERVER_ERROR_500)
                 .body(containsString("500 Internal Server Error"));
         }
 
@@ -895,7 +896,7 @@ public class UserMailboxesRoutesTest {
             when()
                 .delete()
             .then()
-                .statusCode(204);
+                .statusCode(HttpStatus.NO_CONTENT_204);
         }
 
         @Test
@@ -909,7 +910,7 @@ public class UserMailboxesRoutesTest {
             when()
                 .delete()
             .then()
-                .statusCode(500)
+                .statusCode(HttpStatus.INTERNAL_SERVER_ERROR_500)
                 .body(containsString("500 Internal Server Error"));
         }
 
@@ -920,7 +921,7 @@ public class UserMailboxesRoutesTest {
             when()
                 .get(MAILBOX_NAME)
             .then()
-                .statusCode(500)
+                .statusCode(HttpStatus.INTERNAL_SERVER_ERROR_500)
                 .body(containsString("500 Internal Server Error"));
         }
 
@@ -931,7 +932,7 @@ public class UserMailboxesRoutesTest {
             when()
                 .get(MAILBOX_NAME)
             .then()
-                .statusCode(500)
+                .statusCode(HttpStatus.INTERNAL_SERVER_ERROR_500)
                 .body(containsString("500 Internal Server Error"));
         }
 
@@ -942,7 +943,7 @@ public class UserMailboxesRoutesTest {
             when()
                 .get()
             .then()
-                .statusCode(500)
+                .statusCode(HttpStatus.INTERNAL_SERVER_ERROR_500)
                 .body(containsString("500 Internal Server Error"));
         }
 
@@ -953,7 +954,7 @@ public class UserMailboxesRoutesTest {
             when()
                 .get()
             .then()
-                .statusCode(500)
+                .statusCode(HttpStatus.INTERNAL_SERVER_ERROR_500)
                 .body(containsString("500 Internal Server Error"));
         }
 
@@ -964,7 +965,7 @@ public class UserMailboxesRoutesTest {
             when()
                 .get()
             .then()
-                .statusCode(500)
+                .statusCode(HttpStatus.INTERNAL_SERVER_ERROR_500)
                 .body(containsString("500 Internal Server Error"));
         }
 
@@ -975,7 +976,7 @@ public class UserMailboxesRoutesTest {
             when()
                 .get(MAILBOX_NAME)
             .then()
-                .statusCode(500)
+                .statusCode(HttpStatus.INTERNAL_SERVER_ERROR_500)
                 .body(containsString("500 Internal Server Error"));
         }
 
@@ -986,7 +987,7 @@ public class UserMailboxesRoutesTest {
             when()
                 .put(MAILBOX_NAME)
             .then()
-                .statusCode(500)
+                .statusCode(HttpStatus.INTERNAL_SERVER_ERROR_500)
                 .body(containsString("500 Internal Server Error"));
         }
 
@@ -997,7 +998,7 @@ public class UserMailboxesRoutesTest {
             when()
                 .delete(MAILBOX_NAME)
             .then()
-                .statusCode(500)
+                .statusCode(HttpStatus.INTERNAL_SERVER_ERROR_500)
                 .body(containsString("500 Internal Server Error"));
         }
 
@@ -1008,7 +1009,7 @@ public class UserMailboxesRoutesTest {
             when()
                 .delete()
                 .then()
-                .statusCode(500)
+                .statusCode(HttpStatus.INTERNAL_SERVER_ERROR_500)
                 .body(containsString("500 Internal Server Error"));
         }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/21188d00/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
index d6d364e..4dde510 100644
--- 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
@@ -26,6 +26,7 @@ import org.apache.james.webadmin.Routes;
 import org.apache.james.webadmin.WebAdminConfiguration;
 import org.apache.james.webadmin.swagger.SwaggerParser;
 
+import org.eclipse.jetty.http.HttpStatus;
 import spark.Service;
 
 public class SwaggerRoutes implements Routes {
@@ -41,7 +42,7 @@ public class SwaggerRoutes implements Routes {
     @Override
     public void define(Service service) {
         service.get(SWAGGER_ENDPOINT, (request, response) -> {
-            response.status(200);
+            response.status(HttpStatus.OK_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


[3/5] james-project git commit: JAMES-2233 WebAdmin responses more details when error

Posted by bt...@apache.org.
JAMES-2233 WebAdmin responses more details when error


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

Branch: refs/heads/master
Commit: bde6bdb7d4921af4245cd7ab84e6aa3943cbc517
Parents: 16410ae
Author: quynhn <qn...@linagora.com>
Authored: Fri Dec 1 11:51:19 2017 +0700
Committer: benwa <bt...@linagora.com>
Committed: Wed Dec 6 09:10:07 2017 +0700

----------------------------------------------------------------------
 .../routes/CassandraMigrationRoutes.java        |  45 ++-
 .../routes/CassandraMigrationRoutesTest.java    |  45 ++-
 server/protocols/webadmin/webadmin-core/pom.xml |   5 +
 .../james/webadmin/utils/ErrorResponder.java    | 145 ++++++++
 .../webadmin/utils/ErrorResponderTest.java      | 139 ++++++++
 .../james/webadmin/routes/DomainsRoutes.java    |  43 ++-
 .../james/webadmin/routes/GroupsRoutes.java     |  34 +-
 .../james/webadmin/routes/UserRoutes.java       |  40 ++-
 .../webadmin/routes/DomainsRoutesTest.java      |  30 +-
 .../james/webadmin/routes/GroupsRoutesTest.java | 166 ++++++++--
 .../webadmin/routes/GlobalQuotaRoutes.java      |  37 ++-
 .../webadmin/routes/UserMailboxesRoutes.java    |  77 ++++-
 .../webadmin/routes/GlobalQuotaRoutesTest.java  |  61 +++-
 .../routes/UserMailboxesRoutesTest.java         | 330 +++++++++++++++----
 14 files changed, 1029 insertions(+), 168 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/bde6bdb7/server/protocols/webadmin/webadmin-cassandra/src/main/java/org/apache/james/webadmin/routes/CassandraMigrationRoutes.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/webadmin-cassandra/src/main/java/org/apache/james/webadmin/routes/CassandraMigrationRoutes.java b/server/protocols/webadmin/webadmin-cassandra/src/main/java/org/apache/james/webadmin/routes/CassandraMigrationRoutes.java
index c574f13..ff08bea 100644
--- a/server/protocols/webadmin/webadmin-cassandra/src/main/java/org/apache/james/webadmin/routes/CassandraMigrationRoutes.java
+++ b/server/protocols/webadmin/webadmin-cassandra/src/main/java/org/apache/james/webadmin/routes/CassandraMigrationRoutes.java
@@ -26,7 +26,10 @@ import org.apache.james.webadmin.Routes;
 import org.apache.james.webadmin.dto.CassandraVersionRequest;
 import org.apache.james.webadmin.service.CassandraMigrationService;
 import org.apache.james.webadmin.service.MigrationException;
+import org.apache.james.webadmin.utils.ErrorResponder;
+import org.apache.james.webadmin.utils.ErrorResponder.ErrorType;
 import org.apache.james.webadmin.utils.JsonTransformer;
+import org.eclipse.jetty.http.HttpStatus;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -41,9 +44,6 @@ public class CassandraMigrationRoutes implements Routes {
     private static final String VERSION_UPGRADE_BASE = VERSION_BASE + "/upgrade";
     private static final String VERSION_UPGRADE_TO_LATEST_BASE = VERSION_UPGRADE_BASE + "/latest";
     private static final int NO_CONTENT = 204;
-    private static final int INVALID_VERSION = 400;
-    private static final int MIGRATION_CAN_NOT_BE_PERFORMED = 410;
-    private static final int INTERNAL_ERROR = 500;
 
     private final CassandraMigrationService cassandraMigrationService;
     private final JsonTransformer jsonTransformer;
@@ -72,15 +72,28 @@ public class CassandraMigrationRoutes implements Routes {
                 response.status(NO_CONTENT);
             } catch (NullPointerException | IllegalArgumentException e) {
                 LOGGER.info("Invalid request for version upgrade");
-                response.status(INVALID_VERSION);
+                throw ErrorResponder.builder()
+                    .statusCode(HttpStatus.BAD_REQUEST_400)
+                    .type(ErrorType.INVALID_ARGUMENT)
+                    .message("Invalid request for version upgrade")
+                    .cause(e)
+                    .haltError();
             } catch (IllegalStateException e) {
                 LOGGER.info("The migration requested can not be performed.", e);
-                response.status(MIGRATION_CAN_NOT_BE_PERFORMED);
-                response.body(e.getMessage());
+                throw ErrorResponder.builder()
+                    .statusCode(HttpStatus.GONE_410)
+                    .type(ErrorType.WRONG_STATE)
+                    .message("The migration requested can not be performed")
+                    .cause(e)
+                    .haltError();
             } catch (MigrationException e) {
                 LOGGER.error("An error lead to partial migration process", e);
-                response.status(INTERNAL_ERROR);
-                response.body(e.getMessage());
+                throw ErrorResponder.builder()
+                    .statusCode(HttpStatus.INTERNAL_SERVER_ERROR_500)
+                    .type(ErrorType.SERVER_ERROR)
+                    .message("An error lead to partial migration process")
+                    .cause(e)
+                    .haltError();
             }
             return Constants.EMPTY_BODY;
         });
@@ -90,12 +103,20 @@ public class CassandraMigrationRoutes implements Routes {
                 cassandraMigrationService.upgradeToLastVersion();
             } catch (IllegalStateException e) {
                 LOGGER.info("The migration requested can not be performed.", e);
-                response.status(MIGRATION_CAN_NOT_BE_PERFORMED);
-                response.body(e.getMessage());
+                throw ErrorResponder.builder()
+                    .statusCode(HttpStatus.GONE_410)
+                    .type(ErrorType.WRONG_STATE)
+                    .message("The migration requested can not be performed")
+                    .cause(e)
+                    .haltError();
             } catch (MigrationException e) {
                 LOGGER.error("An error lead to partial migration process", e);
-                response.status(INTERNAL_ERROR);
-                response.body(e.getMessage());
+                throw ErrorResponder.builder()
+                    .statusCode(HttpStatus.INTERNAL_SERVER_ERROR_500)
+                    .type(ErrorType.SERVER_ERROR)
+                    .message("An error lead to partial migration process")
+                    .cause(e)
+                    .haltError();
             }
 
             return Constants.EMPTY_BODY;

http://git-wip-us.apache.org/repos/asf/james-project/blob/bde6bdb7/server/protocols/webadmin/webadmin-cassandra/src/test/java/org/apache/james/webadmin/routes/CassandraMigrationRoutesTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/webadmin-cassandra/src/test/java/org/apache/james/webadmin/routes/CassandraMigrationRoutesTest.java b/server/protocols/webadmin/webadmin-cassandra/src/test/java/org/apache/james/webadmin/routes/CassandraMigrationRoutesTest.java
index e647011..a6d6c14 100644
--- a/server/protocols/webadmin/webadmin-cassandra/src/test/java/org/apache/james/webadmin/routes/CassandraMigrationRoutesTest.java
+++ b/server/protocols/webadmin/webadmin-cassandra/src/test/java/org/apache/james/webadmin/routes/CassandraMigrationRoutesTest.java
@@ -145,12 +145,23 @@ public class CassandraMigrationRoutesTest {
     public void postShouldReturnErrorCodeWhenInvalidVersion() throws Exception {
         when(schemaVersionDAO.getCurrentSchemaVersion()).thenReturn(CompletableFuture.completedFuture(Optional.of(OLDER_VERSION)));
 
-        given()
+        Map<String, Object> errors = given()
             .body(String.valueOf("NonInt"))
         .with()
             .post("/upgrade")
         .then()
-            .statusCode(400);
+            .statusCode(400)
+            .contentType(ContentType.JSON)
+            .extract()
+            .body()
+            .jsonPath()
+            .getMap(".");
+
+        assertThat(errors)
+            .containsEntry("statusCode", 400)
+            .containsEntry("type", "InvalidArgument")
+            .containsEntry("message", "Invalid request for version upgrade")
+            .containsEntry("cause", "For input string: \"NonInt\"");
 
         verifyNoMoreInteractions(schemaVersionDAO);
     }
@@ -175,12 +186,23 @@ public class CassandraMigrationRoutesTest {
     public void postShouldNotDoMigrationWhenCurrentVersionIsNewerThan() throws Exception {
         when(schemaVersionDAO.getCurrentSchemaVersion()).thenReturn(CompletableFuture.completedFuture(Optional.of(CURRENT_VERSION)));
 
-        given()
+        Map<String, Object> errors = given()
             .body(String.valueOf(OLDER_VERSION))
         .with()
             .post("/upgrade")
         .then()
-            .statusCode(410);
+            .statusCode(410)
+            .contentType(ContentType.JSON)
+            .extract()
+            .body()
+            .jsonPath()
+            .getMap(".");
+
+        assertThat(errors)
+            .containsEntry("statusCode", 410)
+            .containsEntry("type", "WrongState")
+            .containsEntry("message", "The migration requested can not be performed")
+            .containsEntry("cause", "Current version is already up to date");
 
         verify(schemaVersionDAO, times(1)).getCurrentSchemaVersion();
         verifyNoMoreInteractions(schemaVersionDAO);
@@ -205,10 +227,21 @@ public class CassandraMigrationRoutesTest {
     public void postShouldNotDoMigrationToLatestVersionWhenItIsUpToDate() throws Exception {
         when(schemaVersionDAO.getCurrentSchemaVersion()).thenReturn(CompletableFuture.completedFuture(Optional.of(LATEST_VERSION)));
 
-        when()
+        Map<String, Object> errors = when()
             .post("/upgrade/latest")
         .then()
-            .statusCode(410);
+            .statusCode(410)
+            .contentType(ContentType.JSON)
+            .extract()
+            .body()
+            .jsonPath()
+            .getMap(".");
+
+        assertThat(errors)
+            .containsEntry("statusCode", 410)
+            .containsEntry("type", "WrongState")
+            .containsEntry("message", "The migration requested can not be performed")
+            .containsEntry("cause", "Current version is already up to date");
 
         verify(schemaVersionDAO, times(1)).getCurrentSchemaVersion();
         verifyNoMoreInteractions(schemaVersionDAO);

http://git-wip-us.apache.org/repos/asf/james-project/blob/bde6bdb7/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 4d5e1c5..d99b417 100644
--- a/server/protocols/webadmin/webadmin-core/pom.xml
+++ b/server/protocols/webadmin/webadmin-core/pom.xml
@@ -104,6 +104,11 @@
             <scope>test</scope>
         </dependency>
         <dependency>
+            <groupId>com.jayway.jsonpath</groupId>
+            <artifactId>json-path</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
             <groupId>org.mockito</groupId>
             <artifactId>mockito-core</artifactId>
             <scope>test</scope>

http://git-wip-us.apache.org/repos/asf/james-project/blob/bde6bdb7/server/protocols/webadmin/webadmin-core/src/main/java/org/apache/james/webadmin/utils/ErrorResponder.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/webadmin-core/src/main/java/org/apache/james/webadmin/utils/ErrorResponder.java b/server/protocols/webadmin/webadmin-core/src/main/java/org/apache/james/webadmin/utils/ErrorResponder.java
new file mode 100644
index 0000000..90642bb
--- /dev/null
+++ b/server/protocols/webadmin/webadmin-core/src/main/java/org/apache/james/webadmin/utils/ErrorResponder.java
@@ -0,0 +1,145 @@
+/****************************************************************
+ * 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.utils;
+
+import static spark.Spark.halt;
+
+import java.util.Objects;
+import java.util.Optional;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.base.Preconditions;
+
+import spark.HaltException;
+
+public class ErrorResponder {
+    public enum ErrorType {
+        INVALID_ARGUMENT("InvalidArgument"),
+        WRONG_STATE("WrongState"),
+        SERVER_ERROR("ServerError");
+
+        private final String type;
+
+        ErrorType(String type) {
+            this.type = type;
+        }
+
+        public String getType() {
+            return type;
+        }
+    }
+
+    private Integer statusCode;
+    private ErrorType type;
+    private String message;
+    private Optional<Exception> cause;
+
+    public ErrorResponder() {
+        cause = Optional.empty();
+    }
+
+    public static ErrorResponder builder() {
+        return new ErrorResponder();
+    }
+
+    public ErrorResponder statusCode(int statusCode) {
+        this.statusCode = statusCode;
+        return this;
+    }
+
+    public ErrorResponder type(ErrorType type) {
+        this.type = type;
+        return this;
+    }
+
+    public ErrorResponder message(String message) {
+        this.message = message;
+        return this;
+    }
+
+    public ErrorResponder cause(Exception cause) {
+        this.cause = Optional.of(cause);
+        return this;
+    }
+
+    public HaltException haltError() {
+        Preconditions.checkNotNull(statusCode, "statusCode must not be null in case of error");
+        Preconditions.checkNotNull(type, "type must not be null in case of error");
+        Preconditions.checkNotNull(message, "message must not be null in case of error");
+        try {
+            return halt(statusCode, new JsonTransformer().render(new ErrorDetail(statusCode,
+                type.getType(),
+                message,
+                cause.map(e -> Optional.of(e.getMessage())).orElse(Optional.empty()))));
+        } catch (JsonProcessingException e) {
+            return halt(statusCode);
+        }
+    }
+
+    static class ErrorDetail {
+        private final int statusCode;
+        private final String type;
+        private final String message;
+        private final Optional<String> cause;
+
+        @VisibleForTesting
+        ErrorDetail(int statusCode, String type, String message, Optional<String> cause) {
+            this.statusCode = statusCode;
+            this.type = type;
+            this.message = message;
+            this.cause = cause;
+        }
+
+        public int getStatusCode() {
+            return statusCode;
+        }
+
+        public String getType() {
+            return type;
+        }
+
+        public String getMessage() {
+            return message;
+        }
+
+        public Optional<String> getCause() {
+            return cause;
+        }
+
+        @Override
+        public final boolean equals(Object o) {
+            if (o instanceof ErrorDetail) {
+                ErrorDetail that = (ErrorDetail) o;
+
+                return Objects.equals(this.statusCode, that.statusCode)
+                    && Objects.equals(this.type, that.type)
+                    && Objects.equals(this.message, that.message)
+                    && Objects.equals(this.cause, that.cause);
+            }
+            return false;
+        }
+
+        @Override
+        public final int hashCode() {
+            return Objects.hash(statusCode, type, message, cause);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/bde6bdb7/server/protocols/webadmin/webadmin-core/src/test/java/org/apache/james/webadmin/utils/ErrorResponderTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/webadmin-core/src/test/java/org/apache/james/webadmin/utils/ErrorResponderTest.java b/server/protocols/webadmin/webadmin-core/src/test/java/org/apache/james/webadmin/utils/ErrorResponderTest.java
new file mode 100644
index 0000000..3e98aae
--- /dev/null
+++ b/server/protocols/webadmin/webadmin-core/src/test/java/org/apache/james/webadmin/utils/ErrorResponderTest.java
@@ -0,0 +1,139 @@
+/****************************************************************
+ * 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.utils;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+import java.util.Objects;
+import java.util.Optional;
+
+import org.junit.Test;
+
+import com.jayway.jsonpath.DocumentContext;
+import com.jayway.jsonpath.JsonPath;
+
+import spark.HaltException;
+
+public class ErrorResponderTest {
+
+    public static final Optional<String> NO_CAUSE = Optional.empty();
+
+    @Test
+    public void haltErrorShouldThrowWhenNoStatusCode() throws Exception {
+        assertThatThrownBy(() -> ErrorResponder.builder()
+            .haltError())
+            .isInstanceOf(NullPointerException.class);
+    }
+
+    @Test
+    public void haltErrorShouldThrowWhenNoType() throws Exception {
+        assertThatThrownBy(() -> ErrorResponder.builder()
+            .statusCode(400)
+            .haltError())
+            .isInstanceOf(NullPointerException.class);
+    }
+
+    @Test
+    public void haltErrorShouldThrowWhenNoMessage() throws Exception {
+        assertThatThrownBy(() -> ErrorResponder.builder()
+            .statusCode(400)
+            .type(ErrorResponder.ErrorType.INVALID_ARGUMENT)
+            .haltError())
+            .isInstanceOf(NullPointerException.class);
+    }
+
+    @Test
+    public void haltErrorShouldReturnBodyWithStatusCodeWhenSetting() throws Exception {
+        assertThatThrownBy(() -> ErrorResponder.builder()
+                .statusCode(404)
+                .type(ErrorResponder.ErrorType.INVALID_ARGUMENT)
+                .message("Error")
+                .haltError())
+            .isInstanceOf(HaltException.class)
+            .matches(e -> hasStatus(e, 404))
+            .matches(e -> bodyHasErrorDetail(e, new ErrorResponder.ErrorDetail(404, "InvalidArgument", "Error", NO_CAUSE)));
+    }
+
+    @Test
+    public void haltErrorShouldReturnBodyWithErrorTypeWhenSetting() throws Exception {
+        assertThatThrownBy(() -> ErrorResponder.builder()
+                .statusCode(400)
+                .type(ErrorResponder.ErrorType.WRONG_STATE)
+                .message("Error")
+                .haltError())
+            .isInstanceOf(HaltException.class)
+            .matches(e -> hasStatus(e, 400))
+            .matches(e -> bodyHasErrorDetail(e, new ErrorResponder.ErrorDetail(400, "WrongState", "Error", NO_CAUSE)));
+    }
+
+    @Test
+    public void haltErrorShouldReturnBodyWithErrorMessageWhenSetting() throws Exception {
+        assertThatThrownBy(() -> ErrorResponder.builder()
+                .statusCode(400)
+                .type(ErrorResponder.ErrorType.INVALID_ARGUMENT)
+                .message("It has error")
+                .haltError())
+            .isInstanceOf(HaltException.class)
+            .matches(e -> hasStatus(e, 400))
+            .matches(e -> bodyHasErrorDetail(e, new ErrorResponder.ErrorDetail(400, "InvalidArgument", "It has error", NO_CAUSE)));
+    }
+
+    @Test
+    public void haltErrorShouldReturnBodyWithCauseTypeWhenSetting() throws Exception {
+        assertThatThrownBy(() -> ErrorResponder.builder()
+                .statusCode(400)
+                .type(ErrorResponder.ErrorType.INVALID_ARGUMENT)
+                .message("Error")
+                .cause(new IllegalArgumentException("The input data is invalid"))
+                .haltError())
+            .isInstanceOf(HaltException.class)
+            .matches(e -> hasStatus(e, 400))
+            .matches(e -> bodyHasErrorDetail(e, new ErrorResponder.ErrorDetail(400, "InvalidArgument", "Error", Optional.of("The input data is invalid"))));
+    }
+
+    @Test
+    public void haltErrorShouldReturnBodyWithErrorDetail() throws Exception {
+        assertThatThrownBy(() -> ErrorResponder.builder()
+                .statusCode(400)
+                .type(ErrorResponder.ErrorType.INVALID_ARGUMENT)
+                .message("Error")
+                .cause(new IllegalArgumentException("The input data is invalid"))
+            .haltError())
+            .isInstanceOf(HaltException.class)
+            .matches(e -> hasStatus(e, 400))
+            .matches(e -> bodyHasErrorDetail(e, new ErrorResponder.ErrorDetail(400, "InvalidArgument", "Error", Optional.of("The input data is invalid"))));
+    }
+
+    private boolean hasStatus(Throwable throwable, int status) {
+        HaltException haltException = (HaltException) throwable;
+        return Objects.equals(haltException.statusCode(), status);
+    }
+
+    private boolean bodyHasErrorDetail(Throwable throwable, ErrorResponder.ErrorDetail errorDetail) {
+        HaltException haltException = (HaltException) throwable;
+        DocumentContext jsonPath = JsonPath.parse(haltException.body());
+        return errorDetail.equals(new ErrorResponder.ErrorDetail(
+            jsonPath.read("$.statusCode"),
+            jsonPath.read("$.type"),
+            jsonPath.read("$.message"),
+            Optional.ofNullable(jsonPath.read("$.cause"))));
+    }
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/james-project/blob/bde6bdb7/server/protocols/webadmin/webadmin-data/src/main/java/org/apache/james/webadmin/routes/DomainsRoutes.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/webadmin-data/src/main/java/org/apache/james/webadmin/routes/DomainsRoutes.java b/server/protocols/webadmin/webadmin-data/src/main/java/org/apache/james/webadmin/routes/DomainsRoutes.java
index 6b6fb9a..0864a8a 100644
--- a/server/protocols/webadmin/webadmin-data/src/main/java/org/apache/james/webadmin/routes/DomainsRoutes.java
+++ b/server/protocols/webadmin/webadmin-data/src/main/java/org/apache/james/webadmin/routes/DomainsRoutes.java
@@ -22,6 +22,7 @@ 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;
@@ -33,7 +34,15 @@ 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.ErrorResponder;
+import org.apache.james.webadmin.utils.ErrorResponder.ErrorType;
 import org.apache.james.webadmin.utils.JsonTransformer;
+import org.eclipse.jetty.http.HttpStatus;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Preconditions;
+import com.google.common.base.Strings;
 
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiImplicitParam;
@@ -41,12 +50,6 @@ 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 com.google.common.base.Preconditions;
-import com.google.common.base.Strings;
-
 import spark.Request;
 import spark.Response;
 import spark.Service;
@@ -160,15 +163,26 @@ public class DomainsRoutes implements Routes {
     }
 
     private String addDomain(Request request, Response response) {
+        String domainName = request.params(DOMAIN_NAME);
         try {
-            addDomain(request.params(DOMAIN_NAME));
+            addDomain(domainName);
             response.status(204);
         } catch (DomainListException e) {
-            LOGGER.info("{} already exists", request.params(DOMAIN_NAME));
-            response.status(204);
+            LOGGER.info("{} already exists", domainName);
+            throw ErrorResponder.builder()
+                .statusCode(HttpStatus.NO_CONTENT_204)
+                .type(ErrorType.INVALID_ARGUMENT)
+                .message(domainName + " already exists")
+                .cause(e)
+                .haltError();
         } catch (IllegalArgumentException e) {
             LOGGER.info("Invalid request for domain creation");
-            response.status(400);
+            throw ErrorResponder.builder()
+                .statusCode(HttpStatus.BAD_REQUEST_400)
+                .type(ErrorType.INVALID_ARGUMENT)
+                .message("Invalid request for domain creation " + domainName)
+                .cause(e)
+                .haltError();
         }
         return Constants.EMPTY_BODY;
     }
@@ -181,8 +195,13 @@ public class DomainsRoutes implements Routes {
     }
 
     private String exists(Request request, Response response) throws DomainListException {
-        if (!domainList.containsDomain(request.params(DOMAIN_NAME))) {
-            response.status(404);
+        String domainName = request.params(DOMAIN_NAME);
+        if (!domainList.containsDomain(domainName)) {
+            throw ErrorResponder.builder()
+                .statusCode(HttpStatus.NOT_FOUND_404)
+                .type(ErrorType.INVALID_ARGUMENT)
+                .message("The domain list does not contain: " + domainName)
+                .haltError();
         } else {
             response.status(204);
         }

http://git-wip-us.apache.org/repos/asf/james-project/blob/bde6bdb7/server/protocols/webadmin/webadmin-data/src/main/java/org/apache/james/webadmin/routes/GroupsRoutes.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/webadmin-data/src/main/java/org/apache/james/webadmin/routes/GroupsRoutes.java b/server/protocols/webadmin/webadmin-data/src/main/java/org/apache/james/webadmin/routes/GroupsRoutes.java
index 288a03b..b2c6399 100644
--- a/server/protocols/webadmin/webadmin-data/src/main/java/org/apache/james/webadmin/routes/GroupsRoutes.java
+++ b/server/protocols/webadmin/webadmin-data/src/main/java/org/apache/james/webadmin/routes/GroupsRoutes.java
@@ -49,6 +49,8 @@ import org.apache.james.user.api.UsersRepositoryException;
 import org.apache.james.util.streams.Iterators;
 import org.apache.james.webadmin.Constants;
 import org.apache.james.webadmin.Routes;
+import org.apache.james.webadmin.utils.ErrorResponder;
+import org.apache.james.webadmin.utils.ErrorResponder.ErrorType;
 import org.apache.james.webadmin.utils.JsonExtractException;
 import org.apache.james.webadmin.utils.JsonTransformer;
 import org.eclipse.jetty.http.HttpStatus;
@@ -158,13 +160,21 @@ public class GroupsRoutes implements Routes {
 
     private void ensureRegisteredDomain(String domain) throws DomainListException {
         if (!domainList.containsDomain(domain)) {
-            throw halt(HttpStatus.FORBIDDEN_403);
+            throw ErrorResponder.builder()
+                .statusCode(HttpStatus.FORBIDDEN_403)
+                .type(ErrorType.INVALID_ARGUMENT)
+                .message("Server doesn't own the domain: " + domain)
+                .haltError();
         }
     }
 
     private void ensureNotShadowingAnotherAddress(MailAddress groupAddress) throws UsersRepositoryException {
         if (usersRepository.contains(groupAddress.asString())) {
-            throw halt(HttpStatus.CONFLICT_409);
+            throw ErrorResponder.builder()
+                .statusCode(HttpStatus.CONFLICT_409)
+                .type(ErrorType.INVALID_ARGUMENT)
+                .message("Requested group address is already used for another purpose")
+                .haltError();
         }
     }
 
@@ -217,16 +227,30 @@ public class GroupsRoutes implements Routes {
             String decodedAddress = URLDecoder.decode(address, "UTF-8");
             return new MailAddress(decodedAddress);
         } catch (AddressException e) {
-            throw halt(HttpStatus.BAD_REQUEST_400);
+            throw ErrorResponder.builder()
+                .statusCode(HttpStatus.BAD_REQUEST_400)
+                .type(ErrorType.INVALID_ARGUMENT)
+                .message("The group is not an email address")
+                .cause(e)
+                .haltError();
         } catch (UnsupportedEncodingException e) {
             LOGGER.error("UTF-8 should be a valid encoding");
-            throw halt(HttpStatus.INTERNAL_SERVER_ERROR_500);
+            throw ErrorResponder.builder()
+                .statusCode(HttpStatus.INTERNAL_SERVER_ERROR_500)
+                .type(ErrorType.SERVER_ERROR)
+                .message("Internal server error - Something went bad on the server side.")
+                .cause(e)
+                .haltError();
         }
     }
 
     private void ensureNonEmptyMappings(Mappings mappings) {
         if (mappings == null || mappings.isEmpty()) {
-            throw halt(HttpStatus.NOT_FOUND_404);
+            throw ErrorResponder.builder()
+                .statusCode(HttpStatus.NOT_FOUND_404)
+                .type(ErrorType.INVALID_ARGUMENT)
+                .message("The group does not exist")
+                .haltError();
         }
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/bde6bdb7/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 9c73542..e540d96 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
@@ -34,9 +34,14 @@ 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.ErrorResponder;
+import org.apache.james.webadmin.utils.ErrorResponder.ErrorType;
 import org.apache.james.webadmin.utils.JsonExtractException;
 import org.apache.james.webadmin.utils.JsonExtractor;
 import org.apache.james.webadmin.utils.JsonTransformer;
+import org.eclipse.jetty.http.HttpStatus;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiImplicitParam;
@@ -44,9 +49,6 @@ 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.Request;
 import spark.Response;
 import spark.Service;
@@ -135,12 +137,20 @@ public class UserRoutes implements Routes {
             response.status(204);
             return Constants.EMPTY_BODY;
         } catch (UsersRepositoryException e) {
-            response.status(204);
-            return "The user " + username + " does not exists";
+            throw ErrorResponder.builder()
+                .statusCode(HttpStatus.NO_CONTENT_204)
+                .type(ErrorType.INVALID_ARGUMENT)
+                .message("The user " + username + " does not exists")
+                .cause(e)
+                .haltError();
         } catch (IllegalArgumentException e) {
             LOGGER.info("Invalid user path", e);
-            response.status(400);
-            return Constants.EMPTY_BODY;
+            throw ErrorResponder.builder()
+                .statusCode(HttpStatus.BAD_REQUEST_400)
+                .type(ErrorType.INVALID_ARGUMENT)
+                .message("Invalid user path")
+                .cause(e)
+                .haltError();
         }
     }
 
@@ -151,12 +161,20 @@ public class UserRoutes implements Routes {
                 response);
         } catch (JsonExtractException e) {
             LOGGER.info("Error while deserializing addUser request", e);
-            response.status(400);
-            return Constants.EMPTY_BODY;
+            throw ErrorResponder.builder()
+                .statusCode(HttpStatus.BAD_REQUEST_400)
+                .type(ErrorType.INVALID_ARGUMENT)
+                .message("Error while deserializing addUser request")
+                .cause(e)
+                .haltError();
         } catch (IllegalArgumentException e) {
             LOGGER.info("Invalid user path", e);
-            response.status(400);
-            return Constants.EMPTY_BODY;
+            throw ErrorResponder.builder()
+                .statusCode(HttpStatus.BAD_REQUEST_400)
+                .type(ErrorType.INVALID_ARGUMENT)
+                .message("Invalid user path")
+                .cause(e)
+                .haltError();
         }
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/bde6bdb7/server/protocols/webadmin/webadmin-data/src/test/java/org/apache/james/webadmin/routes/DomainsRoutesTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/webadmin-data/src/test/java/org/apache/james/webadmin/routes/DomainsRoutesTest.java b/server/protocols/webadmin/webadmin-data/src/test/java/org/apache/james/webadmin/routes/DomainsRoutesTest.java
index 5e825e8..a403b5c 100644
--- a/server/protocols/webadmin/webadmin-data/src/test/java/org/apache/james/webadmin/routes/DomainsRoutesTest.java
+++ b/server/protocols/webadmin/webadmin-data/src/test/java/org/apache/james/webadmin/routes/DomainsRoutesTest.java
@@ -27,6 +27,8 @@ import static com.jayway.restassured.config.RestAssuredConfig.newConfig;
 import static org.apache.james.webadmin.Constants.SEPARATOR;
 import static org.apache.james.webadmin.WebAdminServer.NO_CONFIGURATION;
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.startsWith;
 import static org.mockito.Matchers.any;
 import static org.mockito.Mockito.doThrow;
 import static org.mockito.Mockito.mock;
@@ -35,6 +37,7 @@ import static org.mockito.Mockito.when;
 import java.net.InetAddress;
 import java.nio.charset.StandardCharsets;
 import java.util.List;
+import java.util.Map;
 
 import org.apache.james.dnsservice.api.DNSService;
 import org.apache.james.domainlist.api.DomainList;
@@ -157,10 +160,20 @@ public class DomainsRoutesTest {
 
         @Test
         public void putShouldReturnUserErrorWhenNameContainsAT() {
-            when()
+            Map<String, Object> errors = when()
                 .put(DOMAIN + "@" + DOMAIN)
             .then()
-                .statusCode(400);
+                .statusCode(400)
+                .contentType(ContentType.JSON)
+                .extract()
+                .body()
+                .jsonPath()
+                .getMap(".");
+
+            assertThat(errors)
+                .containsEntry("statusCode", 400)
+                .containsEntry("type", "InvalidArgument")
+                .containsEntry("message", "Invalid request for domain creation domain@domain");
         }
 
         @Test
@@ -173,12 +186,21 @@ public class DomainsRoutesTest {
 
         @Test
         public void putShouldReturnUserErrorWhenNameIsTooLong() {
-            when()
+            Map<String, Object> errors = when()
                 .put(DOMAIN + "0123456789.0123456789.0123456789.0123456789.0123456789.0123456789.0123456789.0123456789.0123456789.0123456789." +
                     "0123456789.0123456789.0123456789.0123456789.0123456789.0123456789.0123456789.0123456789.0123456789.0123456789." +
                     "0123456789.0123456789.0123456789.")
             .then()
-                .statusCode(400);
+                .statusCode(400)
+                .contentType(ContentType.JSON)
+                .extract()
+                .body()
+                .jsonPath()
+                .getMap(".");
+
+            assertThat(errors)
+                .containsEntry("statusCode", 400)
+                .containsEntry("type", "InvalidArgument");
         }
 
         @Test

http://git-wip-us.apache.org/repos/asf/james-project/blob/bde6bdb7/server/protocols/webadmin/webadmin-data/src/test/java/org/apache/james/webadmin/routes/GroupsRoutesTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/webadmin-data/src/test/java/org/apache/james/webadmin/routes/GroupsRoutesTest.java b/server/protocols/webadmin/webadmin-data/src/test/java/org/apache/james/webadmin/routes/GroupsRoutesTest.java
index 24ace5c..ff357e8 100644
--- a/server/protocols/webadmin/webadmin-data/src/test/java/org/apache/james/webadmin/routes/GroupsRoutesTest.java
+++ b/server/protocols/webadmin/webadmin-data/src/test/java/org/apache/james/webadmin/routes/GroupsRoutesTest.java
@@ -26,6 +26,7 @@ import static com.jayway.restassured.config.RestAssuredConfig.newConfig;
 import static org.apache.james.webadmin.Constants.SEPARATOR;
 import static org.apache.james.webadmin.WebAdminServer.NO_CONFIGURATION;
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.hamcrest.CoreMatchers.containsString;
 import static org.hamcrest.CoreMatchers.is;
 import static org.mockito.Matchers.anyString;
 import static org.mockito.Mockito.doThrow;
@@ -33,6 +34,7 @@ import static org.mockito.Mockito.mock;
 
 import java.nio.charset.StandardCharsets;
 import java.util.List;
+import java.util.Map;
 
 import org.apache.james.dnsservice.api.DNSService;
 import org.apache.james.domainlist.api.DomainList;
@@ -59,6 +61,7 @@ import com.jayway.restassured.RestAssured;
 import com.jayway.restassured.builder.RequestSpecBuilder;
 import com.jayway.restassured.filter.log.LogDetail;
 import com.jayway.restassured.http.ContentType;
+
 import de.bechte.junit.runners.context.HierarchicalContextRunner;
 
 @RunWith(HierarchicalContextRunner.class)
@@ -148,10 +151,20 @@ public class GroupsRoutesTest {
 
         @Test
         public void getUnregisteredGroupShouldReturnNotFound() {
-            when()
+            Map<String, Object> errors = when()
                 .get("unknown@domain.travel")
             .then()
-                .statusCode(HttpStatus.NOT_FOUND_404);
+                .statusCode(HttpStatus.NOT_FOUND_404)
+                .contentType(ContentType.JSON)
+                .extract()
+                .body()
+                .jsonPath()
+                .getMap(".");
+
+            assertThat(errors)
+                .containsEntry("statusCode", 404)
+                .containsEntry("type", "InvalidArgument")
+                .containsEntry("message", "The group does not exist");
         }
 
         @Test
@@ -276,11 +289,20 @@ public class GroupsRoutesTest {
 
         @Test
         public void putUserInGroupShouldNotAllowGroupOnUnregisteredDomain() throws UsersRepositoryException, DomainListException {
-            when()
+            Map<String, Object> errors = when()
                 .put("group@unregisteredDomain" + SEPARATOR + USER_A)
             .then()
+                .statusCode(HttpStatus.FORBIDDEN_403)
                 .contentType(ContentType.JSON)
-                .statusCode(HttpStatus.FORBIDDEN_403);
+                .extract()
+                .body()
+                .jsonPath()
+                .getMap(".");
+
+            assertThat(errors)
+                .containsEntry("statusCode", 403)
+                .containsEntry("type", "InvalidArgument")
+                .containsEntry("message", "Server doesn't own the domain: unregisteredDomain");
         }
 
 
@@ -288,11 +310,20 @@ public class GroupsRoutesTest {
         public void putUserInGroupShouldNotAllowUserShadowing() throws UsersRepositoryException, DomainListException {
             usersRepository.addUser(USER_A, "whatever");
 
-            when()
+            Map<String, Object> errors = when()
                 .put(USER_A + SEPARATOR + USER_B)
             .then()
+                .statusCode(HttpStatus.CONFLICT_409)
                 .contentType(ContentType.JSON)
-                .statusCode(HttpStatus.CONFLICT_409);
+                .extract()
+                .body()
+                .jsonPath()
+                .getMap(".");
+
+            assertThat(errors)
+                .containsEntry("statusCode", 409)
+                .containsEntry("type", "InvalidArgument")
+                .containsEntry("message", "Requested group address is already used for another purpose");
         }
 
         @Test
@@ -370,18 +401,40 @@ public class GroupsRoutesTest {
 
         @Test
         public void getMalformedGroupShouldReturnBadRequest() {
-            when()
+            Map<String, Object> errors = when()
                 .get("not-an-address")
             .then()
-                .statusCode(HttpStatus.BAD_REQUEST_400);
+                .statusCode(HttpStatus.BAD_REQUEST_400)
+                .contentType(ContentType.JSON)
+                .extract()
+                .body()
+                .jsonPath()
+                .getMap(".");
+
+            assertThat(errors)
+                .containsEntry("statusCode", 400)
+                .containsEntry("type", "InvalidArgument")
+                .containsEntry("message", "The group is not an email address")
+                .containsEntry("cause", "Out of data at position 1 in 'not-an-address'");
         }
 
         @Test
         public void putMalformedGroupShouldReturnBadRequest() {
-            when()
+            Map<String, Object> errors = when()
                 .put("not-an-address" + SEPARATOR + USER_A)
             .then()
-                .statusCode(HttpStatus.BAD_REQUEST_400);
+                .statusCode(HttpStatus.BAD_REQUEST_400)
+                .contentType(ContentType.JSON)
+                .extract()
+                .body()
+                .jsonPath()
+                .getMap(".");
+
+            assertThat(errors)
+                .containsEntry("statusCode", 400)
+                .containsEntry("type", "InvalidArgument")
+                .containsEntry("message", "The group is not an email address")
+                .containsEntry("cause", "Out of data at position 1 in 'not-an-address'");
         }
 
         @Test
@@ -389,7 +442,8 @@ public class GroupsRoutesTest {
             when()
                 .put(GROUP_WITH_SLASH + SEPARATOR + USER_A)
             .then()
-                .statusCode(HttpStatus.NOT_FOUND_404);
+                .statusCode(HttpStatus.NOT_FOUND_404)
+                .body(containsString("404 Not found"));
         }
 
         @Test
@@ -397,15 +451,27 @@ public class GroupsRoutesTest {
             when()
                 .put(GROUP1 + SEPARATOR + USER_WITH_SLASH)
             .then()
-                .statusCode(HttpStatus.NOT_FOUND_404);
+                .statusCode(HttpStatus.NOT_FOUND_404)
+                .body(containsString("404 Not found"));
         }
 
         @Test
         public void putMalformedAddressShouldReturnBadRequest() {
-            when()
+            Map<String, Object> errors = when()
                 .put(GROUP1 + SEPARATOR + "not-an-address")
             .then()
-                .statusCode(HttpStatus.BAD_REQUEST_400);
+                .statusCode(HttpStatus.BAD_REQUEST_400)
+                .contentType(ContentType.JSON)
+                .extract()
+                .body()
+                .jsonPath()
+                .getMap(".");
+
+            assertThat(errors)
+                .containsEntry("statusCode", 400)
+                .containsEntry("type", "InvalidArgument")
+                .containsEntry("message", "The group is not an email address")
+                .containsEntry("cause", "Out of data at position 1 in 'not-an-address'");
         }
 
         @Test
@@ -413,23 +479,46 @@ public class GroupsRoutesTest {
             when()
                 .put(GROUP1)
             .then()
-                .statusCode(HttpStatus.BAD_REQUEST_400);
+                .statusCode(HttpStatus.BAD_REQUEST_400)
+                .body(is(""));
         }
 
         @Test
         public void deleteMalformedGroupShouldReturnBadRequest() {
-            when()
+            Map<String, Object> errors = when()
                 .delete("not-an-address" + SEPARATOR + USER_A)
             .then()
-                .statusCode(HttpStatus.BAD_REQUEST_400);
+                .statusCode(HttpStatus.BAD_REQUEST_400)
+                .contentType(ContentType.JSON)
+                .extract()
+                .body()
+                .jsonPath()
+                .getMap(".");
+
+            assertThat(errors)
+                .containsEntry("statusCode", 400)
+                .containsEntry("type", "InvalidArgument")
+                .containsEntry("message", "The group is not an email address")
+                .containsEntry("cause", "Out of data at position 1 in 'not-an-address'");
         }
 
         @Test
         public void deleteMalformedAddressShouldReturnBadRequest() {
-            when()
+            Map<String, Object> errors = when()
                 .delete(GROUP1 + SEPARATOR + "not-an-address")
             .then()
-                .statusCode(HttpStatus.BAD_REQUEST_400);
+                .statusCode(HttpStatus.BAD_REQUEST_400)
+                .contentType(ContentType.JSON)
+                .extract()
+                .body()
+                .jsonPath()
+                .getMap(".");
+
+            assertThat(errors)
+                .containsEntry("statusCode", 400)
+                .containsEntry("type", "InvalidArgument")
+                .containsEntry("message", "The group is not an email address")
+                .containsEntry("cause", "Out of data at position 1 in 'not-an-address'");
         }
 
         @Test
@@ -437,7 +526,8 @@ public class GroupsRoutesTest {
             when()
                 .delete(GROUP1)
             .then()
-                .statusCode(HttpStatus.BAD_REQUEST_400);
+                .statusCode(HttpStatus.BAD_REQUEST_400)
+                .body(is(""));
         }
 
         @Test
@@ -449,7 +539,8 @@ public class GroupsRoutesTest {
             when()
                 .put(GROUP1 + SEPARATOR + GROUP2)
             .then()
-                .statusCode(HttpStatus.INTERNAL_SERVER_ERROR_500);
+                .statusCode(HttpStatus.INTERNAL_SERVER_ERROR_500)
+                .body(containsString("500 Internal Server Error"));
         }
 
         @Test
@@ -461,7 +552,8 @@ public class GroupsRoutesTest {
             when()
                 .put(GROUP1 + SEPARATOR + GROUP2)
             .then()
-                .statusCode(HttpStatus.INTERNAL_SERVER_ERROR_500);
+                .statusCode(HttpStatus.INTERNAL_SERVER_ERROR_500)
+                .body(containsString("500 Internal Server Error"));
         }
 
         @Test
@@ -473,7 +565,8 @@ public class GroupsRoutesTest {
             when()
                 .put(GROUP1 + SEPARATOR + GROUP2)
             .then()
-                .statusCode(HttpStatus.INTERNAL_SERVER_ERROR_500);
+                .statusCode(HttpStatus.INTERNAL_SERVER_ERROR_500)
+                .body(containsString("500 Internal Server Error"));
         }
 
         @Test
@@ -485,7 +578,8 @@ public class GroupsRoutesTest {
             when()
                 .get()
             .then()
-                .statusCode(HttpStatus.INTERNAL_SERVER_ERROR_500);
+                .statusCode(HttpStatus.INTERNAL_SERVER_ERROR_500)
+                .body(containsString("500 Internal Server Error"));
         }
 
         @Test
@@ -497,7 +591,8 @@ public class GroupsRoutesTest {
             when()
                 .get()
             .then()
-                .statusCode(HttpStatus.INTERNAL_SERVER_ERROR_500);
+                .statusCode(HttpStatus.INTERNAL_SERVER_ERROR_500)
+                .body(containsString("500 Internal Server Error"));
         }
 
         @Test
@@ -509,7 +604,8 @@ public class GroupsRoutesTest {
             when()
                 .get()
             .then()
-                .statusCode(HttpStatus.INTERNAL_SERVER_ERROR_500);
+                .statusCode(HttpStatus.INTERNAL_SERVER_ERROR_500)
+                .body(containsString("500 Internal Server Error"));
         }
 
         @Test
@@ -521,7 +617,8 @@ public class GroupsRoutesTest {
             when()
                 .delete(GROUP1 + SEPARATOR + GROUP2)
             .then()
-                .statusCode(HttpStatus.INTERNAL_SERVER_ERROR_500);
+                .statusCode(HttpStatus.INTERNAL_SERVER_ERROR_500)
+                .body(containsString("500 Internal Server Error"));
         }
 
         @Test
@@ -533,7 +630,8 @@ public class GroupsRoutesTest {
             when()
                 .delete(GROUP1 + SEPARATOR + GROUP2)
             .then()
-                .statusCode(HttpStatus.INTERNAL_SERVER_ERROR_500);
+                .statusCode(HttpStatus.INTERNAL_SERVER_ERROR_500)
+                .body(containsString("500 Internal Server Error"));
         }
 
         @Test
@@ -545,7 +643,8 @@ public class GroupsRoutesTest {
             when()
                 .delete(GROUP1 + SEPARATOR + GROUP2)
             .then()
-                .statusCode(HttpStatus.INTERNAL_SERVER_ERROR_500);
+                .statusCode(HttpStatus.INTERNAL_SERVER_ERROR_500)
+                .body(containsString("500 Internal Server Error"));
         }
 
         @Test
@@ -557,7 +656,8 @@ public class GroupsRoutesTest {
             when()
                 .get(GROUP1)
             .then()
-                .statusCode(HttpStatus.INTERNAL_SERVER_ERROR_500);
+                .statusCode(HttpStatus.INTERNAL_SERVER_ERROR_500)
+                .body(containsString("500 Internal Server Error"));
         }
 
         @Test
@@ -569,7 +669,8 @@ public class GroupsRoutesTest {
             when()
                 .get(GROUP1)
             .then()
-                .statusCode(HttpStatus.INTERNAL_SERVER_ERROR_500);
+                .statusCode(HttpStatus.INTERNAL_SERVER_ERROR_500)
+                .body(containsString("500 Internal Server Error"));
         }
 
         @Test
@@ -581,7 +682,8 @@ public class GroupsRoutesTest {
             when()
                 .get(GROUP1)
             .then()
-                .statusCode(HttpStatus.INTERNAL_SERVER_ERROR_500);
+                .statusCode(HttpStatus.INTERNAL_SERVER_ERROR_500)
+                .body(containsString("500 Internal Server Error"));
         }
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/bde6bdb7/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 a8f7e62..a45bff2 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
@@ -19,6 +19,8 @@
 
 package org.apache.james.webadmin.routes;
 
+import static spark.Spark.halt;
+
 import javax.inject.Inject;
 import javax.ws.rs.DELETE;
 import javax.ws.rs.GET;
@@ -32,9 +34,14 @@ import org.apache.james.webadmin.Constants;
 import org.apache.james.webadmin.Routes;
 import org.apache.james.webadmin.dto.QuotaDTO;
 import org.apache.james.webadmin.dto.QuotaRequest;
+import org.apache.james.webadmin.utils.ErrorResponder;
+import org.apache.james.webadmin.utils.ErrorResponder.ErrorType;
 import org.apache.james.webadmin.utils.JsonExtractException;
 import org.apache.james.webadmin.utils.JsonExtractor;
 import org.apache.james.webadmin.utils.JsonTransformer;
+import org.eclipse.jetty.http.HttpStatus;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiImplicitParam;
@@ -42,8 +49,6 @@ 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")
@@ -108,10 +113,20 @@ public class GlobalQuotaRoutes implements Routes {
                 response.status(204);
             } catch (JsonExtractException e) {
                 LOGGER.info("Malformed JSON", e);
-                response.status(400);
+                throw ErrorResponder.builder()
+                    .statusCode(HttpStatus.BAD_REQUEST_400)
+                    .type(ErrorType.INVALID_ARGUMENT)
+                    .message("Malformed JSON input")
+                    .cause(e)
+                    .haltError();
             } catch (IllegalArgumentException e) {
                 LOGGER.info("Quota should be positive or unlimited (-1)", e);
-                response.status(400);
+                throw ErrorResponder.builder()
+                    .statusCode(HttpStatus.BAD_REQUEST_400)
+                    .type(ErrorType.INVALID_ARGUMENT)
+                    .message("Quota should be positive or unlimited (-1)")
+                    .cause(e)
+                    .haltError();
             }
             return Constants.EMPTY_BODY;
         }));
@@ -170,7 +185,12 @@ public class GlobalQuotaRoutes implements Routes {
                 response.status(204);
             } catch (IllegalArgumentException e) {
                 LOGGER.info("Invalid quota. Need to be an integer value greater than 0");
-                response.status(400);
+                throw ErrorResponder.builder()
+                    .statusCode(HttpStatus.BAD_REQUEST_400)
+                    .type(ErrorType.INVALID_ARGUMENT)
+                    .message("Invalid quota. Need to be an integer value greater than 0")
+                    .cause(e)
+                    .haltError();
             }
             return Constants.EMPTY_BODY;
         });
@@ -225,7 +245,12 @@ public class GlobalQuotaRoutes implements Routes {
                 response.status(204);
             } catch (IllegalArgumentException e) {
                 LOGGER.info("Invalid quota. Need to be an integer value greater than 0");
-                response.status(400);
+                throw ErrorResponder.builder()
+                    .statusCode(HttpStatus.BAD_REQUEST_400)
+                    .type(ErrorType.INVALID_ARGUMENT)
+                    .message("Invalid quota. Need to be an integer value greater than 0")
+                    .cause(e)
+                    .haltError();
             }
             return Constants.EMPTY_BODY;
         });

http://git-wip-us.apache.org/repos/asf/james-project/blob/bde6bdb7/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 1b218f5..2867c20 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
@@ -29,9 +29,14 @@ import javax.ws.rs.Produces;
 import org.apache.james.webadmin.Constants;
 import org.apache.james.webadmin.Routes;
 import org.apache.james.webadmin.service.UserMailboxesService;
+import org.apache.james.webadmin.utils.ErrorResponder;
+import org.apache.james.webadmin.utils.ErrorResponder.ErrorType;
 import org.apache.james.webadmin.utils.JsonTransformer;
 import org.apache.james.webadmin.utils.MailboxHaveChildrenException;
 import org.apache.james.webadmin.validation.MailboxName;
+import org.eclipse.jetty.http.HttpStatus;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiImplicitParam;
@@ -39,8 +44,6 @@ 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")
@@ -100,8 +103,12 @@ public class UserMailboxesRoutes implements Routes {
                 return userMailboxesService.listMailboxes(request.params(USER_NAME));
             } catch (IllegalStateException e) {
                 LOGGER.info("Invalid get on user mailboxes", e);
-                response.status(404);
-                return Constants.EMPTY_BODY;
+                throw ErrorResponder.builder()
+                    .statusCode(HttpStatus.NOT_FOUND_404)
+                    .type(ErrorType.INVALID_ARGUMENT)
+                    .message("Invalid get on user mailboxes")
+                    .cause(e)
+                    .haltError();
             }
         }, jsonTransformer);
     }
@@ -127,13 +134,28 @@ public class UserMailboxesRoutes implements Routes {
                 response.status(204);
             } catch (IllegalStateException e) {
                 LOGGER.info("Invalid delete on user mailbox", e);
-                response.status(404);
+                throw ErrorResponder.builder()
+                    .statusCode(HttpStatus.NOT_FOUND_404)
+                    .type(ErrorType.INVALID_ARGUMENT)
+                    .message("Invalid delete on user mailboxes")
+                    .cause(e)
+                    .haltError();
             } catch (MailboxHaveChildrenException e) {
                 LOGGER.info("Attempt to delete a mailbox with children");
-                response.status(409);
+                throw ErrorResponder.builder()
+                    .statusCode(HttpStatus.CONFLICT_409)
+                    .type(ErrorType.INVALID_ARGUMENT)
+                    .message("Attempt to delete a mailbox with children")
+                    .cause(e)
+                    .haltError();
             } catch (IllegalArgumentException e) {
                 LOGGER.info("Attempt to create an invalid mailbox");
-                response.status(400);
+                throw ErrorResponder.builder()
+                    .statusCode(HttpStatus.BAD_REQUEST_400)
+                    .type(ErrorType.INVALID_ARGUMENT)
+                    .message("Attempt to create an invalid mailbox")
+                    .cause(e)
+                    .haltError();
             }
             return Constants.EMPTY_BODY;
         });
@@ -157,7 +179,12 @@ public class UserMailboxesRoutes implements Routes {
                 response.status(204);
             } catch (IllegalStateException e) {
                 LOGGER.info("Invalid delete on user mailboxes", e);
-                response.status(404);
+                throw ErrorResponder.builder()
+                    .statusCode(HttpStatus.NOT_FOUND_404)
+                    .type(ErrorType.INVALID_ARGUMENT)
+                    .message("Invalid delete on user mailboxes")
+                    .cause(e)
+                    .haltError();
             }
             return Constants.EMPTY_BODY;
         });
@@ -183,14 +210,28 @@ public class UserMailboxesRoutes implements Routes {
                 if (userMailboxesService.testMailboxExists(request.params(USER_NAME), new MailboxName(request.params(MAILBOX_NAME)))) {
                     response.status(204);
                 } else {
-                    response.status(404);
+                    throw ErrorResponder.builder()
+                        .statusCode(HttpStatus.NOT_FOUND_404)
+                        .type(ErrorType.INVALID_ARGUMENT)
+                        .message("Invalid get on user mailboxes")
+                        .haltError();
                 }
             } catch (IllegalStateException e) {
                 LOGGER.info("Invalid get on user mailbox", e);
-                response.status(404);
+                throw ErrorResponder.builder()
+                    .statusCode(HttpStatus.NOT_FOUND_404)
+                    .type(ErrorType.INVALID_ARGUMENT)
+                    .message("Invalid get on user mailboxes")
+                    .cause(e)
+                    .haltError();
             } catch (IllegalArgumentException e) {
                 LOGGER.info("Attempt to create an invalid mailbox");
-                response.status(400);
+                throw ErrorResponder.builder()
+                    .statusCode(HttpStatus.BAD_REQUEST_400)
+                    .type(ErrorType.INVALID_ARGUMENT)
+                    .message("Attempt to create an invalid mailbox")
+                    .cause(e)
+                    .haltError();
             }
             return Constants.EMPTY_BODY;
         });
@@ -217,10 +258,20 @@ public class UserMailboxesRoutes implements Routes {
                 response.status(204);
             } catch (IllegalStateException e) {
                 LOGGER.info("Invalid put on user mailbox", e);
-                response.status(404);
+                throw ErrorResponder.builder()
+                    .statusCode(HttpStatus.NOT_FOUND_404)
+                    .type(ErrorType.INVALID_ARGUMENT)
+                    .message("Invalid get on user mailboxes")
+                    .cause(e)
+                    .haltError();
             } catch (IllegalArgumentException e) {
                 LOGGER.info("Attempt to create an invalid mailbox");
-                response.status(400);
+                throw ErrorResponder.builder()
+                    .statusCode(HttpStatus.BAD_REQUEST_400)
+                    .type(ErrorType.INVALID_ARGUMENT)
+                    .message("Attempt to create an invalid mailbox")
+                    .cause(e)
+                    .haltError();
             }
             return Constants.EMPTY_BODY;
         });

http://git-wip-us.apache.org/repos/asf/james-project/blob/bde6bdb7/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/GlobalQuotaRoutesTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/GlobalQuotaRoutesTest.java b/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/GlobalQuotaRoutesTest.java
index a1e3971..5f79edf 100644
--- a/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/GlobalQuotaRoutesTest.java
+++ b/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/GlobalQuotaRoutesTest.java
@@ -24,6 +24,9 @@ import static com.jayway.restassured.config.EncoderConfig.encoderConfig;
 import static com.jayway.restassured.config.RestAssuredConfig.newConfig;
 import static org.apache.james.webadmin.WebAdminServer.NO_CONFIGURATION;
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.hamcrest.CoreMatchers.is;
+
+import java.util.Map;
 
 import org.apache.james.mailbox.inmemory.quota.InMemoryPerUserMaxQuotaManager;
 import org.apache.james.mailbox.model.Quota;
@@ -101,20 +104,41 @@ public class GlobalQuotaRoutesTest {
 
     @Test
     public void putCountShouldRejectInvalid() throws Exception {
-        given()
+        Map<String, Object> errors = given()
             .body("invalid")
             .put(GlobalQuotaRoutes.COUNT_ENDPOINT)
         .then()
-            .statusCode(400);
+            .statusCode(400)
+            .contentType(ContentType.JSON)
+            .extract()
+            .body()
+            .jsonPath()
+            .getMap(".");
+
+        assertThat(errors)
+            .containsEntry("statusCode", 400)
+            .containsEntry("type", "InvalidArgument")
+            .containsEntry("message", "Invalid quota. Need to be an integer value greater than 0")
+            .containsEntry("cause", "For input string: \"invalid\"");
     }
 
     @Test
     public void putCountShouldRejectNegative() throws Exception {
-        given()
+        Map<String, Object> errors = given()
             .body("-1")
             .put(GlobalQuotaRoutes.COUNT_ENDPOINT)
         .then()
-            .statusCode(400);
+            .statusCode(400)
+            .contentType(ContentType.JSON)
+            .extract()
+            .body()
+            .jsonPath()
+            .getMap(".");
+
+        assertThat(errors)
+            .containsEntry("statusCode", 400)
+            .containsEntry("type", "InvalidArgument")
+            .containsEntry("message", "Invalid quota. Need to be an integer value greater than 0");
     }
 
     @Test
@@ -174,20 +198,41 @@ public class GlobalQuotaRoutesTest {
 
     @Test
     public void putSizeShouldRejectInvalid() throws Exception {
-        given()
+        Map<String, Object> errors = given()
             .body("invalid")
             .put(GlobalQuotaRoutes.SIZE_ENDPOINT)
         .then()
-            .statusCode(400);
+            .statusCode(400)
+            .contentType(ContentType.JSON)
+            .extract()
+            .body()
+            .jsonPath()
+            .getMap(".");
+
+        assertThat(errors)
+            .containsEntry("statusCode", 400)
+            .containsEntry("type", "InvalidArgument")
+            .containsEntry("message", "Invalid quota. Need to be an integer value greater than 0")
+            .containsEntry("cause", "For input string: \"invalid\"");
     }
 
     @Test
     public void putSizeShouldRejectNegative() throws Exception {
-        given()
+        Map<String, Object> errors = given()
             .body("-1")
             .put(GlobalQuotaRoutes.SIZE_ENDPOINT)
         .then()
-            .statusCode(400);
+            .statusCode(400)
+            .contentType(ContentType.JSON)
+            .extract()
+            .body()
+            .jsonPath()
+            .getMap(".");
+
+        assertThat(errors)
+            .containsEntry("statusCode", 400)
+            .containsEntry("type", "InvalidArgument")
+            .containsEntry("message", "Invalid quota. Need to be an integer value greater than 0");
     }
 
     @Test


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