Java Code Examples for com.mashape.unirest.http.Unirest#get()
The following examples show how to use
com.mashape.unirest.http.Unirest#get() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RestAction.java From cognitivej with Apache License 2.0 | 7 votes |
private HttpRequest buildUnirest(WorkingContext workingContext) { String url = String.format("%s%s", PROJECTOXFORD_AI, workingContext.getPathBuilt()); switch (workingContext.getHttpMethod()) { case GET: return Unirest.get(url); case PUT: return Unirest.put(url); case DELETE: return Unirest.delete(url); case PATCH: return Unirest.patch(url); } return Unirest.post(url); }
Example 2
Source File: HGQLConfigService.java From hypergraphql with Apache License 2.0 | 6 votes |
private Reader getReaderForUrl(final String schemaPath, final String username, final String password) { final GetRequest getRequest; if(username == null && password == null) { getRequest = Unirest.get(schemaPath); } else { getRequest = Unirest.get(schemaPath).basicAuth(username, password); } try { final String body = getRequest.asString().getBody(); return new StringReader(body); } catch (UnirestException e) { throw new HGQLConfigurationException("Unable to load configuration", e); } }
Example 3
Source File: ApplicationConfigurationService.java From hypergraphql with Apache License 2.0 | 6 votes |
public List<HGQLConfig> readConfigurationFromUrl(final String configUri, final String username, final String password) { final GetRequest getRequest; if(username == null && password == null) { getRequest = Unirest.get(configUri); } else { getRequest = Unirest.get(configUri).basicAuth(username, password); } try { final InputStream inputStream = getRequest.asBinary().getBody(); final HGQLConfig config = hgqlConfigService.loadHGQLConfig(configUri, inputStream, username, password, false); return Collections.singletonList(config); } catch (UnirestException e) { throw new HGQLConfigurationException("Unable to read from remote URL", e); } }
Example 4
Source File: AbstractRequest.java From alpaca-java with MIT License | 6 votes |
/** * Invoke get. * * @param abstractRequestBuilder the abstract request builder * * @return the http response */ public HttpResponse<InputStream> invokeGet(AbstractRequestBuilder abstractRequestBuilder) { try { String url = abstractRequestBuilder.getURL(); LOGGER.debug("GET URL " + url); GetRequest request = Unirest.get(url); if (!headers.isEmpty()) { request.headers(headers); LOGGER.debug("GET Headers: " + headers); } return request.asBinary(); } catch (UnirestException e) { LOGGER.error("UnirestException", e); } return null; }
Example 5
Source File: Client.java From SikuliNG with MIT License | 6 votes |
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; }
Example 6
Source File: HttpClientTest.java From apicurio-studio with Apache License 2.0 | 6 votes |
@Test public void testEncodedPath_Unirest() throws Exception { String url = new Endpoint("http://127.0.0.1:" + HTTP_PORT + "/echo/encoded%2Fpath").toString(); HttpRequest request = Unirest.get(url); HttpResponse<com.mashape.unirest.http.JsonNode> response = request.asJson(); Assert.assertEquals(200, response.getStatus()); JSONObject responseObj = response.getBody().getObject(); String method = responseObj.getString("method"); String uri = responseObj.getString("uri"); Assert.assertEquals("GET", method); // Note: Unirest messes with the encoded path, incorrectly changing it from "/echo/encoded%2Fpath" // to "/echo/encoded/path" prior to making the HTTP request. This is why Unirest is not used in // the GitLab source connector. Assert.assertEquals("/echo/encoded/path", uri); }
Example 7
Source File: AppServicePacketTransport.java From swellrt with Apache License 2.0 | 5 votes |
private BaseRequest formRequest(Request packet) { HttpRequest httpRequest = null; String url = "https://" + serverAddress + apiAddress + packet.getUrl(); String method = packet.getMethod(); switch (method) { case "GET": httpRequest = Unirest.get(url); break; case "POST": httpRequest = Unirest.post(url); break; case "PUT": httpRequest = Unirest.put(url); break; } Map<String, String> headers = packet.getHeaders(); httpRequest = httpRequest.headers(headers); Map<String, Object> queryStrings = packet.getQueryStrings(); httpRequest = httpRequest.queryString(queryStrings); BaseRequest request = httpRequest; if(!method.equals("GET")) { JSONObject body = packet.getBody(); request = ((HttpRequestWithBody)request).body(body.toString()); } return request; }
Example 8
Source File: MesosContainerImpl.java From minimesos with Apache License 2.0 | 5 votes |
@Override public JSONObject getStateInfoJSON() throws UnirestException { String stateUrl = getStateUrl(); GetRequest request = Unirest.get(stateUrl); HttpResponse<JsonNode> response = request.asJson(); return response.getBody().getObject(); }
Example 9
Source File: HttpClientTest.java From apicurio-studio with Apache License 2.0 | 5 votes |
@Test public void testSimple_Unirest() throws Exception { String url = new Endpoint("http://127.0.0.1:" + HTTP_PORT + "/echo").toString(); HttpRequest request = Unirest.get(url); HttpResponse<com.mashape.unirest.http.JsonNode> response = request.asJson(); Assert.assertEquals(200, response.getStatus()); JSONObject responseObj = response.getBody().getObject(); String method = responseObj.getString("method"); String uri = responseObj.getString("uri"); Assert.assertEquals("GET", method); Assert.assertEquals("/echo", uri); }
Example 10
Source File: CustomHttpClient.java From openvidu with Apache License 2.0 | 5 votes |
private JsonObject commonRest(HttpMethod method, String path, String body, int status) throws Exception { HttpResponse<?> jsonResponse = null; JsonObject json = null; path = openviduUrl + (path.startsWith("/") ? path : ("/" + path)); HttpRequest request = null; if (body != null && !body.isEmpty()) { switch (method) { case POST: request = Unirest.post(path); break; case PUT: request = Unirest.put(path); break; case PATCH: default: request = Unirest.patch(path); break; } ((HttpRequestWithBody) request).header("Content-Type", "application/json").body(body.replaceAll("'", "\"")); } else { switch (method) { case GET: request = Unirest.get(path); request.header("Content-Type", "application/x-www-form-urlencoded"); break; case POST: request = Unirest.post(path); break; case DELETE: request = Unirest.delete(path); request.header("Content-Type", "application/x-www-form-urlencoded"); break; case PUT: request = Unirest.put(path); default: break; } } request = request.header("Authorization", this.headerAuth); try { jsonResponse = request.asJson(); if (jsonResponse.getBody() != null) { jsonResponse.getBody(); json = JsonParser.parseString(((JsonNode) jsonResponse.getBody()).getObject().toString()) .getAsJsonObject(); } } catch (UnirestException e) { try { if (e.getCause().getCause().getCause() instanceof org.json.JSONException) { try { jsonResponse = request.asString(); } catch (UnirestException e1) { throw new Exception("Error sending request to " + path + ": " + e.getMessage()); } } else { throw new Exception("Error sending request to " + path + ": " + e.getMessage()); } } catch (NullPointerException e2) { throw new Exception("Error sending request to " + path + ": " + e.getMessage()); } } if (jsonResponse.getStatus() == 500) { log.error("Internal Server Error: {}", jsonResponse.getBody().toString()); } if (status != jsonResponse.getStatus()) { System.err.println(jsonResponse.getBody().toString()); throw new Exception(path + " expected to return status " + status + " but got " + jsonResponse.getStatus()); } return json; }
Example 11
Source File: RedmineRestClient.java From scava with Eclipse Public License 2.0 | 5 votes |
protected InputStream search(Map<String, String> filter, int startAt, int pageSize) throws UnirestException { String url = apiUrl + "issues" + JSON_SUFFIX; GetRequest getRequest = Unirest.get(url); for (Entry<String, String> entry : filter.entrySet()) { getRequest = getRequest.field(entry.getKey(), entry.getValue()); } getRequest = getRequest.field("offset", startAt); getRequest = getRequest.field("limit", pageSize); HttpResponse<InputStream> response = executeRestCall(getRequest); return response.getRawBody(); }
Example 12
Source File: SourceForgeTrackerRestClient.java From scava with Eclipse Public License 2.0 | 5 votes |
public SourceForgeTicket getTicket(int id) throws JsonParseException, JsonMappingException, IOException, UnirestException { String url = trackerUrl + id; GetRequest getRequest = Unirest.get(url); HttpResponse<InputStream> response = executeRestCall(getRequest); return ticketReader.readValue(response.getRawBody()); }
Example 13
Source File: SourceForgeDiscussionRestClient.java From scava with Eclipse Public License 2.0 | 5 votes |
public SourceForgeTopic getTopic(int forumId, String topicId) throws JsonParseException, JsonMappingException, IOException, UnirestException { String url = trackerUrl + forumId + "/thread/" + topicId; GetRequest getRequest = Unirest.get(url); HttpResponse<InputStream> response = executeRestCall(getRequest); return topicReader.readValue(response.getRawBody()); }
Example 14
Source File: JiraRestClient.java From scava with Eclipse Public License 2.0 | 5 votes |
public JiraComment getComment(String issueIdOrKey, String commentId) throws JsonProcessingException, IOException, UnirestException { String url = apiUrl + "issue/" + issueIdOrKey + "/comment/" + commentId; GetRequest getRequest = Unirest.get(url); HttpResponse<InputStream> response = executeRestCall(getRequest, null); JiraComment comment = commentReader.readValue(response.getRawBody()); comment.setBugId(issueIdOrKey); return comment; }
Example 15
Source File: JiraRestClient.java From scava with Eclipse Public License 2.0 | 5 votes |
public JiraIssue getIssue(String issueIdOrKey, String fields) throws UnirestException, JsonProcessingException, IOException { String url = apiUrl + "issue/" + issueIdOrKey; GetRequest getRequest = Unirest.get(url); HttpResponse<InputStream> response = executeRestCall(getRequest, fields); return issueReader.readValue(response.getRawBody()); }
Example 16
Source File: Client.java From pact-workshop-jvm with Apache License 2.0 | 5 votes |
private Optional<JsonNode> loadProviderJson(String dateTime) throws UnirestException { HttpRequest getRequest = Unirest.get(url + "/provider.json"); if (StringUtils.isNotEmpty(dateTime)) { getRequest = getRequest.queryString("validDate", dateTime); } HttpResponse<JsonNode> jsonNodeHttpResponse = getRequest.asJson(); if (jsonNodeHttpResponse.getStatus() == 200) { return Optional.of(jsonNodeHttpResponse.getBody()); } else { return Optional.empty(); } }
Example 17
Source File: BitbucketSourceConnector.java From apicurio-studio with Apache License 2.0 | 4 votes |
@Override public Collection<BitbucketRepository> getRepositories(String teamName) throws BitbucketException, SourceConnectorException { try { //@formatter:off Endpoint endpoint = endpoint("/repositories/:uname") .bind("uname", teamName) .queryParam("pagelen", "25"); if (!StringUtils.isEmpty(config.getRepositoryFilter())) { String filter = "name~\"" + config.getRepositoryFilter() + "\""; endpoint = endpoint.queryParam("q", filter); } //@formatter:on; String reposUrl = endpoint.toString(); Collection<BitbucketRepository> rVal = new HashSet<>(); boolean done = false; while (!done) { HttpRequest request = Unirest.get(reposUrl); addSecurityTo(request); HttpResponse<com.mashape.unirest.http.JsonNode> response = request.asJson(); JSONObject responseObj = response.getBody().getObject(); if (response.getStatus() != 200) { throw new UnirestException("Unexpected response from Bitbucket: " + response.getStatus() + "::" + response.getStatusText()); } responseObj.getJSONArray("values").forEach(obj -> { BitbucketRepository bbr = new BitbucketRepository(); JSONObject rep = (JSONObject) obj; bbr.setName(rep.getString("name")); bbr.setUuid(rep.getString("uuid")); bbr.setSlug(rep.getString("slug")); rVal.add(bbr); }); done = true; if (responseObj.has("next")) { String next = responseObj.getString("next"); if (!StringUtils.isEmpty(next) && !next.equals(reposUrl)) { done = false; reposUrl = next; } } } return rVal; } catch (UnirestException e) { throw new BitbucketException("Error getting Bitbucket teams.", e); } }
Example 18
Source File: BitbucketSourceConnector.java From apicurio-studio with Apache License 2.0 | 4 votes |
/** * @see io.apicurio.hub.api.bitbucket.IBitbucketSourceConnector#getBranches(java.lang.String, java.lang.String) */ @Override public Collection<SourceCodeBranch> getBranches(String group, String repo) throws BitbucketException, SourceConnectorException { try { //@formatter:off String branchesUrl = endpoint("/repositories/:uname/:repo/refs/branches") .bind("uname", group) .bind("repo", repo) .queryParam("pagelen", "25") .toString(); //@formatter:on; Collection<SourceCodeBranch> rVal = new HashSet<>(); boolean done = false; while (!done) { HttpRequest request = Unirest.get(branchesUrl); addSecurityTo(request); HttpResponse<com.mashape.unirest.http.JsonNode> response = request.asJson(); JSONObject responseObj = response.getBody().getObject(); if (response.getStatus() != 200) { throw new UnirestException("Unexpected response from Bitbucket: " + response.getStatus() + "::" + response.getStatusText()); } responseObj.getJSONArray("values").forEach(obj -> { JSONObject b = (JSONObject) obj; SourceCodeBranch branch = new SourceCodeBranch(); branch.setName(b.getString("name")); branch.setCommitId(b.getJSONObject("target").getString("hash")); rVal.add(branch); }); done = true; if (responseObj.has("next")) { String next = responseObj.getString("next"); if (!StringUtils.isEmpty(next) && !next.equals(branchesUrl)) { done = false; branchesUrl = next; } } } return rVal; } catch (UnirestException e) { throw new BitbucketException("Error getting Bitbucket teams.", e); } }
Example 19
Source File: BaseTestCase.java From blade with Apache License 2.0 | 4 votes |
protected HttpRequest get(String path) { log.info("[GET] {}", (origin + path)); return Unirest.get(origin + path); }
Example 20
Source File: FiltersTest.java From elepy with Apache License 2.0 | 4 votes |
protected List<Product> executeFilters(Iterable<FilterOption> options) { final var request = Unirest.get(elepy.url() + "/products"); options.forEach(option -> request.queryString(String.format("%s_%s", option.fieldName, option.filterType.getName()), option.value)); return executeRequest(request); }