@Override protected JsonNode parse(Http.RequestHeader request, ByteString bytes) throws Exception { return play.libs.Json.parse(bytes.iterator().asInputStream()); } }
@Override protected JsonNode parse(Http.RequestHeader request, ByteString bytes) throws Exception { return play.libs.Json.parse(bytes.iterator().asInputStream()); } }
/** * Set a Json Body to this request. * The <tt>Content-Type</tt> header of the request is set to <tt>application/json</tt>. * * @param json the JsValue * @return the modified builder */ public RequestBuilder bodyJson(JsValue json) { return bodyJson(Json.parse(play.api.libs.json.Json.stringify(json))); }
@Override protected JsonNode parse(Http.RequestHeader request, ByteString bytes) throws Exception { return play.libs.Json.parse(bytes.iterator().asInputStream()); } }
/** * Set a Json Body to this request. * The <tt>Content-Type</tt> header of the request is set to <tt>application/json</tt>. * * @param json the JsValue * @return the modified builder */ public RequestBuilder bodyJson(JsValue json) { return bodyJson(Json.parse(play.api.libs.json.Json.stringify(json))); }
/** * Set a Json Body to this request. * The <tt>Content-Type</tt> header of the request is set to <tt>application/json</tt>. * * @param json the JsValue * @return the modified builder */ public RequestBuilder bodyJson(JsValue json) { return bodyJson(Json.parse(play.api.libs.json.Json.stringify(json))); }
/** * Get the response body as a {@link JsonNode} * * @return the json response */ @Override public JsonNode asJson() { // Jackson will automatically detect the correct encoding according to the rules in RFC-4627 return Json.parse(ahcResponse.getResponseBodyAsStream()); }
public DataField[] getRemoteStructure() throws IOException, ClassNotFoundException { HttpGet get = new HttpGet(wsURL + "/api/sensors/" + vsName); try { String content = doRequest(get); JsonNode jn = Json.parse(content).get("properties"); DataField[] df = new DataField[jn.get("fields").size()-1]; int i = 0; for(JsonNode f : jn.get("fields")){ if (f.get("name").asText().equals("timestamp")) continue; df[i] = new DataField(f.get("name").asText(),f.get("type").asText()); i++; } return df; } catch (Exception e){ logger.error(e.getMessage(), e); } return null; }
/** * {@inheritDoc} */ @Override public <U> Optional<U> findObjectByKey(final String key, final Class<U> clazz) { return findValueByKey(key) .flatMap(valueAsJson -> { try { final U value = Json.fromJson(Json.parse(valueAsJson), clazz); return Optional.of(value); } catch (RuntimeException e) { logger.error("Could not parse value in session key \"{}\" into type \"{}\"", key, clazz.getSimpleName(), e); return Optional.empty(); } }); }
public String getToken(){ HttpPost post = new HttpPost(wsURL + "/oauth2/token"); List<BasicNameValuePair> parametersBody = new ArrayList<BasicNameValuePair>(); parametersBody.add(new BasicNameValuePair("grant_type", "client_credentials")); parametersBody.add(new BasicNameValuePair("client_id", clientId)); parametersBody.add(new BasicNameValuePair("client_secret", clientSecret)); HttpResponse response = null; try { post.setEntity(new UrlEncodedFormEntity(parametersBody, StandardCharsets.UTF_8)); response = client.execute(post); int code = response.getStatusLine().getStatusCode(); if (code == 401) { // Add Basic Authorization header post.addHeader("Authorization",Base64.encodeBase64String((clientId+":"+clientSecret).getBytes())); post.releaseConnection(); response = client.execute(post); code = response.getStatusLine().getStatusCode(); } if (code == 200){ String content = EntityUtils.toString(response.getEntity()); return Json.parse(content).get("access_token").asText(); } } catch (Exception e){ logger.error(e.getMessage(), e); } return null; }
JsonNode jn = Json.parse(s).get("properties"); DataField[] df = new DataField[jn.get("fields").size()-1]; int i = 0;