Search in sources :

Example 11 with GetMethod

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

the class NotebookRestApiTest method testClearAllParagraphOutput.

@Test
public void testClearAllParagraphOutput() throws IOException {
    // Create note and set result explicitly
    Note note = ZeppelinServer.notebook.createNote(anonymous);
    Paragraph p1 = note.addParagraph(AuthenticationInfo.ANONYMOUS);
    InterpreterResult result = new InterpreterResult(InterpreterResult.Code.SUCCESS, InterpreterResult.Type.TEXT, "result");
    p1.setResult(result);
    Paragraph p2 = note.addParagraph(AuthenticationInfo.ANONYMOUS);
    p2.setReturn(result, new Throwable());
    // clear paragraph result
    PutMethod put = httpPut("/notebook/" + note.getId() + "/clear", "");
    LOG.info("test clear paragraph output response\n" + put.getResponseBodyAsString());
    assertThat(put, isAllowed());
    put.releaseConnection();
    // check if paragraph results are cleared
    GetMethod get = httpGet("/notebook/" + note.getId() + "/paragraph/" + p1.getId());
    assertThat(get, isAllowed());
    Map<String, Object> resp1 = gson.fromJson(get.getResponseBodyAsString(), new TypeToken<Map<String, Object>>() {
    }.getType());
    Map<String, Object> resp1Body = (Map<String, Object>) resp1.get("body");
    assertNull(resp1Body.get("result"));
    get = httpGet("/notebook/" + note.getId() + "/paragraph/" + p2.getId());
    assertThat(get, isAllowed());
    Map<String, Object> resp2 = gson.fromJson(get.getResponseBodyAsString(), new TypeToken<Map<String, Object>>() {
    }.getType());
    Map<String, Object> resp2Body = (Map<String, Object>) resp2.get("body");
    assertNull(resp2Body.get("result"));
    get.releaseConnection();
    //cleanup
    ZeppelinServer.notebook.removeNote(note.getId(), anonymous);
}
Also used : TypeToken(com.google.gson.reflect.TypeToken) Note(org.apache.zeppelin.notebook.Note) GetMethod(org.apache.commons.httpclient.methods.GetMethod) InterpreterResult(org.apache.zeppelin.interpreter.InterpreterResult) PutMethod(org.apache.commons.httpclient.methods.PutMethod) Map(java.util.Map) Paragraph(org.apache.zeppelin.notebook.Paragraph) Test(org.junit.Test)

Example 12 with GetMethod

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

the class AbstractTestRestApi method httpGet.

protected static GetMethod httpGet(String path, String user, String pwd) throws IOException {
    LOG.info("Connecting to {}", url + path);
    HttpClient httpClient = new HttpClient();
    GetMethod getMethod = new GetMethod(url + path);
    getMethod.addRequestHeader("Origin", url);
    if (userAndPasswordAreNotBlank(user, pwd)) {
        getMethod.setRequestHeader("Cookie", "JSESSIONID=" + getCookie(user, pwd));
    }
    httpClient.executeMethod(getMethod);
    LOG.info("{} - {}", getMethod.getStatusCode(), getMethod.getStatusText());
    return getMethod;
}
Also used : HttpClient(org.apache.commons.httpclient.HttpClient) GetMethod(org.apache.commons.httpclient.methods.GetMethod)

Example 13 with GetMethod

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

the class ConfigurationsRestApiTest method testGetAll.

@Test
public void testGetAll() throws IOException {
    GetMethod get = httpGet("/configurations/all");
    Map<String, Object> resp = gson.fromJson(get.getResponseBodyAsString(), new TypeToken<Map<String, Object>>() {
    }.getType());
    Map<String, String> body = (Map<String, String>) resp.get("body");
    assertTrue(body.size() > 0);
    // it shouldn't have key/value pair which key contains "password"
    assertTrue(Iterators.all(body.keySet().iterator(), new Predicate<String>() {

        @Override
        public boolean apply(String key) {
            return !key.contains("password");
        }
    }));
}
Also used : TypeToken(com.google.gson.reflect.TypeToken) GetMethod(org.apache.commons.httpclient.methods.GetMethod) Map(java.util.Map) Predicate(com.google.common.base.Predicate) Test(org.junit.Test)

Example 14 with GetMethod

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

the class ConfigurationsRestApiTest method testGetViaPrefix.

@Test
public void testGetViaPrefix() throws IOException {
    final String prefix = "zeppelin.server";
    GetMethod get = httpGet("/configurations/prefix/" + prefix);
    Map<String, Object> resp = gson.fromJson(get.getResponseBodyAsString(), new TypeToken<Map<String, Object>>() {
    }.getType());
    Map<String, String> body = (Map<String, String>) resp.get("body");
    assertTrue(body.size() > 0);
    assertTrue(Iterators.all(body.keySet().iterator(), new Predicate<String>() {

        @Override
        public boolean apply(String key) {
            return !key.contains("password") && key.startsWith(prefix);
        }
    }));
}
Also used : TypeToken(com.google.gson.reflect.TypeToken) GetMethod(org.apache.commons.httpclient.methods.GetMethod) Map(java.util.Map) Predicate(com.google.common.base.Predicate) Test(org.junit.Test)

Example 15 with GetMethod

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

the class InterpreterRestApiTest method testListRepository.

@Test
public void testListRepository() throws IOException {
    GetMethod get = httpGet("/interpreter/repository");
    assertThat(get, isAllowed());
    get.releaseConnection();
}
Also used : GetMethod(org.apache.commons.httpclient.methods.GetMethod) Test(org.junit.Test)

Aggregations

GetMethod (org.apache.commons.httpclient.methods.GetMethod)357 HttpClient (org.apache.commons.httpclient.HttpClient)216 HttpMethod (org.apache.commons.httpclient.HttpMethod)93 IOException (java.io.IOException)82 Test (org.junit.Test)70 InputStream (java.io.InputStream)65 HttpException (org.apache.commons.httpclient.HttpException)41 Map (java.util.Map)39 ArrayList (java.util.ArrayList)37 HashMap (java.util.HashMap)36 JSONParser (org.json.simple.parser.JSONParser)34 JSONObject (org.json.simple.JSONObject)31 Header (org.apache.commons.httpclient.Header)22 Element (org.w3c.dom.Element)22 PostMethod (org.apache.commons.httpclient.methods.PostMethod)21 TypeToken (com.google.gson.reflect.TypeToken)20 List (java.util.List)19 HttpState (org.apache.commons.httpclient.HttpState)18 URI (java.net.URI)17 JSONArray (org.json.simple.JSONArray)17