本文整理汇总了Java中com.mashape.unirest.http.JsonNode类的典型用法代码示例。如果您正苦于以下问题:Java JsonNode类的具体用法?Java JsonNode怎么用?Java JsonNode使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
JsonNode类属于com.mashape.unirest.http包,在下文中一共展示了JsonNode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: processHttpRequest
import com.mashape.unirest.http.JsonNode; //导入依赖的package包/类
public static String processHttpRequest(String completeURL,
Map<String, Object> params,
Map<String, String> customHeaders,
HttpMethod method) throws IOException {
Map<String, String> headers = getDefaultHeader();
if (customHeaders != null) {
headers.putAll(customHeaders);
}
HttpResponse<JsonNode> result = executeHttpMethod(completeURL, params, headers, method);
if (result == null) {
return null;
}
if (result.getStatus() != 200) {
String exceptionResponse = result.getBody().toString();
throw new ServiceException((result.getStatus() + result.getStatusText()),
exceptionResponse);
}
return result.getBody().toString();
}
示例2: fetchSchemaFromRemote
import com.mashape.unirest.http.JsonNode; //导入依赖的package包/类
public static String fetchSchemaFromRemote(String url, String basicAuthUsername, String basicAuthPassword) {
Map<String, String> bodyMap = new HashMap<>();
bodyMap.put("query", introspectionQuery());
bodyMap.put("variables", null);
HttpRequestWithBody requestWithBody = Unirest.post(url)
.header("Content-Type", "application/json")
.header("accept", "application/json");
// basic auth
if (basicAuthUsername != null && basicAuthPassword != null) {
requestWithBody.basicAuth(basicAuthUsername, basicAuthPassword);
}
// body
RequestBodyEntity requestBodyEntity = requestWithBody.body(bodyMap);
HttpResponse<JsonNode> jsonNodeHttpResponse;
try {
jsonNodeHttpResponse = requestBodyEntity.asJson();
} catch (UnirestException e) {
throw new RuntimeException(e);
}
return Util.convertStreamToString(jsonNodeHttpResponse.getRawBody(), "UTF-8");
}
示例3: getAsJSONObject
import com.mashape.unirest.http.JsonNode; //导入依赖的package包/类
/**
* @return The json object get by performing request.
*/
public JSONObject getAsJSONObject() {
JSONObject json;
try {
HttpResponse<JsonNode> response = request.asJson();
checkRateLimit(response);
handleErrorCode(response);
JsonNode node = response.getBody();
if (node.isArray()) {
throw new UnirestException("The request returns a JSON Array. Json: "+node.getArray().toString(4));
} else {
json = node.getObject();
}
} catch (UnirestException e) {
throw new JSONException("Error Occurred while getting JSON Object: "+e.getLocalizedMessage());
}
handleErrorResponse(json);
return json;
}
示例4: getAsJSONArray
import com.mashape.unirest.http.JsonNode; //导入依赖的package包/类
/**
* @return The json array get by performing request.
*/
public JSONArray getAsJSONArray() {
JSONArray json;
try {
HttpResponse<JsonNode> response = request.asJson();
checkRateLimit(response);
handleErrorCode(response);
JsonNode node = response.getBody();
if (!node.isArray()) {
handleErrorResponse(node.getObject());
throw new UnirestException("The request returns a JSON Object. Json: "+node.getObject().toString(4));
} else {
json = node.getArray();
}
} catch (UnirestException e) {
throw new JSONException("Error Occurred while getting JSON Array: "+e.getLocalizedMessage());
}
return json;
}
示例5: test
import com.mashape.unirest.http.JsonNode; //导入依赖的package包/类
@Test
public void test() throws UnirestException {
gitHubSourceTask.config = new GitHubSourceConnectorConfig(initialConfig());
gitHubSourceTask.nextPageToVisit = 1;
gitHubSourceTask.nextQuerySince = Instant.parse("2017-01-01T00:00:00Z");
gitHubSourceTask.gitHubHttpAPIClient = new GitHubAPIHttpClient(gitHubSourceTask.config);
String url = gitHubSourceTask.gitHubHttpAPIClient.constructUrl(gitHubSourceTask.nextPageToVisit, gitHubSourceTask.nextQuerySince);
System.out.println(url);
HttpResponse<JsonNode> httpResponse = gitHubSourceTask.gitHubHttpAPIClient.getNextIssuesAPI(gitHubSourceTask.nextPageToVisit, gitHubSourceTask.nextQuerySince);
if (httpResponse.getStatus() != 403) {
assertEquals(200, httpResponse.getStatus());
Set<String> headers = httpResponse.getHeaders().keySet();
assertTrue(headers.contains("ETag"));
assertTrue(headers.contains("X-RateLimit-Limit"));
assertTrue(headers.contains("X-RateLimit-Remaining"));
assertTrue(headers.contains("X-RateLimit-Reset"));
assertEquals(batchSize.intValue(), httpResponse.getBody().getArray().length());
JSONObject jsonObject = (JSONObject) httpResponse.getBody().getArray().get(0);
Issue issue = Issue.fromJson(jsonObject);
assertNotNull(issue);
assertNotNull(issue.getNumber());
assertEquals(2072, issue.getNumber().intValue());
}
}
示例6: readUsers
import com.mashape.unirest.http.JsonNode; //导入依赖的package包/类
@Override
public List<User> readUsers(String locatie) {
try {
HttpResponse<JsonNode> getResponse = Unirest
.get("http://localhost:8080/openidm/managed/user?_prettyPrint=true&_queryId=query-all")
.header("Accept", "application/json")
.header("Content-Type", "application/json")
.header("X-Requested-With", "Swagger-UI")
.header("X-OpenIDM-Username", "openidm-admin")
.header("X-OpenIDM-Password", "openidm-admin")
.asJson();
JSONObject body = getResponse.getBody().getObject();
System.out.println(body.toString(4));
JSONArray users = body.getJSONArray("result");
List<User> result = new ArrayList<>();
for (int i = 0, maxi = users.length(); i < maxi; i++) {
result.add(toUser((JSONObject) users.get(i)));
}
return result;
} catch (UnirestException e) {
throw new RuntimeException("Wrapped checked exception.", e);
}
}
示例7: reloadCMCPrice
import com.mashape.unirest.http.JsonNode; //导入依赖的package包/类
private void reloadCMCPrice() {
try {
HttpResponse<JsonNode> jsonResponse = Unirest.get("https://api.coinmarketcap.com/v1/ticker").asJson();
JSONArray body = jsonResponse.getBody().getArray();
synchronized (cmcCurrencies) {
cmcCurrencies.clear();
for (int i = 0; i < body.length(); i++) {
JSONObject currency = body.getJSONObject(i);
cmcCurrencies.add(new CurrencyData(currency.getString("name"), currency.getString("symbol"), !currency.isNull("price_btc") ? currency.getString("price_btc") : "0", !currency.isNull("price_usd") ? currency.getString("price_usd") : "0", !currency.isNull("market_cap_usd") ? currency.getString("market_cap_usd") : "0", !currency.isNull("percent_change_24h") ? currency.getString("percent_change_24h") : "0"));
}
CurrencyData btc = getCurrencyByCode("BTC");
cmcCurrencies.add(new CurrencyData("American Dollar", "USD", 1 / btc.getUsdPrice(), 1, 0, 0, false));
cmcCurrencies.add(new CurrencyData("Milli-Bitcoin", "mBTC", 0.001, btc.getUsdPrice() / 1000, btc.getMarketCap(), btc.getPctChange24h(), false));
cmcCurrencies.add(new CurrencyData("Satoshi", "Sat", 0.00000001, btc.getUsdPrice() / 100000000, btc.getMarketCap(), btc.getPctChange24h(), false));
}
lastCoinMarketCapUpdate = System.currentTimeMillis();
} catch (Exception e) {
e.printStackTrace();
}
}
示例8: parse
import com.mashape.unirest.http.JsonNode; //导入依赖的package包/类
public <T> Results<T> parse(JsonNode jsonNode, Class<? extends ApiObject> apiObject) {
LOGGER.debug("Parsing JSON node");
final Results<T> results = new Results<>();
final JSONObject root = jsonNode.getObject();
results.setPage(root.getInt("current_page"));
results.setTotal(root.getInt("total_entries"));
results.setRawResults(jsonNode.toString());
final JSONArray rso = root.getJSONArray("results");
if (Product.class == apiObject) {
results.setResults(parseProducts(rso));
} else if (Vendor.class == apiObject) {
results.setResults(parseVendors(rso));
} else if (Version.class == apiObject) {
results.setResults(parseVersions(rso));
} else if (Vulnerability.class == apiObject) {
results.setResults(parseVulnerabilities(rso));
}
return results;
}
示例9: getToken
import com.mashape.unirest.http.JsonNode; //导入依赖的package包/类
@Override
public String getToken(String code) throws UnirestException {
HttpResponse<JsonNode> response = Unirest.post("https://www.googleapis.com/oauth2/v4/token")
.header("User-Agent", "pxls.space")
.field("grant_type", "authorization_code")
.field("code", code)
.field("redirect_uri", getCallbackUrl())
.field("client_id", App.getConfig().getString("oauth.google.key"))
.field("client_secret", App.getConfig().getString("oauth.google.secret"))
.asJson();
JSONObject json = response.getBody().getObject();
if (json.has("error")) {
return null;
} else {
return json.getString("access_token");
}
}
示例10: getToken
import com.mashape.unirest.http.JsonNode; //导入依赖的package包/类
public String getToken(String code) throws UnirestException {
HttpResponse<JsonNode> response = Unirest.post("https://oauth.vk.com/access_token")
.header("User-Agent", "pxls.space")
.field("grant_type", "authorization_code")
.field("code", code)
.field("redirect_uri", getCallbackUrl())
.field("client_id", App.getConfig().getString("oauth.vk.key"))
.field("client_secret", App.getConfig().getString("oauth.vk.secret"))
.asJson();
JSONObject json = response.getBody().getObject();
if (json.has("error")) {
return null;
} else {
return json.getString("access_token");
}
}
示例11: getIdentifier
import com.mashape.unirest.http.JsonNode; //导入依赖的package包/类
public String getIdentifier(String token) throws UnirestException, InvalidAccountException {
HttpResponse<JsonNode> me = Unirest.get("https://api.vk.com/method/users.get?access_token=" + token)
.header("User-Agent", "pxls.space")
.asJson();
JSONObject json = me.getBody().getObject();
if (json.has("error")) {
return null;
} else {
try {
return Integer.toString(json.getJSONArray("response").getJSONObject(0).getInt("uid"));
} catch (JSONException e) {
return null;
}
}
}
示例12: getIdentifier
import com.mashape.unirest.http.JsonNode; //导入依赖的package包/类
public String getIdentifier(String token) throws UnirestException, InvalidAccountException {
String[] codes = token.split("\\|");
HttpResponse<JsonNode> me = Unirest.get("https://api.tumblr.com/v2/user/info?" + getOauthRequest("https://api.tumblr.com/v2/user/info", "oauth_token="+codes[0], "oob", "GET", codes[1]))
.header("User-Agent", "pxls.space")
.asJson();
JSONObject json = me.getBody().getObject();
if (json.has("error")) {
return null;
} else {
try {
return json.getJSONObject("response").getJSONObject("user").getString("name");
} catch (JSONException e) {
return null;
}
}
}
示例13: getToken
import com.mashape.unirest.http.JsonNode; //导入依赖的package包/类
public String getToken(String code) throws UnirestException {
HttpResponse<JsonNode> response = Unirest.post("https://discordapp.com/api/oauth2/token")
.header("User-Agent", "pxls.space")
.field("grant_type", "authorization_code")
.field("code", code)
.field("redirect_uri", getCallbackUrl())
.basicAuth(App.getConfig().getString("oauth.discord.key"), App.getConfig().getString("oauth.discord.secret"))
.asJson();
JSONObject json = response.getBody().getObject();
if (json.has("error")) {
return null;
} else {
return json.getString("access_token");
}
}
示例14: getIdentifier
import com.mashape.unirest.http.JsonNode; //导入依赖的package包/类
public String getIdentifier(String token) throws UnirestException, InvalidAccountException {
HttpResponse<JsonNode> me = Unirest.get("https://discordapp.com/api/users/@me")
.header("Authorization", "Bearer " + token)
.header("User-Agent", "pxls.space")
.asJson();
JSONObject json = me.getBody().getObject();
if (json.has("error")) {
return null;
} else {
long id = json.getLong("id");
long signupTimeMillis = (id >> 22) + 1420070400000L;
long ageMillis = System.currentTimeMillis() - signupTimeMillis;
long minAgeMillis = App.getConfig().getDuration("oauth.discord.minAge", TimeUnit.MILLISECONDS);
if (ageMillis < minAgeMillis){
long days = minAgeMillis / 86400 / 1000;
throw new InvalidAccountException("Account too young");
}
return json.getString("id");
}
}
示例15: getToken
import com.mashape.unirest.http.JsonNode; //导入依赖的package包/类
public String getToken(String code) throws UnirestException {
HttpResponse<JsonNode> response = Unirest.post("https://www.reddit.com/api/v1/access_token")
.header("User-Agent", "pxls.space")
.field("grant_type", "authorization_code")
.field("code", code)
.field("redirect_uri", getCallbackUrl())
.basicAuth(App.getConfig().getString("oauth.reddit.key"), App.getConfig().getString("oauth.reddit.secret"))
.asJson();
JSONObject json = response.getBody().getObject();
if (json.has("error")) {
return null;
} else {
return json.getString("access_token");
}
}