@Test
  public void testDELETEObjectUnAuthorized() throws Exception {
    Object objectToBeDeleted = getObject("XWiki.TagClass");

    DeleteMethod deleteMethod =
        executeDelete(
            getUriBuilder(ObjectResource.class)
                .build(
                    getWiki(),
                    "Main",
                    "WebHome",
                    objectToBeDeleted.getClassName(),
                    objectToBeDeleted.getNumber())
                .toString());
    Assert.assertEquals(
        getHttpMethodInfo(deleteMethod), HttpStatus.SC_UNAUTHORIZED, deleteMethod.getStatusCode());

    GetMethod getMethod =
        executeGet(
            getUriBuilder(ObjectResource.class)
                .build(
                    getWiki(),
                    "Main",
                    "WebHome",
                    objectToBeDeleted.getClassName(),
                    objectToBeDeleted.getNumber())
                .toString());
    Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
  }
Ejemplo n.º 2
0
 protected static DeleteMethod httpDelete(String path) throws IOException {
   LOG.info("Connecting to {}", url + path);
   HttpClient httpClient = new HttpClient();
   DeleteMethod deleteMethod = new DeleteMethod(url + path);
   deleteMethod.addRequestHeader("Origin", url);
   httpClient.executeMethod(deleteMethod);
   LOG.info("{} - {}", deleteMethod.getStatusCode(), deleteMethod.getStatusText());
   return deleteMethod;
 }
Ejemplo n.º 3
0
  public void executeDeleteObject(final String uri) throws CloudstackRESTException {
    final DeleteMethod dm = (DeleteMethod) createMethod(DELETE_METHOD_TYPE, uri);
    dm.setRequestHeader(CONTENT_TYPE, JSON_CONTENT_TYPE);

    executeMethod(dm);

    if (dm.getStatusCode() != HttpStatus.SC_NO_CONTENT) {
      final String errorMessage = responseToErrorMessage(dm);
      dm.releaseConnection();
      s_logger.error("Failed to delete object : " + errorMessage);
      throw new CloudstackRESTException("Failed to delete object : " + errorMessage);
    }
    dm.releaseConnection();
  }