use of jakarta.validation.ConstraintViolationException in project resteasy by resteasy.
the class GeneralValidatorImpl method checkForConstraintViolations.
@Override
@SuppressWarnings({ "rawtypes", "unchecked" })
public void checkForConstraintViolations(HttpRequest request, Exception e) {
Throwable t = e;
while (t != null && !(t instanceof ConstraintViolationException)) {
t = t.getCause();
}
if (t instanceof ResteasyViolationException) {
throw ResteasyViolationException.class.cast(t);
}
if (t instanceof ConstraintViolationException) {
SimpleViolationsContainer violationsContainer = getViolationsContainer(request, null);
ConstraintViolationException cve = ConstraintViolationException.class.cast(t);
Set cvs = cve.getConstraintViolations();
violationsContainer.addViolations(cvs);
if (violationsContainer.size() > 0) {
throw new ResteasyViolationExceptionImpl(violationsContainer, request.getHttpHeaders().getAcceptableMediaTypes());
}
}
return;
}
use of jakarta.validation.ConstraintViolationException in project org.openntf.xsp.jakartaee by OpenNTF.
the class GenericThrowableMapper method createResponseFromException.
protected Response createResponseFromException(final Throwable throwable, final int status, ResourceInfo resourceInfo, HttpServletRequest req) {
MediaType type = getMediaType(resourceInfo);
if (MediaType.TEXT_HTML_TYPE.isCompatible(type)) {
// Handle as HTML
return Response.status(status).type(MediaType.TEXT_HTML_TYPE).entity((StreamingOutput) out -> {
try (PrintWriter w = new PrintWriter(new OutputStreamWriter(out, StandardCharsets.UTF_8))) {
XSPErrorPage.handleException(w, throwable, req.getRequestURL().toString(), false);
} catch (ServletException e) {
throw new IOException(e);
}
}).build();
} else {
// Handle as JSON
return Response.status(status).type(MediaType.APPLICATION_JSON_TYPE).entity((StreamingOutput) out -> {
Objects.requireNonNull(out);
String message = "";
Throwable t = throwable;
while ((message == null || message.length() == 0) && t != null) {
if (t instanceof NotesException) {
message = ((NotesException) t).text;
} else if (t instanceof ConstraintViolationException) {
message = t.getMessage();
if (message == null || message.isEmpty()) {
List<String> cvMsgList = new ArrayList<>();
for (@SuppressWarnings("rawtypes") ConstraintViolation cv : ((ConstraintViolationException) t).getConstraintViolations()) {
String cvMsg = cv.getPropertyPath() + ": " + cv.getMessage();
cvMsgList.add(cvMsg);
}
message = String.join(",", cvMsgList);
}
} else {
message = t.getMessage();
}
t = t.getCause();
}
JsonGeneratorFactory jsonFac = Json.createGeneratorFactory(Collections.singletonMap(JsonGenerator.PRETTY_PRINTING, true));
try (JsonGenerator json = jsonFac.createGenerator(out)) {
json.writeStartObject();
json.write("message", throwable.getClass().getName() + ": " + message);
json.writeKey("stackTrace");
json.writeStartArray();
for (Throwable cause = throwable; cause != null; cause = cause.getCause()) {
json.writeStartArray();
json.write(cause.getClass().getName() + ": " + cause.getLocalizedMessage());
Arrays.stream(cause.getStackTrace()).map(String::valueOf).map(line -> " at " + line).forEach(json::write);
json.writeEnd();
}
json.writeEnd();
json.writeEnd();
}
}).build();
}
}
use of jakarta.validation.ConstraintViolationException in project Clownfish by rawdog71.
the class JavaList method onCreate.
@Override
public void onCreate(ActionEvent actionEvent) {
try {
if (!javaName.isBlank()) {
CfJava newjava = new CfJava();
newjava.setName(javaName);
switch(javaLanguage) {
case 0:
newjava.setContent("package io.clownfish.java;\n\n" + "public class " + javaName + "\n{\n\n}");
break;
case 1:
newjava.setContent("package io.clownfish.kotlin;\n\n" + "public class " + javaName + "\n{\n\n}");
break;
case 2:
newjava.setContent("package io.clownfish.groovy;\n\n" + "public class " + javaName + "\n{\n\n}");
break;
case 3:
newjava.setContent("package io.clownfish.scala\n\n" + "class " + javaName + "\n{\n\n}");
break;
}
newjava.setLanguage(javaLanguage);
cfjavaService.create(newjava);
javaListe = cfjavaService.findAll();
javaName = "";
} else {
FacesMessage message = new FacesMessage("Please enter Java name");
FacesContext.getCurrentInstance().addMessage(null, message);
}
} catch (ConstraintViolationException ex) {
LOGGER.error(ex.getMessage());
}
}
use of jakarta.validation.ConstraintViolationException in project Clownfish by rawdog71.
the class JavascriptList method onCreate.
@Override
public void onCreate(ActionEvent actionEvent) {
try {
if (!javascriptName.isBlank()) {
CfJavascript newjavascript = new CfJavascript();
newjavascript.setName(javascriptName);
newjavascript.setContent("//" + javascriptName);
cfjavascriptService.create(newjavascript);
javascriptListe = cfjavascriptService.findAll();
javascriptName = "";
selectedJavascript = newjavascript;
onSelect(null);
onCheckOut(null);
} else {
FacesMessage message = new FacesMessage("Please enter javascript name");
FacesContext.getCurrentInstance().addMessage(null, message);
}
} catch (ConstraintViolationException ex) {
LOGGER.error(ex.getMessage());
}
}
use of jakarta.validation.ConstraintViolationException in project Clownfish by rawdog71.
the class ClassList method onEdit.
public void onEdit(ActionEvent actionEvent) {
try {
selectedClass.setName(className);
selectedClass.setSearchrelevant(classSearchrelevant);
selectedClass.setMaintenance(classMaintenance);
selectedClass.setTemplateref(selectedTemplateRef);
cfclassService.edit(selectedClass);
classListe = cfclassService.findAll();
contentlist.init();
datalist.init();
FacesMessage message = new FacesMessage("Content changed");
FacesContext.getCurrentInstance().addMessage(null, message);
} catch (ConstraintViolationException ex) {
LOGGER.error(ex.getMessage());
}
}
Aggregations