Search in sources :

Example 21 with Fault

use of org.ovirt.engine.api.model.Fault in project ovirt-engine by oVirt.

the class BackendGlusterBrickResourceTest method testReplace.

@Test
public void testReplace() throws Exception {
    try {
        resource.replace(new Action());
        fail("Expected excpetion");
    } catch (WebApplicationException wae) {
        assertTrue(wae.getResponse().getEntity() instanceof Fault);
    }
}
Also used : Action(org.ovirt.engine.api.model.Action) WebApplicationException(javax.ws.rs.WebApplicationException) Fault(org.ovirt.engine.api.model.Fault) Test(org.junit.Test) AbstractBackendSubResourceTest(org.ovirt.engine.api.restapi.resource.AbstractBackendSubResourceTest)

Example 22 with Fault

use of org.ovirt.engine.api.model.Fault in project ovirt-engine by oVirt.

the class UsageFinderTest method testAdd.

@Test
public void testAdd() {
    try {
        UriInfo uriInfo = mockUri("hosts", "00000001-0001-0001-0001-000000000011", "nics");
        Request request = mockRequest("POST");
        Fault fault = usageFinder.getUsageMessage(uriInfo, request);
        assertEquals("For correct usage, see: http://localhost:8080/ovirt-engine/apidoc#services/host_nics/methods/add", fault.getDetail());
    } catch (ClassNotFoundException | IOException | URISyntaxException e) {
        fail();
    }
}
Also used : Request(javax.ws.rs.core.Request) Fault(org.ovirt.engine.api.model.Fault) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) UriInfo(javax.ws.rs.core.UriInfo) Test(org.junit.Test)

Example 23 with Fault

use of org.ovirt.engine.api.model.Fault in project ovirt-engine by oVirt.

the class UsageFinderTest method testUpdateWithNonGuidId.

@Test
public void testUpdateWithNonGuidId() {
    try {
        // LUN id.
        UriInfo uriInfo = mockUri("hosts", "00000001-0001-0001-0001-000000000011", "nics", "116");
        Request request = mockRequest("PUT");
        Fault fault = usageFinder.getUsageMessage(uriInfo, request);
        assertEquals("For correct usage, see: http://localhost:8080/ovirt-engine/apidoc#services/host_nic/methods/update", fault.getDetail());
    } catch (URISyntaxException | ClassNotFoundException | IOException e) {
        fail();
    }
}
Also used : Request(javax.ws.rs.core.Request) Fault(org.ovirt.engine.api.model.Fault) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) UriInfo(javax.ws.rs.core.UriInfo) Test(org.junit.Test)

Example 24 with Fault

use of org.ovirt.engine.api.model.Fault in project ovirt-engine by oVirt.

the class IOExceptionMapper method toResponse.

@Override
public Response toResponse(IOException exception) {
    // Check if the cause of the exception is an invalid value, and generate a specific error message:
    Throwable cause = exception.getCause();
    if (cause instanceof InvalidValueException) {
        Fault fault = new Fault();
        fault.setReason("Invalid value");
        fault.setDetail(cause.getMessage());
        return Response.status(Response.Status.BAD_REQUEST).entity(fault).build();
    }
    // the request:
    try {
        log.error("IO exception while processing \"{}\" request for path \"{}\"", request.getMethod(), uriInfo.getPath());
        log.error("Exception", exception);
        UsageFinder finder = new UsageFinder();
        return Response.status(Status.BAD_REQUEST).entity(finder.getUsageMessage(uriInfo, request)).build();
    } catch (Exception error) {
        throw new WebApplicationException(error, Response.status(Status.INTERNAL_SERVER_ERROR).build());
    }
}
Also used : InvalidValueException(org.ovirt.engine.api.utils.InvalidValueException) WebApplicationException(javax.ws.rs.WebApplicationException) Fault(org.ovirt.engine.api.model.Fault) IOException(java.io.IOException) InvalidValueException(org.ovirt.engine.api.utils.InvalidValueException) WebApplicationException(javax.ws.rs.WebApplicationException)

Example 25 with Fault

use of org.ovirt.engine.api.model.Fault in project ovirt-engine by oVirt.

the class MalformedIdExceptionMapper method toResponse.

@Override
public Response toResponse(MalformedIdException exception) {
    log.error("Malformed id detected while processing \"{}\" request for path \"{}\"", request.getMethod(), uriInfo.getPath());
    log.error("Exception", exception);
    final Fault fault = new Fault();
    fault.setReason("Operation failed");
    fault.setDetail(exception.getCause().getMessage());
    return Response.status(Status.BAD_REQUEST).entity(fault).build();
}
Also used : Fault(org.ovirt.engine.api.model.Fault)

Aggregations

Fault (org.ovirt.engine.api.model.Fault)42 WebApplicationException (javax.ws.rs.WebApplicationException)17 Test (org.junit.Test)15 UriInfo (javax.ws.rs.core.UriInfo)14 IOException (java.io.IOException)4 URISyntaxException (java.net.URISyntaxException)3 Request (javax.ws.rs.core.Request)3 AbstractBackendCollectionResourceTest (org.ovirt.engine.api.restapi.resource.AbstractBackendCollectionResourceTest)3 Action (org.ovirt.engine.api.model.Action)2 CreationStatus (org.ovirt.engine.api.model.CreationStatus)2 AsyncTaskStatus (org.ovirt.engine.core.common.businessentities.AsyncTaskStatus)2 Response (javax.ws.rs.core.Response)1 Creation (org.ovirt.engine.api.model.Creation)1 GlusterBrick (org.ovirt.engine.api.model.GlusterBrick)1 Vm (org.ovirt.engine.api.model.Vm)1 AbstractBackendSubResourceTest (org.ovirt.engine.api.restapi.resource.AbstractBackendSubResourceTest)1 InvalidValueException (org.ovirt.engine.api.utils.InvalidValueException)1 ActionType (org.ovirt.engine.core.common.action.ActionType)1 RemoveStorageDomainParameters (org.ovirt.engine.core.common.action.RemoveStorageDomainParameters)1 RunVmParams (org.ovirt.engine.core.common.action.RunVmParams)1