use of org.apache.commons.httpclient.methods.GetMethod in project zeppelin by apache.
the class NotebookSecurityRestApiTest method userTryGetNote.
private void userTryGetNote(String noteId, String user, String pwd, Matcher<? super HttpMethodBase> m) throws IOException {
GetMethod get = httpGet("/notebook/" + noteId, user, pwd);
assertThat(get, m);
get.releaseConnection();
}
use of org.apache.commons.httpclient.methods.GetMethod in project zeppelin by apache.
the class ZeppelinRestApiTest method testexportNote.
@Test
public void testexportNote() throws IOException {
LOG.info("testexportNote");
Note note = ZeppelinServer.notebook.createNote(anonymous);
assertNotNull("can't create new note", note);
note.setName("source note for export");
Paragraph paragraph = note.addParagraph(AuthenticationInfo.ANONYMOUS);
Map config = paragraph.getConfig();
config.put("enabled", true);
paragraph.setConfig(config);
paragraph.setText("%md This is my new paragraph in my new note");
note.persist(anonymous);
String sourceNoteId = note.getId();
// Call export Note REST API
GetMethod get = httpGet("/notebook/export/" + sourceNoteId);
LOG.info("testNoteExport \n" + get.getResponseBodyAsString());
assertThat("test note export method:", get, isAllowed());
Map<String, Object> resp = gson.fromJson(get.getResponseBodyAsString(), new TypeToken<Map<String, Object>>() {
}.getType());
String exportJSON = (String) resp.get("body");
assertNotNull("Can not find new notejson", exportJSON);
LOG.info("export JSON:=" + exportJSON);
ZeppelinServer.notebook.removeNote(sourceNoteId, anonymous);
get.releaseConnection();
}
use of org.apache.commons.httpclient.methods.GetMethod in project zeppelin by apache.
the class AbstractTestRestApi method checkIfServerIsRunning.
protected static boolean checkIfServerIsRunning() {
GetMethod request = null;
boolean isRunning = true;
try {
request = httpGet("/version");
isRunning = request.getStatusCode() == 200;
} catch (IOException e) {
LOG.error("AbstractTestRestApi.checkIfServerIsRunning() fails .. ZeppelinServer is not running");
isRunning = false;
} finally {
if (request != null) {
request.releaseConnection();
}
}
return isRunning;
}
use of org.apache.commons.httpclient.methods.GetMethod in project pinot by linkedin.
the class SchemaUtils method getSchema.
/**
* Given host, port and schema name, send a http GET request to download the {@link Schema}.
*
* @return schema on success.
* <P><code>null</code> on failure.
*/
@Nullable
public static Schema getSchema(@Nonnull String host, int port, @Nonnull String schemaName) {
Preconditions.checkNotNull(host);
Preconditions.checkNotNull(schemaName);
try {
URL url = new URL("http", host, port, "/schemas/" + schemaName);
GetMethod httpGet = new GetMethod(url.toString());
try {
int responseCode = HTTP_CLIENT.executeMethod(httpGet);
String response = httpGet.getResponseBodyAsString();
if (responseCode >= 400) {
// File not find error code.
if (responseCode == 404) {
LOGGER.info("Cannot find schema: {} from host: {}, port: {}", schemaName, host, port);
} else {
LOGGER.warn("Got error response code: {}, response: {}", responseCode, response);
}
return null;
}
return Schema.fromString(response);
} finally {
httpGet.releaseConnection();
}
} catch (Exception e) {
LOGGER.error("Caught exception while getting the schema: {} from host: {}, port: {}", schemaName, host, port, e);
return null;
}
}
use of org.apache.commons.httpclient.methods.GetMethod in project pinot by linkedin.
the class MultiGetRequestTest method testMultiGet.
@Test
public void testMultiGet() {
MultiGetRequest mget = new MultiGetRequest(Executors.newCachedThreadPool(), new MultiThreadedHttpConnectionManager());
List<String> urls = Arrays.asList("http://localhost:" + String.valueOf(portStart) + URI_PATH, "http://localhost:" + String.valueOf(portStart + 1) + URI_PATH, "http://localhost:" + String.valueOf(portStart + 2) + URI_PATH, // 2nd request to the same server
"http://localhost:" + String.valueOf(portStart) + URI_PATH);
// timeout value needs to be less than 5000ms set above for
// third server
final int requestTimeoutMs = 1000;
CompletionService<GetMethod> completionService = mget.execute(urls, requestTimeoutMs);
int success = 0;
int errors = 0;
int timeouts = 0;
for (int i = 0; i < urls.size(); i++) {
GetMethod getMethod = null;
try {
getMethod = completionService.take().get();
if (getMethod.getStatusCode() >= 300) {
++errors;
Assert.assertEquals(getMethod.getResponseBodyAsString(), ERROR_MSG);
} else {
++success;
Assert.assertEquals(getMethod.getResponseBodyAsString(), SUCCESS_MSG);
}
} catch (InterruptedException e) {
LOGGER.error("Interrupted", e);
++errors;
} catch (ExecutionException e) {
if (Throwables.getRootCause(e) instanceof SocketTimeoutException) {
LOGGER.debug("Timeout");
++timeouts;
} else {
LOGGER.error("Error", e);
++errors;
}
} catch (IOException e) {
++errors;
}
}
Assert.assertEquals(2, success);
Assert.assertEquals(1, errors);
Assert.assertEquals(1, timeouts);
}
Aggregations