ConstraintViolationException can contain mulitple violation messages

Signed-off-by: Melanie Retter <melanie.retter@bosch-si.com>
This commit is contained in:
Melanie Retter
2016-08-24 13:48:18 +02:00
parent 679f465db1
commit 50a86cdb7b
2 changed files with 8 additions and 7 deletions

View File

@@ -12,8 +12,8 @@ import org.eclipse.hawkbit.exception.AbstractServerRtException;
import org.eclipse.hawkbit.exception.SpServerError;
/**
* the {@link ConstraintViolationException} is thrown when an entity is
* tried to be saved which has constraint violations
* the {@link ConstraintViolationException} is thrown when an entity is tried to
* be saved which has constraint violations
*
*/
public class ConstraintViolationException extends AbstractServerRtException {

View File

@@ -13,6 +13,7 @@ import java.util.EnumMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import javax.servlet.http.HttpServletRequest;
import javax.validation.ConstraintViolation;
@@ -141,16 +142,16 @@ public class ResponseExceptionHandler {
final Exception ex) {
logRequest(request, ex);
final ExceptionInfo response = null;
final Set<ConstraintViolation<?>> violations = ((ConstraintViolationException) ex).getConstraintViolations();
final List<String> messages = new ArrayList<>();
violations.stream()
.forEach(violation -> messages.add(violation.getPropertyPath() + " " + violation.getMessage() + ". "));
.forEach(violation -> messages.add(violation.getPropertyPath() + " " + violation.getMessage() + "."));
final ExceptionInfo response = createExceptionInfo(
new org.eclipse.hawkbit.repository.exception.ConstraintViolationException(
messages.stream().collect(Collectors.joining(" "))));
// response = createExceptionInfo(new
// org.eclipse.hawkbit.repository.exception.ConstraintViolationException(
// messages.forEach(StringBuilder::append(this))));
return new ResponseEntity<>(response, HttpStatus.BAD_REQUEST);
}