public MultipartBody field(String name, InputStream stream, String fileName) { MultipartBody body = field(name, stream, ContentType.APPLICATION_OCTET_STREAM, fileName); this.body = body; return body; }
public MultipartBody field(String name, File file) { return field(name, file, null); }
public MultipartBody field(String name, Object value) { return field(name, value, null); }
public MultipartBody field(String name, InputStream stream, String fileName) { MultipartBody body = field(name, stream, ContentType.APPLICATION_OCTET_STREAM, fileName); this.body = body; return body; }
public MultipartBody field(String name, InputStream stream, String fileName) { MultipartBody body = field(name, stream, ContentType.APPLICATION_OCTET_STREAM, fileName); this.body = body; return body; }
public MultipartBody field(String name, org.springframework.web.multipart.MultipartFile file) { return field(name, file, null); }
public MultipartBody field(String name, Object value) { return field(name, value, null); }
public MultipartBody field(String name, File file) { return field(name, file, null); }
public MultipartBody field(String name, Object value) { return field(name, value, null); }
public MultipartBody field(String name, File file) { return field(name, file, null); }
public JSONObject addTestStepsToTestCases(List<String> testSteps) throws UnirestException { if (testSteps.isEmpty()) { return new JSONObject(); } MultipartBody request = Unirest.patch(url + TESTCASEINSESSION_API_URL + testCaseInSessionId + "/").field("testSteps", testSteps.get(0)); for (String tc: testSteps.subList(1, testSteps.size())) { request = request.field("testSteps", tc); } return getJSonResponse(request); }
public ScriptRequestResponse retreiveRequestedRsyncScript(String datasetIdentifier, String scriptRequestUrl) throws DataCaptureModuleException { logger.fine("retreiveRequestedRsyncScript using dataset identifier + " + datasetIdentifier + " to " + scriptRequestUrl); try { //When the result is an error, html is returned from DCM instead of json. This causes the parser to blow up unhelpfully. //Stock unirest hasn't been updated in years, but in a fork this issue seems to be improved: https://github.com/OpenUnirest/unirest-java/issues/10 HttpResponse<JsonNode> scriptRequest = Unirest.post(scriptRequestUrl) .field("datasetIdentifier", datasetIdentifier) .asJson(); return DataCaptureModuleUtil.getScriptFromRequest(scriptRequest); } catch( UnirestException ex) { String error = "Error calling " + scriptRequestUrl + ". This likely indicates the DCM service returned an error page and not valid json. Unirest parsing error: " + ex; logger.info(error); throw new DataCaptureModuleException(error, ex); } }
public void createApplication() { if (!active) { return; } try { JSONObject applicationJson = getJSonResponse(Unirest.post(url + APPLICATION_API_URL) .field("name", SeleniumTestsContextManager.getApplicationName())); applicationId = applicationJson.getInt("id"); } catch (UnirestException | JSONException e) { throw new SeleniumRobotServerException("cannot create application", e); } }
private void unreserveVariable(TestVariable variable) { if (variable.isReservable() && variable.getId() != null) { try { getJSonResponse(Unirest.patch(String.format(url + EXISTING_VARIABLE_API_URL, variable.getId())) .field("releaseDate", "")); } catch (UnirestException e) { logger.warn("variable could not be unreserved, server will do it automatically after reservation period: " + e.getMessage()); } } }
public static void main(String[] args) throws UnirestException { HttpResponse<JsonNode> jsonResponse = Unirest.post("http://httpbin.org/post") .header("accept", "application/json") .field("parameter", "value") .field("file", new File("/tmp/file")) .asJson(); System.out.println(jsonResponse.getBody().toString()); } }
/** * Create test step and add it to the current test case */ public void createTestStep(String testStep) { if (!active) { return; } try { JSONObject stepJson = getJSonResponse(Unirest.post(url + TESTSTEP_API_URL) .field("name", testStep)); testStepId = stepJson.getInt("id"); addCurrentTestStepToTestCase(); } catch (UnirestException | JSONException e) { throw new SeleniumRobotServerException("cannot create test step", e); } }
public void createEnvironment() { if (!active) { return; } try { JSONObject envJson = getJSonResponse(Unirest.post(url + ENVIRONMENT_API_URL) .field("name", SeleniumTestsContextManager.getThreadContext().getTestEnv())); environmentId = envJson.getInt("id"); } catch (UnirestException | JSONException e) { throw new SeleniumRobotServerException("cannot create environment", e); } }
public void addLogsToTestCaseInSession(String logs) { if (testCaseInSessionId == null) { createTestCaseInSession(); } try { getJSonResponse(Unirest.patch(url + TESTCASEINSESSION_API_URL + testCaseInSessionId + "/").field("stacktrace", logs)); } catch (UnirestException e) { throw new SeleniumRobotServerException("cannot add logs to test case", e); } } public Integer getSessionId() {
public Image uploadImage(File file) throws Exception { // {"data":{"bandwidth":0,"nsfw":null,"is_ad":false,"link":"http://i.imgur.com/4a2U4HI.png","description":null,"section":null,"title":null,"type":"image/png","tags":[],"deletehash":"g5KtSKSSXT2l54Q","datetime":1490023631,"account_id":0,"size":258,"width":35,"account_url":null,"name":"","animated":false,"id":"4a2U4HI","in_gallery":false,"vote":null,"favorite":false,"views":0,"height":35},"success":true,"status":200} HttpResponse<JsonNode> response = Unirest .post("https://api.imgur.com/3/image") .header("accept", "application/json") .header("Authorization", "Client-ID " + clientId) .field("image", file) .field("name", file.getName()) .field("title", file.getName()) .asJson(); if (!response.getBody().getObject().getBoolean("success")) { Logger.debug(response.getBody().toString()); throw new Exception(response.getBody().getObject().getJSONObject("data").getString("error")); } Image image = new Image(); image.id = response.getBody().getObject().getJSONObject("data").getString("id"); image.deleteHash = response.getBody().getObject().getJSONObject("data").getString("deletehash"); return image; }
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()); } }