Reputation: 673
I would like to attach a file to an issue via the redmine-api. However, if I run my method I receive an Execution failed for task ...
private void uploadFileToDemoRedmine304651() {
String plainCredentials = "TestTheAPI:Qwert5678";
String base64Credentials = new String(Base64.getEncoder().encode(plainCredentials.getBytes()));
String authorizationHeader = "Basic " + base64Credentials;
try {
HttpRequest request = HttpRequest.newBuilder()
.uri(new URI("http://demo.redmine.org/uploads.json?filename=dummy.txt" ))
.header("Authorization", authorizationHeader)
.header("Content-Type", "application/octet-stream")
.POST(BodyPublishers.ofFile(Paths.get(String.valueOf(getClass().getResource("/dummy.txt")))))
.build();
HttpResponse<String> response = HttpClient.newBuilder().build().send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.statusCode());
System.out.println(response.body());
} catch (URISyntaxException e) {
System.out.println("Ye, it ain't working my man.");
} catch (IOException e) {
System.out.println("ups, not what you wanted huh?");
} catch (InterruptedException e) {
System.out.println("DON'T INTERRUPT ME WHEN I'M SENDING");
}
}
Since this topic is very new to me in Java I seek your help.
Can someone explain to me, what I'm doing wrong?
Stacktrace:
* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task 'Main.main()' <36 internal lines>
Process 'command 'C:/Program Files/Amazon Corretto/jdk15.0.2_7/bin/java.exe'' finished with non-zero exit value 1 <101 internal lines>
Upvotes: 0
Views: 392