Search in sources :

Example 31 with JsonNode

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);
    }
}
Also used : DataflowException(edu.uci.ics.texera.api.exception.DataflowException) UnirestException(com.mashape.unirest.http.exceptions.UnirestException) JsonNode(com.mashape.unirest.http.JsonNode)

Example 32 with JsonNode

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());
    }
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) JsonNode(com.mashape.unirest.http.JsonNode) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 33 with JsonNode

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());
}
Also used : Article(com.baeldung.unirest.Article) JsonNode(com.mashape.unirest.http.JsonNode) Test(org.junit.Test)

Example 34 with JsonNode

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());
    }
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) JsonNode(com.mashape.unirest.http.JsonNode) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 35 with JsonNode

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;
}
Also used : JSONArray(org.json.JSONArray) RestResponseResult(uk.ac.ebi.spot.goci.model.RestResponseResult) JsonNode(com.mashape.unirest.http.JsonNode)

Aggregations

JsonNode (com.mashape.unirest.http.JsonNode)47 UnirestException (com.mashape.unirest.http.exceptions.UnirestException)20 JSONObject (org.json.JSONObject)19 IOException (java.io.IOException)14 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)12 JSONArray (org.json.JSONArray)11 RestResponseResult (uk.ac.ebi.spot.goci.model.RestResponseResult)5 Incident (io.github.asw.i3a.operatorsWebClient.entitites.Incident)4 List (java.util.List)4 ActionException (org.apache.zeppelin.elasticsearch.action.ActionException)4 ActionResponse (org.apache.zeppelin.elasticsearch.action.ActionResponse)4 HitWrapper (org.apache.zeppelin.elasticsearch.action.HitWrapper)4 JSONException (org.json.JSONException)4 Gson (com.google.gson.Gson)3 Type (java.lang.reflect.Type)3 JsonObjectBuilder (javax.json.JsonObjectBuilder)3 Test (org.junit.Test)3 RestTemplate (org.springframework.web.client.RestTemplate)3 HttpResponse (com.mashape.unirest.http.HttpResponse)2 HttpRequest (com.mashape.unirest.request.HttpRequest)2