@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());
  }
예제 #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;
 }
예제 #3
0
 public void purgeObject(String pid, boolean force) throws IOException {
   StringBuilder uri = new StringBuilder(getBaseUrl());
   uri.append("/objects/");
   uri.append(pid);
   uri.append("?force=");
   uri.append(force);
   DeleteMethod method = new DeleteMethod(uri.toString());
   executeMethod(method);
   method.releaseConnection();
 }
예제 #4
0
 /** Remove entry from server. */
 public void remove() throws ProponoException {
   if (getEditURI() == null) {
     throw new ProponoException("ERROR: cannot delete unsaved entry");
   }
   DeleteMethod method = new DeleteMethod(getEditURI());
   addAuthentication(method);
   try {
     getHttpClient().executeMethod(method);
   } catch (IOException ex) {
     throw new ProponoException("ERROR: removing entry, HTTP code", ex);
   } finally {
     method.releaseConnection();
   }
 }
예제 #5
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();
  }
예제 #6
0
  private DeleteMethod convertHttpServletRequestToDeleteMethod(
      String url, HttpServletRequest request) {
    DeleteMethod method = new DeleteMethod(url);

    for (Enumeration headers = request.getHeaderNames(); headers.hasMoreElements(); ) {
      String headerName = (String) headers.nextElement();
      String headerValue = (String) request.getHeader(headerName);
      method.addRequestHeader(headerName, headerValue);
    }

    method.removeRequestHeader("Host");
    method.addRequestHeader("Host", request.getRequestURL().toString());

    return method;
  }
  @Test
  public void testAddDeleteRepository() throws IOException {
    // Call create repository REST API
    String repoId = "securecentral";
    String jsonRequest =
        "{\"id\":\""
            + repoId
            + "\",\"url\":\"https://repo1.maven.org/maven2\",\"snapshot\":\"false\"}";

    PostMethod post = httpPost("/interpreter/repository/", jsonRequest);
    assertThat("Test create method:", post, isCreated());
    post.releaseConnection();

    // Call delete repository REST API
    DeleteMethod delete = httpDelete("/interpreter/repository/" + repoId);
    assertThat("Test delete method:", delete, isAllowed());
    delete.releaseConnection();
  }
 @Override
 public boolean deleteFromStore(String locator, Mailbox mbox) throws IOException {
   HttpClient client = ZimbraHttpConnectionManager.getInternalHttpConnMgr().newHttpClient();
   DeleteMethod delete = new DeleteMethod(getDeleteUrl(mbox, locator));
   try {
     int statusCode = HttpClientUtil.executeMethod(client, delete);
     if (statusCode == HttpStatus.SC_OK || statusCode == HttpStatus.SC_NO_CONTENT) {
       return true;
     } else if (statusCode == HttpStatus.SC_NOT_FOUND) {
       return false;
     } else {
       throw new IOException(
           "unexpected return code during blob DELETE: " + delete.getStatusText());
     }
   } finally {
     delete.releaseConnection();
   }
 }
  public JSONObject delete(String path) throws Exception {
    JSONObject result = new JSONObject();
    DeleteMethod method = new DeleteMethod(repoHostname + ":" + repoHostPort + "/api/data/" + path);
    method.getParams().setCookiePolicy(CookiePolicy.RFC_2109);
    method.setRequestHeader("Cookie", "jsonhub-store-key=" + getStoreKey());

    // client.getState().setCredentials(new AuthScope(null, repoHostPort, "authentication"), new
    // UsernamePasswordCredentials(memberId, memberPassword));

    // method.setDoAuthentication(true);

    int statusCode = client.executeMethod(method);

    if (statusCode != HttpStatus.SC_OK) {
      System.err.println("Method failed: " + method.getStatusLine());
    }

    Reader reader = new InputStreamReader(method.getResponseBodyAsStream());
    CharArrayWriter cdata = new CharArrayWriter();
    char buf[] = new char[BUFFER_SIZE];
    int ret;
    while ((ret = reader.read(buf, 0, BUFFER_SIZE)) != -1) cdata.write(buf, 0, ret);

    reader.close();

    result = JSONObject.fromString(cdata.toString());

    method.releaseConnection();

    if (result.has("error")) throw new GeneralException(result.getString("error"));

    return result;
  }
  @Test
  public void testSettingsCRUD() throws IOException {
    // Call Create Setting REST API
    String jsonRequest =
        "{\"name\":\"md2\",\"group\":\"md\",\"properties\":{\"propname\":\"propvalue\"},"
            + "\"interpreterGroup\":[{\"class\":\"org.apache.zeppelin.markdown.Markdown\",\"name\":\"md\"}],"
            + "\"dependencies\":[],"
            + "\"option\": { \"remote\": true, \"session\": false }}";
    PostMethod post = httpPost("/interpreter/setting/", jsonRequest);
    LOG.info("testSettingCRUD create response\n" + post.getResponseBodyAsString());
    assertThat("test create method:", post, isCreated());

    Map<String, Object> resp =
        gson.fromJson(
            post.getResponseBodyAsString(), new TypeToken<Map<String, Object>>() {}.getType());
    Map<String, Object> body = (Map<String, Object>) resp.get("body");
    // extract id from body string {id=2AWMQDNX7, name=md2, group=md,
    String newSettingId = body.toString().split(",")[0].split("=")[1];
    post.releaseConnection();

    // Call Update Setting REST API
    jsonRequest =
        "{\"name\":\"md2\",\"group\":\"md\",\"properties\":{\"propname\":\"Otherpropvalue\"},"
            + "\"interpreterGroup\":[{\"class\":\"org.apache.zeppelin.markdown.Markdown\",\"name\":\"md\"}],"
            + "\"dependencies\":[],"
            + "\"option\": { \"remote\": true, \"session\": false }}";
    PutMethod put = httpPut("/interpreter/setting/" + newSettingId, jsonRequest);
    LOG.info("testSettingCRUD update response\n" + put.getResponseBodyAsString());
    assertThat("test update method:", put, isAllowed());
    put.releaseConnection();

    // Call Delete Setting REST API
    DeleteMethod delete = httpDelete("/interpreter/setting/" + newSettingId);
    LOG.info("testSettingCRUD delete response\n" + delete.getResponseBodyAsString());
    assertThat("Test delete method:", delete, isAllowed());
    delete.releaseConnection();
  }