Search in sources :

Example 21 with PutMethod

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

the class AbstractTestRestApi method httpPut.

protected static PutMethod httpPut(String path, String body, String user, String pwd) throws IOException {
    LOG.info("Connecting to {}", url + path);
    HttpClient httpClient = new HttpClient();
    PutMethod putMethod = new PutMethod(url + path);
    putMethod.addRequestHeader("Origin", url);
    RequestEntity entity = new ByteArrayRequestEntity(body.getBytes("UTF-8"));
    putMethod.setRequestEntity(entity);
    if (userAndPasswordAreNotBlank(user, pwd)) {
        putMethod.setRequestHeader("Cookie", "JSESSIONID=" + getCookie(user, pwd));
    }
    httpClient.executeMethod(putMethod);
    LOG.info("{} - {}", putMethod.getStatusCode(), putMethod.getStatusText());
    return putMethod;
}
Also used : HttpClient(org.apache.commons.httpclient.HttpClient) PutMethod(org.apache.commons.httpclient.methods.PutMethod) ByteArrayRequestEntity(org.apache.commons.httpclient.methods.ByteArrayRequestEntity) RequestEntity(org.apache.commons.httpclient.methods.RequestEntity) ByteArrayRequestEntity(org.apache.commons.httpclient.methods.ByteArrayRequestEntity)

Example 22 with PutMethod

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

the class InterpreterRestApiTest method testSettingsCRUD.

@Test
public void testSettingsCRUD() throws IOException {
    // when: call create setting API
    String rawRequest = "{\"name\":\"md2\",\"group\":\"md\",\"properties\":{\"propname\":\"propvalue\"}," + "\"interpreterGroup\":[{\"class\":\"org.apache.zeppelin.markdown.Markdown\",\"name\":\"md\"}]," + "\"dependencies\":[]," + "\"option\": { \"remote\": true, \"session\": false }}";
    JsonObject jsonRequest = gson.fromJson(rawRequest, JsonElement.class).getAsJsonObject();
    PostMethod post = httpPost("/interpreter/setting/", jsonRequest.toString());
    String postResponse = post.getResponseBodyAsString();
    LOG.info("testSettingCRUD create response\n" + post.getResponseBodyAsString());
    InterpreterSetting created = convertResponseToInterpreterSetting(postResponse);
    String newSettingId = created.getId();
    // then : call create setting API
    assertThat("test create method:", post, isAllowed());
    post.releaseConnection();
    // when: call read setting API
    GetMethod get = httpGet("/interpreter/setting/" + newSettingId);
    String getResponse = get.getResponseBodyAsString();
    LOG.info("testSettingCRUD get response\n" + getResponse);
    InterpreterSetting previouslyCreated = convertResponseToInterpreterSetting(getResponse);
    // then : read Setting API
    assertThat("Test get method:", get, isAllowed());
    assertEquals(newSettingId, previouslyCreated.getId());
    get.releaseConnection();
    // when: call update setting API
    jsonRequest.getAsJsonObject("properties").addProperty("propname2", "this is new prop");
    PutMethod put = httpPut("/interpreter/setting/" + newSettingId, jsonRequest.toString());
    LOG.info("testSettingCRUD update response\n" + put.getResponseBodyAsString());
    // then: call update setting API
    assertThat("test update method:", put, isAllowed());
    put.releaseConnection();
    // when: call delete setting API
    DeleteMethod delete = httpDelete("/interpreter/setting/" + newSettingId);
    LOG.info("testSettingCRUD delete response\n" + delete.getResponseBodyAsString());
    // then: call delete setting API
    assertThat("Test delete method:", delete, isAllowed());
    delete.releaseConnection();
}
Also used : DeleteMethod(org.apache.commons.httpclient.methods.DeleteMethod) PostMethod(org.apache.commons.httpclient.methods.PostMethod) JsonElement(com.google.gson.JsonElement) InterpreterSetting(org.apache.zeppelin.interpreter.InterpreterSetting) GetMethod(org.apache.commons.httpclient.methods.GetMethod) JsonObject(com.google.gson.JsonObject) PutMethod(org.apache.commons.httpclient.methods.PutMethod) Test(org.junit.Test)

Example 23 with PutMethod

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

the class InterpreterRestApiTest method testInterpreterRestart.

