Search in sources :

Example 6 with PutMethod

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

the class NotebookRestApiTest method testUpdateParagraphConfig.

@Test
public void testUpdateParagraphConfig() throws IOException {
    Note note = ZeppelinServer.notebook.createNote(anonymous);
    String noteId = note.getId();
    Paragraph p = note.addParagraph(AuthenticationInfo.ANONYMOUS);
    assertNull(p.getConfig().get("colWidth"));
    String paragraphId = p.getId();
    String jsonRequest = "{\"colWidth\": 6.0}";
    PutMethod put = httpPut("/notebook/" + noteId + "/paragraph/" + paragraphId + "/config", jsonRequest);
    assertThat("test testUpdateParagraphConfig:", put, isAllowed());
    Map<String, Object> resp = gson.fromJson(put.getResponseBodyAsString(), new TypeToken<Map<String, Object>>() {
    }.getType());
    Map<String, Object> respBody = (Map<String, Object>) resp.get("body");
    Map<String, Object> config = (Map<String, Object>) respBody.get("config");
    put.releaseConnection();
    assertEquals(config.get("colWidth"), 6.0);
    note = ZeppelinServer.notebook.getNote(noteId);
    assertEquals(note.getParagraph(paragraphId).getConfig().get("colWidth"), 6.0);
    //cleanup
    ZeppelinServer.notebook.removeNote(noteId, anonymous);
}
Also used : TypeToken(com.google.gson.reflect.TypeToken) Note(org.apache.zeppelin.notebook.Note) PutMethod(org.apache.commons.httpclient.methods.PutMethod) Map(java.util.Map) Paragraph(org.apache.zeppelin.notebook.Paragraph) Test(org.junit.Test)

Example 7 with PutMethod

use of org.apache.commons.httpclient.methods.PutMethod 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 8 with PutMethod

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

the class NotebookSecurityRestApiTest method setPermissionForNote.

private void setPermissionForNote(String noteId, String user, String pwd) throws IOException {
    String payload = "{\"owners\":[\"" + user + "\"],\"readers\":[\"" + user + "\"],\"writers\":[\"" + user + "\"]}";
    PutMethod put = httpPut(("/notebook/" + noteId + "/permissions"), payload, user, pwd);
    put.releaseConnection();
}
Also used : PutMethod(org.apache.commons.httpclient.methods.PutMethod)

Example 9 with PutMethod

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

the class MDMTransactionClient method newTransaction.

public static MDMTransaction newTransaction(String url, String username, String password) throws IOException {
    HttpClient client = new HttpClient();
    client.getState().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(username, password));
    client.getParams().setAuthenticationPreemptive(true);
    PutMethod put = new PutMethod(url);
    put.setDoAuthentication(true);
    String tid;
    String sessionID;
    try {
        client.executeMethod(put);
        tid = put.getResponseBodyAsString();
        sessionID = parseSessionID(put);
    } catch (HttpException e) {
        throw e;
    } catch (IOException e) {
        throw e;
    } finally {
        put.releaseConnection();
    }
    MDMTransaction result = new MDMTransaction();
    result.setUrl(url);
    result.setId(tid);
    result.setUsername(username);
    result.setPassword(password);
    result.setSessionId(sessionID);
    return result;
}
Also used : HttpClient(org.apache.commons.httpclient.HttpClient) PutMethod(org.apache.commons.httpclient.methods.PutMethod) HttpException(org.apache.commons.httpclient.HttpException) IOException(java.io.IOException) UsernamePasswordCredentials(org.apache.commons.httpclient.UsernamePasswordCredentials)

Example 10 with PutMethod

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

the class WebDavClient method sendPut.

public HttpInputStream sendPut(String href, byte[] buf, String contentType, String etag, Collection<Pair<String, String>> headers) throws IOException {
    boolean done = false;
    PutMethod put = null;
    while (!done) {
        put = new PutMethod(mBaseUrl + href);
        put.setRequestEntity(new ByteArrayRequestEntity(buf, contentType));
        if (mDebugEnabled && contentType.startsWith("text"))
            ZimbraLog.dav.debug("PUT payload: \n" + new String(buf, "UTF-8"));
        if (etag != null)
            put.setRequestHeader(DavProtocol.HEADER_IF_MATCH, etag);
        if (headers != null)
            for (Pair<String, String> h : headers) put.addRequestHeader(h.getFirst(), h.getSecond());
        executeMethod(put, Depth.zero);
        int ret = put.getStatusCode();
        if (ret == HttpStatus.SC_MOVED_PERMANENTLY || ret == HttpStatus.SC_MOVED_TEMPORARILY) {
            Header newLocation = put.getResponseHeader("Location");
            if (newLocation != null) {
                href = newLocation.getValue();
                ZimbraLog.dav.debug("redirect to new url = " + href);
                put.releaseConnection();
                continue;
            }
        }
        done = true;
    }
    return new HttpInputStream(put);
}
Also used : Header(org.apache.commons.httpclient.Header) PutMethod(org.apache.commons.httpclient.methods.PutMethod) HttpInputStream(com.zimbra.cs.service.UserServlet.HttpInputStream) ByteArrayRequestEntity(org.apache.commons.httpclient.methods.ByteArrayRequestEntity) Pair(com.zimbra.common.util.Pair)

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