1
0
mirror of https://github.com/sismics/docs.git synced 2025-12-17 19:51:39 +00:00

Closes #29: Upgrade to Jersey 2

This commit is contained in:
jendib
2015-09-07 21:51:13 +02:00
parent 97694d5d59
commit 0fe51d355c
44 changed files with 1643 additions and 2292 deletions

View File

@@ -1,11 +1,9 @@
package com.sismics.rest.exception;
import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.json.Json;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
@@ -32,9 +30,8 @@ public class ClientException extends WebApplicationException {
* @param type Error type (e.g. AlreadyExistingEmail, ValidationError)
* @param message Human readable error message
* @param e Readable error message
* @throws JSONException
*/
public ClientException(String type, String message, Exception e) throws JSONException {
public ClientException(String type, String message, Exception e) {
this(type, message);
log.error(type + ": " + message, e);
}
@@ -44,11 +41,10 @@ public class ClientException extends WebApplicationException {
*
* @param type Error type (e.g. AlreadyExistingEmail, ValidationError)
* @param message Human readable error message
* @throws JSONException
*/
public ClientException(String type, String message) throws JSONException {
super(Response.status(Status.BAD_REQUEST).entity(new JSONObject()
.put("type", type)
.put("message", message)).build());
public ClientException(String type, String message) {
super(Response.status(Status.BAD_REQUEST).entity(Json.createObjectBuilder()
.add("type", type)
.add("message", message).build()).build());
}
}

View File

@@ -1,8 +1,6 @@
package com.sismics.rest.exception;
import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;
import javax.json.Json;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
@@ -20,12 +18,10 @@ public class ForbiddenClientException extends WebApplicationException {
/**
* Constructor of ForbiddenClientException.
*
* @throws JSONException
*/
public ForbiddenClientException() throws JSONException {
super(Response.status(Status.FORBIDDEN).entity(new JSONObject()
.put("type", "ForbiddenError")
.put("message", "You don't have access to this resource")).build());
public ForbiddenClientException() {
super(Response.status(Status.FORBIDDEN).entity(Json.createObjectBuilder()
.add("type", "ForbiddenError")
.add("message", "You don't have access to this resource").build()).build());
}
}

View File

@@ -1,14 +1,13 @@
package com.sismics.rest.exception;
import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.json.Json;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Jersey exception encapsulating an error from the client (INTERNAL_SERVER_ERROR).
*
@@ -31,9 +30,8 @@ public class ServerException extends WebApplicationException {
* @param type Error type (e.g. DatabaseError)
* @param message Human readable error message
* @param e Inner exception
* @throws JSONException
*/
public ServerException(String type, String message, Exception e) throws JSONException {
public ServerException(String type, String message, Exception e) {
this(type, message);
log.error(type + ": " + message, e);
}
@@ -43,11 +41,10 @@ public class ServerException extends WebApplicationException {
*
* @param type Error type (e.g. DatabaseError)
* @param message Human readable error message
* @throws JSONException
*/
public ServerException(String type, String message) throws JSONException {
super(Response.status(Status.INTERNAL_SERVER_ERROR).entity(new JSONObject()
.put("type", type)
.put("message", message)).build());
public ServerException(String type, String message) {
super(Response.status(Status.INTERNAL_SERVER_ERROR).entity(Json.createObjectBuilder()
.add("type", type)
.add("message", message).build()).build());
}
}