@Test
public void testInterpreterRestart() throws IOException, InterruptedException {
    // when: create new note
    Note note = ZeppelinServer.notebook.createNote(anonymous);
    note.addParagraph(AuthenticationInfo.ANONYMOUS);
    Paragraph p = note.getLastParagraph();
    Map config = p.getConfig();
    config.put("enabled", true);
    // when: run markdown paragraph
    p.setConfig(config);
    p.setText("%md markdown");
    p.setAuthenticationInfo(anonymous);
    note.run(p.getId());
    while (p.getStatus() != Status.FINISHED) {
        Thread.sleep(100);
    }
    assertEquals(p.getResult().message().get(0).getData(), getSimulatedMarkdownResult("markdown"));
    // when: restart interpreter
    for (InterpreterSetting setting : ZeppelinServer.notebook.getInterpreterSettingManager().getInterpreterSettings(note.getId())) {
        if (setting.getName().equals("md")) {
            // call restart interpreter API
            PutMethod put = httpPut("/interpreter/setting/restart/" + setting.getId(), "");
            assertThat("test interpreter restart:", put, isAllowed());
            put.releaseConnection();
            break;
        }
    }
    // when: run markdown paragraph, again
    p = note.addParagraph(AuthenticationInfo.ANONYMOUS);
    p.setConfig(config);
    p.setText("%md markdown restarted");
    p.setAuthenticationInfo(anonymous);
    note.run(p.getId());
    while (p.getStatus() != Status.FINISHED) {
        Thread.sleep(100);
    }
    // then
    assertEquals(p.getResult().message().get(0).getData(), getSimulatedMarkdownResult("markdown restarted"));
    ZeppelinServer.notebook.removeNote(note.getId(), anonymous);
}
Also used : Note(org.apache.zeppelin.notebook.Note) InterpreterSetting(org.apache.zeppelin.interpreter.InterpreterSetting) PutMethod(org.apache.commons.httpclient.methods.PutMethod) Map(java.util.Map) Paragraph(org.apache.zeppelin.notebook.Paragraph) Test(org.junit.Test)

Example 24 with PutMethod

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

the class NotebookSecurityRestApiTest method testThatWriterCannotRemoveNote.

@Test
public void testThatWriterCannotRemoveNote() throws IOException {
    String noteId = createNoteForUser("test", "admin", "password1");
    //set permission
    String payload = "{ \"owners\": [\"admin\", \"user1\"], \"readers\": [\"user2\"], \"writers\": [\"user2\"] }";
    PutMethod put = httpPut("/notebook/" + noteId + "/permissions", payload, "admin", "password1");
    assertThat("test set note permission method:", put, isAllowed());
    put.releaseConnection();
    userTryRemoveNote(noteId, "user2", "password3", isForbidden());
    userTryRemoveNote(noteId, "user1", "password2", isAllowed());
    Note deletedNote = ZeppelinServer.notebook.getNote(noteId);
    assertNull("Deleted note should be null", deletedNote);
}
Also used : Note(org.apache.zeppelin.notebook.Note) PutMethod(org.apache.commons.httpclient.methods.PutMethod) Test(org.junit.Test)

Example 25 with PutMethod

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

the class CredentialsRestApiTest method testPutUserCredentials.

public void testPutUserCredentials(String requestData) throws IOException {
    PutMethod putMethod = httpPut("/credential", requestData);
    putMethod.addRequestHeader("Origin", "http://localhost");
    assertThat(putMethod, isAllowed());
    putMethod.releaseConnection();
}
Also used : PutMethod(org.apache.commons.httpclient.methods.PutMethod)

Aggregations

PutMethod (org.apache.commons.httpclient.methods.PutMethod)37 Test (org.junit.Test)13 HttpClient (org.apache.commons.httpclient.HttpClient)12 Header (org.apache.commons.httpclient.Header)8 ByteArrayRequestEntity (org.apache.commons.httpclient.methods.ByteArrayRequestEntity)8 GetMethod (org.apache.commons.httpclient.methods.GetMethod)8 IOException (java.io.IOException)7 HttpMethod (org.apache.commons.httpclient.HttpMethod)6 Map (java.util.Map)5 Note (org.apache.zeppelin.notebook.Note)5 Pair (com.zimbra.common.util.Pair)4 Account (com.zimbra.cs.account.Account)4 HttpException (org.apache.commons.httpclient.HttpException)4 DeleteMethod (org.apache.commons.httpclient.methods.DeleteMethod)4 PostMethod (org.apache.commons.httpclient.methods.PostMethod)4 StringRequestEntity (org.apache.commons.httpclient.methods.StringRequestEntity)4 InputStreamRequestEntity (org.apache.commons.httpclient.methods.InputStreamRequestEntity)3 RequestEntity (org.apache.commons.httpclient.methods.RequestEntity)3 Paragraph (org.apache.zeppelin.notebook.Paragraph)3 TypeToken (com.google.gson.reflect.TypeToken)2