use of org.webpieces.http.exception.Violation in project webpieces by deanhiller.
the class BeanValidator method validate.
public List<Violation> validate(Object controller, Method m, List<Object> args) {
Object[] params = args.toArray();
List<Violation> all = new ArrayList<>();
Set<ConstraintViolation<Object>> violations = execValidator.validateParameters(controller, m, params);
addAll(null, all, violations);
Parameter[] parameters = m.getParameters();
for (int i = 0; i < parameters.length; i++) {
Object arg = args.get(i);
if (arg != null) {
Parameter param = parameters[i];
String paramName = param.getName();
Set<ConstraintViolation<Object>> violations2 = validator.validate(arg);
addAll(paramName + ".", all, violations2);
}
}
return all;
}
use of org.webpieces.http.exception.Violation in project webpieces by deanhiller.
the class BeanValidator method addAll.
private void addAll(String prefix, List<Violation> all, Set<ConstraintViolation<Object>> violations) {
for (ConstraintViolation<Object> violation : violations) {
String path = getPathFun(prefix, violation);
all.add(new Violation(path, violation.getMessage()));
}
}
use of org.webpieces.http.exception.Violation in project webpieces by deanhiller.
the class SvcProxyForHtml method validate.
/**
* This validation covers THREE cases I know of
* controller method public Action postHibernateEntity(CustomerDbo customer) //hibernate plugin validation AFTER looking up in DB
* controller method public Action postDto(@Dto SomeDto dto) //dto plugin validation AFTER looking up from remote service
* controller method public Action postSomething(@NotBlank String username) //simple validation
*
* JSON or other content validation is done in SvcProxyForContent.java and throws BadClientRequestException so that translators
* can translate to generic error message sent to clients
*/
private List<Object> validate(Object controller, Method m, RequestContext requestContext, List<Object> args) {
if (requestContext.getRequest().method != HttpMethod.POST)
// ONLY validate on post requests
return args;
Validation validation = requestContext.getValidation();
List<Violation> violations = validator.validate(controller, m, args);
// Since this is web, just add errors to Validation object
for (Violation violation : violations) {
// add error to list of errors for form to display
validation.addError(violation.getPath(), violation.getMessage());
}
return args;
}
use of org.webpieces.http.exception.Violation in project webpieces by deanhiller.
the class JacksonCatchAllFilter method translateViolations.
protected String translateViolations(BadRequestException t, String defaultMessage) {
if (t.getViolations() == null || t.getViolations().size() == 0) {
return defaultMessage;
}
String failures = "Your request is bad. ";
int counter = 1;
for (Violation violation : t.getViolations()) {
failures += "Violation #" + counter + ":'" + violation.getMessage() + "' path=" + violation.getPath();
if (counter < t.getViolations().size()) {
failures += "****";
}
}
return failures;
}
Aggregations