Search in sources :

Example 46 with JsonNode

use of com.mashape.unirest.http.JsonNode in project InciDashboard_i3a by Arquisoft.

the class OperatorService method authenticate.

public static HttpResponse<JsonNode> authenticate(String login, String password) {
    Map<String, String> map = new HashMap<>();
    HttpResponse<JsonNode> response = null;
    map.put("email", login);
    map.put("password", password);
    try {
        response = Unirest.post(API_GATEWAY + "/auth").header("Content-Type", "application/json").body(new JSONObject(map)).asJson();
        if (response.getStatus() == HttpStatus.SC_OK) {
            log.debug("Login succeded");
        } else {
            log.debug("The login didn't succeded");
        }
    } catch (UnirestException e) {
        log.debug("The login didn't succeded");
    }
    return response;
}
Also used : JSONObject(org.json.JSONObject) HashMap(java.util.HashMap) UnirestException(com.mashape.unirest.http.exceptions.UnirestException) JsonNode(com.mashape.unirest.http.JsonNode)

Example 47 with JsonNode

use of com.mashape.unirest.http.JsonNode in project InciDashboard_i3a by Arquisoft.

the class OperatorService method getAllOperators.

public static List<Operator> getAllOperators() {
    try {
        HttpResponse<JsonNode> response = Unirest.post(API_GATEWAY + "/operators").asJson();
        ObjectMapper mapper = new ObjectMapper();
        List<Operator> items = mapper.readValue(response.getBody().toString(), mapper.getTypeFactory().constructParametricType(List.class, Operator.class));
        return items;
    } catch (IOException | UnirestException e) {
        e.printStackTrace();
        return null;
    }
}
Also used : Operator(io.github.asw.i3a.operatorsWebClient.entitites.Operator) UnirestException(com.mashape.unirest.http.exceptions.UnirestException) JsonNode(com.mashape.unirest.http.JsonNode) List(java.util.List) IOException(java.io.IOException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

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