use of com.mashape.unirest.http.JsonNode in project textdb by TextDB.
the class AsterixSource method open.
@Override
public void open() throws TexeraException {
if (cursor == OPENED) {
return;
}
try {
String asterixAddress = "http://" + predicate.getHost() + ":" + predicate.getPort() + "/query/service";
String asterixQuery = generateAsterixQuery(predicate);
HttpResponse<JsonNode> jsonResponse = Unirest.post(asterixAddress).queryString("statement", asterixQuery).field("mode", "immediate").asJson();
// if status is 200 OK, store the results
if (jsonResponse.getStatus() == 200) {
this.resultJsonArray = jsonResponse.getBody().getObject().getJSONArray("results");
} else {
throw new DataflowException("Send query to asterix failed: " + "error status: " + jsonResponse.getStatusText() + ", " + "error body: " + jsonResponse.getBody().toString());
}
cursor = OPENED;
} catch (UnirestException e) {
throw new DataflowException(e);
}
}
use of com.mashape.unirest.http.JsonNode in project tutorials by eugenp.
the class HttpClientTest method givenInputStreamWhenUploadedThenCorrect.
// @Test
public void givenInputStreamWhenUploadedThenCorrect() throws UnirestException, IOException {
try (InputStream inputStream = new FileInputStream(new File("/path/to/file/artcile.txt"))) {
HttpResponse<JsonNode> jsonResponse = Unirest.post("http://www.mocky.io/v2/5a9ce7663100006800ab515d").field("file", inputStream, ContentType.APPLICATION_OCTET_STREAM, "article.txt").asJson();
assertEquals(201, jsonResponse.getStatus());
}
}
use of com.mashape.unirest.http.JsonNode in project tutorials by eugenp.
the class HttpClientTest method givenArticleWhenCreatedThenCorrect.
@Test
public void givenArticleWhenCreatedThenCorrect() throws UnirestException {
Article article = new Article("ID1213", "Guide to Rest", "baeldung");
HttpResponse<JsonNode> jsonResponse = Unirest.post("http://www.mocky.io/v2/5a9ce7663100006800ab515d").body(article).asJson();
assertEquals(201, jsonResponse.getStatus());
}
use of com.mashape.unirest.http.JsonNode in project tutorials by eugenp.
the class HttpClientTest method givenByteStreamWhenUploadedThenCorrect.
// @Test
public void givenByteStreamWhenUploadedThenCorrect() throws IOException, UnirestException {
try (InputStream inputStream = new FileInputStream(new File("/path/to/file/artcile.txt"))) {
byte[] bytes = new byte[inputStream.available()];
inputStream.read(bytes);
HttpResponse<JsonNode> jsonResponse = Unirest.post("http://www.mocky.io/v2/5a9ce7663100006800ab515d").field("file", bytes, "article.txt").asJson();
assertEquals(201, jsonResponse.getStatus());
}
}
use of com.mashape.unirest.http.JsonNode in project goci by EBISPOT.
the class EnsemblMappingPipeline method getOverlapRegionCalls.
/**
* Ensembl REST API call for the overlap region endpoint
*
* @param chromosome the chromosome name
* @param position1 the 5' position of the region
* @param position2 the 3' position of the region
* @param rest_opt the extra parameters to add at the end of the REST call url (inherited from other methods)
* @return A JSONArray object containing a list of JSONObjects corresponding to the genes overlapping the region
*/
private JSONArray getOverlapRegionCalls(String chromosome, Integer position1, Integer position2, String rest_opt, String eRelease) throws EnsemblRestIOException {
String data = chromosome + ":" + position1 + "-" + position2;
String param = data.concat("?").concat(rest_opt);
RestResponseResult restResponseResult = ensemblRestcallHistoryService.getEnsemblRestCallByTypeAndParamAndVersion("overlap_region", param, eRelease);
if (restResponseResult == null) {
restResponseResult = ensemblRestTemplateService.getRestCall("overlap_region", data, rest_opt);
ensemblRestcallHistoryService.create(restResponseResult, "overlap_region", param, eRelease);
}
JsonNode result = restResponseResult.getRestResult();
JSONArray overlap_result = new JSONArray();
if (result != null && result.isArray()) {
overlap_result = result.getArray();
} else {
// Errors
getEnsemblMappingResult().addPipelineErrors(restResponseResult.getError());
overlap_result = new JSONArray("[{\"overlap_error\":\"1\"}]");
}
return overlap_result;
}
Aggregations