public String getInfoHeaderValue(final String value) { // HTTP header values cannot contain CR / LF return (name() + ":" + value).replaceAll("(\\r|\\n)", " "); }
public String getInfoHeaderValue(final String value) { // HTTP header values cannot contain CR / LF return (name() + ":" + value).replaceAll("(\\r|\\n)", " "); }
public static ClientExceptionType fromHeaderValue(final String exceptionTypeHeaderValue) { ClientExceptionType result = null; for (ClientExceptionType type : values()) { if (exceptionTypeHeaderValue.equals(type.name())) { result = type; } } if (result == null) { throw new IllegalArgumentException("Unexpected header value: " + exceptionTypeHeaderValue); } return result; }
public static ClientExceptionType fromHeaderValue(final String exceptionTypeHeaderValue) { ClientExceptionType result = null; for (ClientExceptionType type : values()) { if (exceptionTypeHeaderValue.equals(type.name())) { result = type; } } if (result == null) { throw new IllegalArgumentException("Unexpected header value: " + exceptionTypeHeaderValue); } return result; }
private ResponseBuilder builder(final ClientExceptionType hType, final String msg) { ResponseBuilder builder = Response.status(hType.getResponseStatus()). header(RESTHeaders.ERROR_CODE, hType.name()). header(RESTHeaders.ERROR_INFO, hType.getInfoHeaderValue(msg)); ErrorTO error = new ErrorTO(); error.setStatus(hType.getResponseStatus().getStatusCode()); error.setType(hType); error.getElements().add(msg); return builder.entity(error); }
private ResponseBuilder getSyncopeClientCompositeExceptionResponse(final SyncopeClientCompositeException ex) { if (ex.getExceptions().size() == 1) { return getSyncopeClientExceptionResponse(ex.getExceptions().iterator().next()); } ResponseBuilder builder = Response.status(Response.Status.BAD_REQUEST); List<ErrorTO> errors = new ArrayList<>(); ex.getExceptions().stream().map(sce -> { builder.header(RESTHeaders.ERROR_CODE, sce.getType().name()); ErrorTO error = new ErrorTO(); error.setStatus(sce.getType().getResponseStatus().getStatusCode()); error.setType(sce.getType()); sce.getElements().forEach(element -> { builder.header(RESTHeaders.ERROR_INFO, sce.getType().getInfoHeaderValue(element)); error.getElements().add(element); }); return error; }).collect(Collectors.toList()); return builder.entity(errors); }
private ResponseBuilder getSyncopeClientExceptionResponse(final SyncopeClientException ex) { ResponseBuilder builder = Response.status(ex.getType().getResponseStatus()); builder.header(RESTHeaders.ERROR_CODE, ex.getType().name()); ErrorTO error = new ErrorTO(); error.setStatus(ex.getType().getResponseStatus().getStatusCode()); error.setType(ex.getType()); ex.getElements().forEach(element -> { builder.header(RESTHeaders.ERROR_INFO, ex.getType().getInfoHeaderValue(element)); error.getElements().add(element); }); return builder.entity(error); }
if (exInfos != null && !exInfos.isEmpty()) { for (String element : exInfos) { if (element.startsWith(exceptionType.name())) { clientException.getElements().add(StringUtils.substringAfter(element, ":"));
if (exInfos != null && !exInfos.isEmpty()) { for (String element : exInfos) { if (element.startsWith(exceptionType.name())) { clientException.getElements().add(StringUtils.substringAfter(element, ":"));
builder.header(RESTHeaders.ERROR_CODE, exType.name());
header(RESTHeaders.ERROR_CODE, ClientExceptionType.RESTValidation.name()). header(RESTHeaders.ERROR_INFO, ClientExceptionType.RESTValidation.getInfoHeaderValue( ExceptionUtils.getRootCauseMessage(ex)));