use of org.monarchinitiative.loinc2hpo.exception.NetPostException in project loinc2hpo by monarch-initiative.
the class GitHubPoster method postIssue.
public void postIssue() throws Exception {
URL url = new URL("https://api.github.com/repos/obophenotype/human-phenotype-ontology/issues");
URLConnection con = url.openConnection();
String userpass = String.format("%s:%s", username, password);
String basicAuth = "Basic " + javax.xml.bind.DatatypeConverter.printBase64Binary(userpass.getBytes());
HttpURLConnection http = (HttpURLConnection) con;
// PUT is another valid option
http.setRequestMethod("POST");
http.setDoOutput(true);
byte[] out = payload.toString().getBytes(StandardCharsets.UTF_8);
int length = out.length;
http.setFixedLengthStreamingMode(length);
http.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
http.setRequestProperty("Authorization", basicAuth);
http.connect();
try (OutputStream os = http.getOutputStream()) {
os.write(out);
os.close();
}
if (http.getResponseCode() == 400) {
String erro = String.format("URL:%s\nPayload=%s\nServer response: %s [%d]", http.toString(), payload, http.getResponseMessage(), http.getResponseCode());
throw new NetPostException(erro);
} else {
this.response = http.getResponseMessage();
this.responsecode = http.getResponseCode();
}
}
use of org.monarchinitiative.loinc2hpo.exception.NetPostException in project loinc2hpo by monarch-initiative.
the class AnnotateTabController method postGitHubIssue.
private void postGitHubIssue(String message, String title, String uname, String pword, List<String> chosenLabels) {
GitHubPoster poster = new GitHubPoster(uname, pword, title, message);
this.githubUsername = uname;
this.githubPassword = pword;
if (chosenLabels != null && !chosenLabels.isEmpty()) {
logger.trace("Labels being chosen: ");
chosenLabels.forEach(logger::trace);
poster.setLabel(chosenLabels);
logger.trace("Labels sent to poster: \t");
logger.trace(poster.debugLabelsArray4Json());
}
try {
logger.trace("Message sent to Github: \t" + poster.debugReformatpayloadWithLabel());
poster.postIssue();
} catch (NetPostException he) {
PopUps.showException("GitHub error", "Bad Request (400): Could not post issue", he);
} catch (Exception ex) {
PopUps.showException("GitHub error", "GitHub error: Could not post issue", ex);
return;
}
String response = poster.getHttpResponse();
PopUps.showInfoMessage(String.format("Created issue for %s\nServer response: %s", loincIdSelected.toString(), response), "Created new issue");
}
Aggregations