changed deprecated method with non deprecated versioen

This commit is contained in:
Miriam Baglioni 2020-10-30 14:10:10 +01:00
parent 14bf2e7238
commit 10d8bbada8
1 changed files with 12 additions and 11 deletions

View File

@ -59,8 +59,7 @@ public class ZenodoAPIClient implements Serializable {
String json = "{}"; String json = "{}";
OkHttpClient httpClient = new OkHttpClient.Builder().connectTimeout(600, TimeUnit.SECONDS).build(); OkHttpClient httpClient = new OkHttpClient.Builder().connectTimeout(600, TimeUnit.SECONDS).build();
// RequestBody body = RequestBody.create(MEDIA_TYPE_JSON, json);
//RequestBody body = RequestBody.create(MEDIA_TYPE_JSON, json);
RequestBody body = RequestBody.create(json, MEDIA_TYPE_JSON); RequestBody body = RequestBody.create(json, MEDIA_TYPE_JSON);
@ -99,9 +98,10 @@ public class ZenodoAPIClient implements Serializable {
*/ */
public int uploadIS(InputStream is, String file_name, long len) throws IOException { public int uploadIS(InputStream is, String file_name, long len) throws IOException {
OkHttpClient httpClient = new OkHttpClient.Builder() OkHttpClient httpClient = new OkHttpClient.Builder()
.writeTimeout(600, TimeUnit.SECONDS) .writeTimeout(600, TimeUnit.SECONDS)
.readTimeout(600, TimeUnit.SECONDS) .readTimeout(600, TimeUnit.SECONDS)
.connectTimeout(600, TimeUnit.SECONDS).build(); .connectTimeout(600, TimeUnit.SECONDS)
.build();
Request request = new Request.Builder() Request request = new Request.Builder()
.url(bucket + "/" + file_name) .url(bucket + "/" + file_name)
@ -128,7 +128,7 @@ public class ZenodoAPIClient implements Serializable {
OkHttpClient httpClient = new OkHttpClient.Builder().connectTimeout(600, TimeUnit.SECONDS).build(); OkHttpClient httpClient = new OkHttpClient.Builder().connectTimeout(600, TimeUnit.SECONDS).build();
//RequestBody body = RequestBody.create(MEDIA_TYPE_JSON, metadata); // RequestBody body = RequestBody.create(MEDIA_TYPE_JSON, metadata);
RequestBody body = RequestBody.create(metadata, MEDIA_TYPE_JSON); RequestBody body = RequestBody.create(metadata, MEDIA_TYPE_JSON);
Request request = new Request.Builder() Request request = new Request.Builder()
@ -166,8 +166,8 @@ public class ZenodoAPIClient implements Serializable {
Request request = new Request.Builder() Request request = new Request.Builder()
.url(urlString + "/" + deposition_id + "/actions/publish") .url(urlString + "/" + deposition_id + "/actions/publish")
.addHeader("Authorization", "Bearer " + access_token) .addHeader("Authorization", "Bearer " + access_token)
//.post(RequestBody.create(MEDIA_TYPE_JSON, json)) // .post(RequestBody.create(MEDIA_TYPE_JSON, json))
.post(body) .post(body)
.build(); .build();
try (Response response = httpClient.newCall(request).execute()) { try (Response response = httpClient.newCall(request).execute()) {
@ -202,8 +202,8 @@ public class ZenodoAPIClient implements Serializable {
Request request = new Request.Builder() Request request = new Request.Builder()
.url(urlString + "/" + deposition_id + "/actions/newversion") .url(urlString + "/" + deposition_id + "/actions/newversion")
.addHeader("Authorization", "Bearer " + access_token) .addHeader("Authorization", "Bearer " + access_token)
//.post(RequestBody.create(MEDIA_TYPE_JSON, json)) // .post(RequestBody.create(MEDIA_TYPE_JSON, json))
.post(body) .post(body)
.build(); .build();
try (Response response = httpClient.newCall(request).execute()) { try (Response response = httpClient.newCall(request).execute()) {
@ -285,7 +285,8 @@ public class ZenodoAPIClient implements Serializable {
private String getBucket(String url) throws IOException { private String getBucket(String url) throws IOException {
OkHttpClient httpClient = new OkHttpClient.Builder() OkHttpClient httpClient = new OkHttpClient.Builder()
.connectTimeout(600, TimeUnit.SECONDS).build(); .connectTimeout(600, TimeUnit.SECONDS)
.build();
Request request = new Request.Builder() Request request = new Request.Builder()
.url(url) .url(url)