Search in sources :

Example 16 with DeleteMethod

use of org.apache.commons.httpclient.methods.DeleteMethod in project zeppelin by apache.

the class NotebookSecurityRestApiTest method deleteNoteForUser.

private void deleteNoteForUser(String noteId, String user, String pwd) throws IOException {
    DeleteMethod delete = httpDelete(("/notebook/" + noteId), user, pwd);
    assertThat("Test delete method:", delete, isAllowed());
    delete.releaseConnection();
    // make sure note is deleted
    if (!noteId.isEmpty()) {
        Note deletedNote = ZeppelinServer.notebook.getNote(noteId);
        assertNull("Deleted note should be null", deletedNote);
    }
}
Also used : DeleteMethod(org.apache.commons.httpclient.methods.DeleteMethod) Note(org.apache.zeppelin.notebook.Note)

Example 17 with DeleteMethod

use of org.apache.commons.httpclient.methods.DeleteMethod in project zeppelin by apache.

the class ZeppelinRestApiTest method testJobs.

@Test
public void testJobs() throws InterruptedException, IOException {
    // create a note and a paragraph
    Note note = ZeppelinServer.notebook.createNote(anonymous);
    note.setName("note for run test");
    Paragraph paragraph = note.addParagraph(AuthenticationInfo.ANONYMOUS);
    paragraph.setText("%md This is test paragraph.");
    Map config = paragraph.getConfig();
    config.put("enabled", true);
    paragraph.setConfig(config);
    note.runAll();
    // wait until job is finished or timeout.
    int timeout = 1;
    while (!paragraph.isTerminated()) {
        Thread.sleep(1000);
        if (timeout++ > 10) {
            LOG.info("testNoteJobs timeout job.");
            break;
        }
    }
    String jsonRequest = "{\"cron\":\"* * * * * ?\" }";
    // right cron expression but not exist note.
    PostMethod postCron = httpPost("/notebook/cron/notexistnote", jsonRequest);
    assertThat("", postCron, isNotFound());
    postCron.releaseConnection();
    // right cron expression.
    postCron = httpPost("/notebook/cron/" + note.getId(), jsonRequest);
    assertThat("", postCron, isAllowed());
    postCron.releaseConnection();
    Thread.sleep(1000);
    // wrong cron expression.
    jsonRequest = "{\"cron\":\"a * * * * ?\" }";
    postCron = httpPost("/notebook/cron/" + note.getId(), jsonRequest);
    assertThat("", postCron, isBadRequest());
    postCron.releaseConnection();
    Thread.sleep(1000);
    // remove cron job.
    DeleteMethod deleteCron = httpDelete("/notebook/cron/" + note.getId());
    assertThat("", deleteCron, isAllowed());
    deleteCron.releaseConnection();
    ZeppelinServer.notebook.removeNote(note.getId(), anonymous);
}
Also used : DeleteMethod(org.apache.commons.httpclient.methods.DeleteMethod) PostMethod(org.apache.commons.httpclient.methods.PostMethod) Note(org.apache.zeppelin.notebook.Note) Map(java.util.Map) Paragraph(org.apache.zeppelin.notebook.Paragraph) Test(org.junit.Test)

Example 18 with DeleteMethod

use of org.apache.commons.httpclient.methods.DeleteMethod in project zeppelin by apache.

the class ZeppelinRestApiTest method testDeleteParagraph.

@Test
public void testDeleteParagraph() throws IOException {
    Note note = ZeppelinServer.notebook.createNote(anonymous);
    Paragraph p = note.addParagraph(AuthenticationInfo.ANONYMOUS);
    p.setTitle("title1");
    p.setText("text1");
    note.persist(anonymous);
    DeleteMethod delete = httpDelete("/notebook/" + note.getId() + "/paragraph/" + p.getId());
    assertThat("Test delete method: ", delete, isAllowed());
    delete.releaseConnection();
    Note retrNote = ZeppelinServer.notebook.getNote(note.getId());
    Paragraph retrParagrah = retrNote.getParagraph(p.getId());
    assertNull("paragraph should be deleted", retrParagrah);
    ZeppelinServer.notebook.removeNote(note.getId(), anonymous);
}
Also used : DeleteMethod(org.apache.commons.httpclient.methods.DeleteMethod) Note(org.apache.zeppelin.notebook.Note) Paragraph(org.apache.zeppelin.notebook.Paragraph) Test(org.junit.Test)

Example 19 with DeleteMethod

