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);
}
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);
}
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();
}
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;
}
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);
}
Aggregations