/** * upload file to browser * @param fileName name of the file to upload * @param base64Content content of the file, encoded in base 64 */ @Override public void uploadFileToBrowser(String fileName, String base64Content) { if (nodeUrl == null) { throw new ScenarioException("You cannot upload file to browser before driver has been created and corresponding node instanciated"); } logger.info("uploading file to browser: " + fileName); try { Unirest.post(String.format("%s%s", nodeUrl, NODE_TASK_SERVLET)) .queryString("action", "uploadFile") .queryString("content", base64Content) .queryString("name", fileName) .asString(); } catch (UnirestException e) { logger.warn(String.format("Could send keys: %s", e.getMessage())); } }
/** * Left clic on desktop at x,y * @param x x coordinate * @param y y coordinate */ @Override public void leftClic(int x, int y) { if (nodeUrl == null) { throw new ScenarioException("You cannot clic left before driver has been created and corresponding node instanciated"); } logger.info(String.format("clic left: %d,%d", x, y)); try { Unirest.post(String.format("%s%s", nodeUrl, NODE_TASK_SERVLET)) .queryString("action", "leftClic") .queryString("x", x) .queryString("y", y) .asString(); } catch (UnirestException e) { logger.warn(String.format("Could not clic left: %s", e.getMessage())); } }
/** * right clic on desktop at x,y * @param x x coordinate * @param y y coordinate */ @Override public void rightClic(int x, int y) { if (nodeUrl == null) { throw new ScenarioException("You cannot clic right before driver has been created and corresponding node instanciated"); } logger.info(String.format("clic right: %d,%d", x, y)); try { Unirest.post(String.format("%s%s", nodeUrl, NODE_TASK_SERVLET)) .queryString("action", "rightClic") .queryString("x", x) .queryString("y", y) .asString(); } catch (UnirestException e) { logger.warn(String.format("Could not clic right: %s", e.getMessage())); } }
/** * Kill process * @param processName */ @Override public void killProcess(String processName) { if (nodeUrl == null) { throw new ScenarioException("You cannot kill a remote process before driver has been created and corresponding node instanciated"); } logger.info("killing process: " + processName); try { Unirest.post(String.format("%s%s", nodeUrl, NODE_TASK_SERVLET)) .queryString("action", "kill") .queryString("process", processName).asString(); } catch (UnirestException e) { logger.warn(String.format("Could not kill process %s: %s", processName, e.getMessage())); } }
/** * Write text to desktop using keyboard * @param text */ @Override public void writeText(String text) { if (nodeUrl == null) { throw new ScenarioException("You cannot write text before driver has been created and corresponding node instanciated"); } logger.info("writing text: " + text); try { Unirest.post(String.format("%s%s", nodeUrl, NODE_TASK_SERVLET)) .queryString("action", "writeText") .queryString("text", text).asString(); } catch (UnirestException e) { logger.warn(String.format("Could not write text: %s", e.getMessage())); } }
/** * Send keys to desktop * @param keys */ @Override public void sendKeysWithKeyboard(List<Integer> keyCodes) { if (nodeUrl == null) { throw new ScenarioException("You cannot use keyboard before driver has been created and corresponding node instanciated"); } String keyCodeString = String.join(",", keyCodes .stream() .map(k -> Integer.toString(k)) .collect(Collectors.toList())); logger.info("sending keys: " + keyCodes); try { Unirest.post(String.format("%s%s", nodeUrl, NODE_TASK_SERVLET)) .queryString("action", "sendKeys") .queryString("keycodes", keyCodeString).asString(); } catch (UnirestException e) { logger.warn(String.format("Could send keys: %s", e.getMessage())); } }
/** * Call BosonNLP word segmenter API via Java library Unirest. * * @param target, the text to be processed * @throws JSONException * @throws UnirestException * @throws IOException */ public void segment(String target) throws JSONException, UnirestException, IOException { // Clean the word token this.words.clear(); // Get the new word token of target String body = new JSONArray(new String[] { target }).toString(); HttpResponse<JsonNode> jsonResponse = Unirest.post(this.TAG_URL) .queryString("space_mode", this.spaceMode) .queryString("oov_level", this.oovLevel) .queryString("t2s", this.t2s) .queryString("special_char_conv", this.specialCharConv) .header("Accept", "application/json") .header("X-Token", this.BOSONNLP_API_TOKEN).body(body).asJson(); makeToken(jsonResponse.getBody()); }
public static UserProfilePhotos createUserProfilePhotos(long user_id, TelegramBot telegramBot) { try { JSONObject json = Unirest.post(telegramBot.getBotAPIUrl() + "getUserProfilePhotos") .queryString("user_id", user_id).asJson().getBody().getObject(); if(json.getBoolean("ok")) { return new UserProfilePhotosImpl(json.getJSONObject("result")); } } catch (UnirestException e) { e.printStackTrace(); } return null; }
public EmailResponse sendPlainText(Email email) { HttpRequestWithBody requestWithBody = Unirest.post("https://{url}/{version}/{domain}/messages") .routeParam("domain", mailGunSettings.getDomain()) .routeParam("url", mailGunSettings.getUrl()) .routeParam("version", mailGunSettings.getVersion()) .basicAuth("api", mailGunSettings.getApiKey()) .queryString("subject", email.getSubject()) .queryString("text", email.getMessage()); if (email.getFrom() != null) { requestWithBody.queryString("from", email.getFrom()); } else { requestWithBody.queryString("from", mailGunSettings.getFrom()); } if (mailGunSettings.isTestMode()) { requestWithBody.queryString("to", mailGunSettings.getTestModeTo()); } else { requestWithBody.queryString("to", email.getTo()); } if(mailGunSettings.isTestMode()) { requestWithBody.field("o:testmode", "true"); } return getEmailResponse(requestWithBody); }
public static void main(String[] args) throws UnirestException { HttpResponse<JsonNode> jsonResponse = Unirest.post("http://httpbin.org/post") .header("accept", "application/json") .queryString("apiKey", "123") .field("parameter", "value") .field("foo", "bar") .asJson(); System.out.println(jsonResponse.getBody().toString()); } }
private RocketChatClientResponse buildPostCall(RocketChatRestApiV1 call, RocketChatQueryParams queryParams, Object body) throws IOException { HttpRequestWithBody req = Unirest.post(serverUrl + call.getMethodName()).header("Content-Type", "application/json"); if (call.requiresAuth()) { req.header("X-Auth-Token", authToken); req.header("X-User-Id", userId); } if (queryParams != null && queryParams.get() != null && !queryParams.isEmpty()) { for (Entry<? extends String, ? extends String> e : queryParams.get().entrySet()) { req.queryString(e.getKey(), e.getValue()); } } if (body != null) { req.body(objectMapper.writeValueAsString(body)); } try { HttpResponse<String> res = req.asString(); return objectMapper.readValue(res.getBody(), RocketChatClientResponse.class); } catch (UnirestException e) { throw new IOException(e); } } }
requestWithBody.queryString("from", email.getFrom()); } else { requestWithBody.queryString("from", mailGunSettings.getFrom()); requestWithBody.queryString("to", mailGunSettings.getTestModeTo()); } else { requestWithBody.queryString("to", email.getTo()); requestWithBody.queryString("cc", email.getCc()); requestWithBody.queryString("bcc", email.getBcc()); requestWithBody.queryString("subject", email.getSubject()); requestWithBody.queryString("text", email.getMessage()); requestWithBody.queryString("html", email.getHtml());
+ "Case not covered. Check if it is an error or the tool should be changed "); postRequest = postRequest.queryString(queryName, value);
@Override public void open() throws TexeraException { if (cursor == OPENED) { return; } try { String asterixAddress = "http://" + predicate.getHost() + ":" + predicate.getPort() + "/query/service"; String asterixQuery = generateAsterixQuery(predicate); HttpResponse<JsonNode> jsonResponse = Unirest.post(asterixAddress) .queryString("statement", asterixQuery) .field("mode", "immediate") .asJson(); // if status is 200 OK, store the results if (jsonResponse.getStatus() == 200) { this.resultJsonArray = jsonResponse.getBody().getObject().getJSONArray("results"); } else { throw new DataflowException("Send query to asterix failed: " + "error status: " + jsonResponse.getStatusText() + ", " + "error body: " + jsonResponse.getBody().toString()); } cursor = OPENED; } catch (UnirestException e) { throw new DataflowException(e); } }