use of org.apache.commons.httpclient.methods.DeleteMethod in project tdi-studio-se by Talend.

the class MDMTransaction method rollback.

public void rollback() throws IOException {
    HttpClient client = new HttpClient();
    client.getState().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(username, password));
    HttpMethod method = new DeleteMethod(url + "/" + id);
    method.setDoAuthentication(true);
    try {
        //$NON-NLS-1$ //$NON-NLS-2$
        method.setRequestHeader("Cookie", getStickySession() + "=" + sessionId);
        client.executeMethod(method);
    } catch (HttpException e) {
        throw e;
    } catch (IOException e) {
        throw e;
    } finally {
        method.releaseConnection();
    }
    int statuscode = method.getStatusCode();
    if (statuscode >= 400) {
        throw new MDMTransactionException("Rollback failed. The rollback operation has returned the code " + statuscode + ".");
    }
}
Also used : DeleteMethod(org.apache.commons.httpclient.methods.DeleteMethod) HttpClient(org.apache.commons.httpclient.HttpClient) HttpException(org.apache.commons.httpclient.HttpException) IOException(java.io.IOException) HttpMethod(org.apache.commons.httpclient.HttpMethod) UsernamePasswordCredentials(org.apache.commons.httpclient.UsernamePasswordCredentials)

Example 20 with DeleteMethod

use of org.apache.commons.httpclient.methods.DeleteMethod in project zm-mailbox by Zimbra.

the class ElasticSearchIndexTest method cleanupForIndexStore.

@Override
protected void cleanupForIndexStore() {
    String key = testAcct.getId();
    String indexUrl = String.format("%s%s/", LC.zimbra_index_elasticsearch_url_base.value(), key);
    HttpMethod method = new DeleteMethod(indexUrl);
    try {
        ElasticSearchConnector connector = new ElasticSearchConnector();
        int statusCode = connector.executeMethod(method);
        if (statusCode == HttpStatus.SC_OK) {
            boolean ok = connector.getBooleanAtJsonPath(new String[] { "ok" }, false);
            boolean acknowledged = connector.getBooleanAtJsonPath(new String[] { "acknowledged" }, false);
            if (!ok || !acknowledged) {
                ZimbraLog.index.debug("Delete index status ok=%b acknowledged=%b", ok, acknowledged);
            }
        } else {
            String error = connector.getStringAtJsonPath(new String[] { "error" });
            if (error != null && error.startsWith("IndexMissingException")) {
                ZimbraLog.index.debug("Unable to delete index for key=%s.  Index is missing", key);
            } else {
                ZimbraLog.index.error("Problem deleting index for key=%s error=%s", key, error);
            }
        }
    } catch (HttpException e) {
        ZimbraLog.index.error("Problem Deleting index with key=" + key, e);
    } catch (IOException e) {
        ZimbraLog.index.error("Problem Deleting index with key=" + key, e);
    }
}
Also used : DeleteMethod(org.apache.commons.httpclient.methods.DeleteMethod) ElasticSearchConnector(com.zimbra.cs.index.elasticsearch.ElasticSearchConnector) HttpException(org.apache.commons.httpclient.HttpException) IOException(java.io.IOException) HttpMethod(org.apache.commons.httpclient.HttpMethod)

Aggregations

DeleteMethod (org.apache.commons.httpclient.methods.DeleteMethod)25 HttpClient (org.apache.commons.httpclient.HttpClient)9 IOException (java.io.IOException)8 HttpMethod (org.apache.commons.httpclient.HttpMethod)6 Test (org.junit.Test)6 HttpException (org.apache.commons.httpclient.HttpException)5 PostMethod (org.apache.commons.httpclient.methods.PostMethod)5 Note (org.apache.zeppelin.notebook.Note)5 GetMethod (org.apache.commons.httpclient.methods.GetMethod)4 PutMethod (org.apache.commons.httpclient.methods.PutMethod)4 Paragraph (org.apache.zeppelin.notebook.Paragraph)3 Account (com.zimbra.cs.account.Account)2 ElasticSearchConnector (com.zimbra.cs.index.elasticsearch.ElasticSearchConnector)2 URL (java.net.URL)2 Map (java.util.Map)2 Header (org.apache.commons.httpclient.Header)2 UsernamePasswordCredentials (org.apache.commons.httpclient.UsernamePasswordCredentials)2 ByteArrayRequestEntity (org.apache.commons.httpclient.methods.ByteArrayRequestEntity)2 JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1