diff --git a/bpm/bonita-common/src/main/java/org/bonitasoft/engine/bpm/BaseRestElement.java b/bpm/bonita-common/src/main/java/org/bonitasoft/engine/bpm/BaseRestElement.java index bdc1aca201..e3ae5fe1a4 100644 --- a/bpm/bonita-common/src/main/java/org/bonitasoft/engine/bpm/BaseRestElement.java +++ b/bpm/bonita-common/src/main/java/org/bonitasoft/engine/bpm/BaseRestElement.java @@ -13,12 +13,14 @@ **/ package org.bonitasoft.engine.bpm; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; import com.fasterxml.jackson.databind.annotation.JsonSerialize; import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; /** * Interface BaseRestElement identifies a BonitaObject that can be used in the REST API. */ +@JsonPropertyOrder(alphabetic = true) public interface BaseRestElement extends BaseElement { /** diff --git a/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/api/AbstractRESTController.java b/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/api/AbstractRESTController.java index a492804048..9320958628 100644 --- a/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/api/AbstractRESTController.java +++ b/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/api/AbstractRESTController.java @@ -13,12 +13,16 @@ **/ package org.bonitasoft.web.rest.server.api; +import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; import lombok.extern.slf4j.Slf4j; import org.bonitasoft.console.common.server.utils.SessionUtil; import org.bonitasoft.engine.session.APISession; import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.ResponseStatus; +import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException; import org.springframework.web.server.ResponseStatusException; /** @@ -35,24 +39,11 @@ public APISession getApiSession(HttpSession session) { return apiSession; } - protected long getParameterAsLong(String parameterValue, String errorMessage) { - try { - return Long.parseLong(parameterValue); - } catch (NumberFormatException e) { - log.debug(errorMessage, e); - throw new ResponseStatusException(HttpStatus.BAD_REQUEST, - errorMessage); - } - } - - protected int getParameterAsInt(String parameterValue, String errorMessage) { - try { - return Integer.parseInt(parameterValue); - } catch (NumberFormatException e) { - log.debug(errorMessage, e); - throw new ResponseStatusException(HttpStatus.BAD_REQUEST, - errorMessage); - } + @ResponseStatus(value = HttpStatus.BAD_REQUEST, reason = "Bad request") + @ExceptionHandler(MethodArgumentTypeMismatchException.class) + public void handleBadRequestError(HttpServletRequest req, MethodArgumentTypeMismatchException ex) { + String error = "[" + req.getPathInfo() + "] " + ex.getName() + ": " + ex.getMessage(); + log.debug(error); } }