use of org.ovirt.engine.api.model.Fault in project ovirt-engine by oVirt.
the class ValidationExceptionMapper method toResponse.
@Override
public Response toResponse(ValidationException exception) {
log.error("Input validation failed while processing '{}' request for path '{}'.", request.getMethod(), uriInfo.getPath());
log.error("Exception", exception);
final Fault fault = new Fault();
fault.setReason("Input validation failed.");
fault.setDetail(exception.getMessage());
return Response.status(Status.BAD_REQUEST).entity(fault).build();
}
use of org.ovirt.engine.api.model.Fault in project ovirt-engine by oVirt.
the class UsageFinderTest method testAction.
@Test
public void testAction() {
try {
UriInfo uriInfo = mockUri("vms", "00000001-0001-0001-0001-000000000011", "freezefilesystems");
Request request = mockRequest("POST");
Fault fault = usageFinder.getUsageMessage(uriInfo, request);
assertEquals("For correct usage, see: http://localhost:8080/ovirt-engine/apidoc#services/vm/methods/freeze_filesystems", fault.getDetail());
} catch (URISyntaxException | ClassNotFoundException | IOException e) {
fail();
}
}
use of org.ovirt.engine.api.model.Fault in project ovirt-engine by oVirt.
the class BackendGlusterBricksResourceTest method testListFailure.
@Override
@Test
public void testListFailure() throws Exception {
setUpBricksQueryExpectations(FAILURE);
UriInfo uriInfo = setUpUriExpectations(null);
collection.setUriInfo(uriInfo);
try {
getCollection();
fail("expected WebApplicationException");
} catch (WebApplicationException wae) {
assertTrue(wae.getResponse().getEntity() instanceof Fault);
assertEquals(mockl10n(FAILURE), ((Fault) wae.getResponse().getEntity()).getDetail());
}
}
use of org.ovirt.engine.api.model.Fault in project ovirt-engine by oVirt.
the class CompletenessAssertor method assertRequired.
/**
* Validate presence of required parameters.
*
* @param reason the fault reason
* @param detail the fault detail
* @param model the incoming representation
* @param frameOffset the stack frame offset of the public resource method
* @param missingMembers the stack frame offset of the public resource method
* @param required the required field names
* @return error Response if appropriate
*/
private static Response assertRequired(String reason, String detail, Object model, int frameOffset, String... required) {
List<String> missing = doAssertRequired(reason, detail, model, frameOffset, required);
Response response = null;
if (!missing.isEmpty()) {
StackTraceElement[] trace = new Throwable().getStackTrace();
Fault fault = new Fault();
fault.setReason(reason);
fault.setDetail(MessageFormat.format(detail, model.getClass().getSimpleName(), missing, trace[frameOffset + 1].getMethodName()));
response = Response.status(INCOMPLETE_PARAMS_STATUS).entity(fault).build();
}
return response;
}
use of org.ovirt.engine.api.model.Fault in project ovirt-engine by oVirt.
the class EnumValidator method fault.
private static Fault fault(String reason, String detail) {
Fault fault = new Fault();
fault.setReason(reason);
fault.setDetail(detail);
return fault;
}
Aggregations