/** * Method to fill the JSON with the experiment information. This JSON includes the files field. * * @param json Input JSON to fill with data. * @param zipPath Path of the temporary zip files for the Experiment. * @return String with the new JSON. * @throws IOException */ private String getJSONExperiment(String json, String zipPath) throws IOException { // Get bioID json += "\"id\":\"" + selExp.getBioID() + "\""; // Set zip file Path path = FileSystems.getDefault().getPath(zipPath); json += ",\"file\":\"" + new String(Base64Coder.encode(Files.readAllBytes(path))) + "\"}"; return json; }
/** * Method to open the connection to send the JSON to BiofOmics server. * * @return A HttpURLConnection with the server. * @throws IOException */ private HttpURLConnection openConnection() throws IOException { // Get URL URL url; url = new URL(BewConstants.WEB); // Open the connection HttpURLConnection connection = (HttpURLConnection) url.openConnection(); // Set authorization header String auth = Base64Coder.encodeString(BewConstants.USER + ":" + BewConstants.PASS); connection.addRequestProperty("Authorization", "Basic " + auth); connection.setDoOutput(true); connection.setInstanceFollowRedirects(true); connection.setRequestMethod("POST"); connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); connection.setRequestProperty("charset", "UTF-8"); connection.setUseCaches(false); return connection; }