protected String postBodyString(String path) throws Exception { log.info("[POST] {}", (origin + path)); return Unirest.post(origin + path).asString().getBody(); }
protected String getBodyString(String path) throws Exception { log.info("[GET] {}", (origin + path)); return Unirest.get(origin + path).asString().getBody(); }
protected String putBodyString(String path) throws Exception { log.info("[PUT] {}", (origin + path)); return Unirest.put(origin + path).asString().getBody(); }
protected String deleteBodyString(String path) throws Exception { log.info("[DELETE] {}", (origin + path)); return Unirest.delete(origin + path).asString().getBody(); }
protected String bodyToString(String path) throws Exception { return get(path).asString().getBody(); }
public void completed(HttpResponse<JsonNode> response) { JSONObject responseBody = response.getBody().getObject(); if ("ERROR".equals(responseBody.getString("result"))) { onFail((JSONObject) responseBody.get("data")); return; } onSuccess(responseBody.getJSONObject("data")); }
public static JSONObject get(String urlCommand) { log.trace("get: %s", urlCommand); HttpResponse<JsonNode> jsonResponse = null; JSONObject response = null; try { jsonResponse = Unirest.get(urlBase + urlCommand) .header("accept", "application/json") .asJson(); } catch (UnirestException e) { log.error("get: %s", e.getMessage()); } String responseBody = "null"; if (SX.isNotNull(jsonResponse)) { responseBody = jsonResponse.getBody().toString(); response = SXJson.makeObject(responseBody); } log.trace("get: response: %s",jsonResponse.getBody().toString()); return response; }
public static JSONObject post(String urlCommand, String body) { log.trace("post: %s body: %s", urlCommand, body); HttpResponse<JsonNode> jsonResponse = null; JSONObject response = null; try { jsonResponse = Unirest.post(urlBase + urlCommand) .header("accept", "application/json") .header("content-type", "application/json") .body(body) .asJson(); } catch (UnirestException e) { log.error("post(): %s", e.getMessage()); } String responseBody = "null"; if (SX.isNotNull(jsonResponse)) { responseBody = jsonResponse.getBody().toString(); response = SXJson.makeObject(responseBody); } log.trace("post: response: %s", responseBody); return response; }
@Override public void completed(HttpResponse<JsonNode> response) { int code = response.getStatus(); JsonNode body = response.getBody(); System.out.println("Status Code: " + code); System.out.println(body.toString()); }
public Integer getDocumentCount(String httpAddress) throws UnirestException { JSONArray responseElements = Unirest.get("http://" + httpAddress + "/_count").asJson().getBody().getArray(); LOGGER.debug(responseElements); return responseElements.getJSONObject(0).getInt("count"); }
static UploadRequestResponse makeUploadRequest(HttpResponse<String> uploadRequest) { int status = uploadRequest.getStatus(); String body = uploadRequest.getBody(); logger.fine("Got " + status + " with body: " + body); return new UploadRequestResponse(uploadRequest.getStatus(), body); }
private List<MergeRequest> getMergeRequests(Integer projectId) throws UnirestException { GetRequest mergeRequestsRequest = Unirest.get(apiEndPoint + "/projects/"+projectId.toString()+"/merge_requests?state=merged").header("PRIVATE-TOKEN", privateToken); if (getRequestOK(mergeRequestsRequest)) { String json = mergeRequestsRequest.asJson().getBody().getArray().toString(); return Arrays.asList(mapper.readValue(json, MergeRequest[].class)); } return null; }
public static HtmlAnalysisResult analyze(Map<String, String> config, String url) { try { String userAgent = config.getOrDefault(CONFIG_USER_AGENT, DEFAULT_USER_AGENT); HttpResponse<String> response = Unirest.get(url) .header("User-Agent", userAgent) .asString(); return analyze(config, url, response.getBody(), response.getStatus(), response.getHeaders()); } catch (UnirestException e) { throw new RuntimeException(e); } }
@Override public Boolean call() throws Exception { try { Unirest.get(getServiceUrl().toString() + APPS_ENDPOINT).header(HEADER_ACCEPT, APPLICATION_JSON).asJson().getBody().getObject(); } catch (UnirestException e) { //NOSONAR // meaning API is not ready return false; } return true; } }
public static void main(String[] args) throws UnirestException { HttpResponse<JsonNode> jsonResponse = Unirest.post("http://httpbin.org/post") .header("accept", "application/json") .body("{\"parameter\":\"value\", \"foo\":\"bar\"}") .asJson(); System.out.println(jsonResponse.getBody().toString()); } }
@Override public JSONObject getStateInfoJSON() throws UnirestException { String stateUrl = getStateUrl(); GetRequest request = Unirest.get(stateUrl); HttpResponse<JsonNode> response = request.asJson(); return response.getBody().getObject(); }
static public JsonNode post(String url, JSONObject json) { HttpResponse<JsonNode> jsonResponse = null; try { jsonResponse = Unirest.post(url).header("content-type", "application/json").body(json).asJson(); } catch (UnirestException e) { unirestCrash(e); } return jsonResponse.getBody(); }
private void whenTheCapacityIsRetrievedForExchange(String exchangeCode) throws UnirestException { String apiPath = GetCapacityForExchangeEndpoint.API_PATH.replace("{exchangeCode}", exchangeCode); String apiUrl = "http://localhost:8080" + apiPath; log("API Url", apiUrl); HttpResponse<String> httpResponse = Unirest.get(apiUrl).asString(); responseStatus = httpResponse.getStatus(); log("Response Status", responseStatus); responseContent = httpResponse.getBody(); log("Response Content", formatJson(responseContent)); }
private void whenTheApiToGetTheDeviceDetailsIsCalledForThatDevice() throws UnirestException { String apiPath = GetBroadbandAccessDeviceEndpoint.API_PATH.replace("{hostname}", HOSTNAME); String apiUrl = "http://localhost:8080" + apiPath; log("API Url", apiUrl); HttpResponse<String> httpResponse = Unirest.get(apiUrl).asString(); responseStatus = httpResponse.getStatus(); log("Response Status", responseStatus); responseContent = httpResponse.getBody(); log("Response Content", formatJson(responseContent)); }
@Test public void shouldStartAndServeFile() throws UnknownHostException, UnirestException, InterruptedException { final SimpleFileServer simpleFileServer = new SimpleFileServer(TEST_FILE); simpleFileServer.run(); InetSocketAddress address = simpleFileServer.getAddress(); String serverAddress = NetworkUtils.addressToString(address, true); HttpResponse<String> response = Unirest.get(serverAddress + "/get").asString(); assertEquals(200, response.getStatus()); assertTrue(response.getBody().contains("This is a test file")); }