protected HttpRequest get(String path) { log.info("[GET] {}", (origin + path)); return Unirest.get(origin + path); }
protected String getBodyString(String path) throws Exception { log.info("[GET] {}", (origin + path)); return Unirest.get(origin + path).asString().getBody(); }
@Test public void testListen() throws Exception { Blade blade = Blade.of(); blade.listen(9001).start().await(); try { int code = Unirest.get("http://127.0.0.1:9001").asString().getStatus(); assertEquals(404, code); } finally { blade.stop(); try { new Socket("127.0.0.1", 9001); Assert.fail("Server is still running"); } catch (ConnectException e) { } } }
@Test public void testListenAddress() throws Exception { Blade blade = Blade.of(); blade.listen("localhost", 9002).start().await(); try { int code = Unirest.get("http://localhost:9002/").asString().getStatus(); assertEquals(404, code); } finally { blade.stop(); } }
public static boolean stopServer() { try { log.trace("stopServer: trying"); String url = urlBase + "/stop"; GetRequest request = Unirest.get(url); try { HttpResponse<?> response = request.asString(); // InputStream respIS = response.getRawBody(); // String respText = IOUtils.toString(respIS, "UTF-8"); // log.trace("%s", respText); } catch (Exception ex) { log.error("%s", ex.getMessage()); } } catch (Exception e) { log.error("stopServer: %s", e.getMessage()); return false; } return true; } }
Unirest.get(BURP_API_URL) .routeParam("path", "rules") .asJsonAsync(new VulnersRestCallback(callbacks) {
Unirest.get(BURP_API_URL) .routeParam("path", "path") .queryString("path", path)
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; }
final HttpRequest request = Unirest.get(BURP_API_URL) .routeParam("path", "software") .queryString("software", software.getAlias())
public boolean isMountebankRunning() { try { HttpResponse<JsonNode> response = Unirest.get(baseUrl).asJson(); return response.getStatus() == 200; } catch (UnirestException e) { return false; } }
@Override public void orderBook() throws UnirestException { HttpResponse<String> response = Unirest.get(orderBookURL()) .asString(); unirestParamsClient.orderBook(response, BITFINEX); }
@Override public void trades() throws UnirestException { HttpResponse<String> response = Unirest.get(TRADES_URL) .queryString("limit_trades", "100") .asString(); unirestParamsClient.trades(response, BITFINEX); } }
@Override public void ticker() throws IOException, UnirestException { HttpResponse<String> response = Unirest.get(TICKER_URL) .queryString(PAIR_QUERY_KEY, PAIR_QUERY_VALUE) .asString(); unirestParamsClient.ticker(response, KRAKEN); }
@Override public void trades() throws IOException, UnirestException { HttpResponse<String> response = Unirest.get(TRADES_URL) .queryString(PAIR_QUERY_KEY, PAIR_QUERY_VALUE) .asString(); unirestParamsClient.trades(response, KRAKEN); } }
private List<Project> getProjects() throws UnirestException { if (projects != null) { return projects; } GetRequest projectsRequest = Unirest.get(apiEndPoint + "/projects").header("PRIVATE-TOKEN", privateToken); if (getRequestOK(projectsRequest)) { String json = projectsRequest.asJson().getBody().getArray().toString(); projects = Arrays.asList(mapper.readValue(json, Project[].class)); } return projects; }
@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; } }
@Override public JSONObject getStateInfoJSON() throws UnirestException { String stateUrl = getStateUrl(); GetRequest request = Unirest.get(stateUrl); HttpResponse<JsonNode> response = request.asJson(); return response.getBody().getObject(); }
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")); }