@Override
  protected int checkResponse(URI uri, ClientResponse response) {
    ClientResponse.Status status = response.getClientResponseStatus();
    int errorCode = status.getStatusCode();
    if (errorCode >= 300) {
      JSONObject obj = null;
      int code = 0;
      try {
        obj = response.getEntity(JSONObject.class);
        code = obj.getInt(ScaleIOConstants.ERROR_CODE);
      } catch (Exception e) {
        log.error("Parsing the failure response object failed", e);
      }

      if (code == 404 || code == 410) {
        throw ScaleIOException.exceptions.resourceNotFound(uri.toString());
      } else if (code == 401) {
        throw ScaleIOException.exceptions.authenticationFailure(uri.toString());
      } else {
        throw ScaleIOException.exceptions.internalError(uri.toString(), obj.toString());
      }
    } else {
      return errorCode;
    }
  }
 public void testUser(String userName, ClientResponse.Status expectedStatus, String expectedResult)
     throws Exception {
   Client webClient = Client.create();
   webClient.addFilter(new HTTPBasicAuthFilter(userName, generalPassword));
   WebResource webResource =
       webClient.resource(
           new URI(contextUri(scheduler().injector()) + "/jobscheduler/engine-cpp/command"));
   ClientResponse response = webResource.post(ClientResponse.class, xmlCommand);
   assertThat(response.getStatus(), equalTo(expectedStatus.getStatusCode()));
   assertThat(response.getEntity(String.class), containsString(expectedResult));
   webClient.destroy();
 }
 private SchemaEntry handleRegisterRequest(String path, String schema)
     throws SchemaValidationException {
   String schemaId;
   try {
     schemaId = webResource.path(path).type(MediaType.TEXT_PLAIN_TYPE).put(String.class, schema);
     return new SchemaEntry(schemaId, schema);
   } catch (UniformInterfaceException e) {
     ClientResponse cr = e.getResponse();
     if (ClientResponse.Status.fromStatusCode(cr.getStatus())
         .equals(ClientResponse.Status.FORBIDDEN)) {
       throw new SchemaValidationException("Invalid schema: " + schema);
     } else {
       // any other status should return null
       return null;
     }
   } catch (ClientHandlerException e) {
     return null;
   }
 }