diff --git a/lib/tsd-file-api-client/src/main/java/no/uio/ifi/tc/TSDFileAPIClient.java b/lib/tsd-file-api-client/src/main/java/no/uio/ifi/tc/TSDFileAPIClient.java index 56f836ae..e2916629 100644 --- a/lib/tsd-file-api-client/src/main/java/no/uio/ifi/tc/TSDFileAPIClient.java +++ b/lib/tsd-file-api-client/src/main/java/no/uio/ifi/tc/TSDFileAPIClient.java @@ -142,13 +142,12 @@ public Message deleteFile(String token, String appId, String fileName) throws IO Message message = new Message(); try (Response response = client.newCall(request).execute()) { - message.setStatusCode(response.code()); - message.setStatusText(response.message()); - if (response.isSuccessful() && response.body() != null) { String responseBody = response.body().string(); message = gson.fromJson(responseBody, Message.class); } + message.setStatusCode(response.code()); + message.setStatusText(response.message()); } catch (JsonSyntaxException e) { log.error(e.getMessage(), e); } @@ -173,13 +172,12 @@ public ResumableUploads listResumableUploads(String token, String appId) throws ResumableUploads resumableUploads = new ResumableUploads(); try (Response response = client.newCall(request).execute()) { - resumableUploads.setStatusCode(response.code()); - resumableUploads.setStatusText(response.message()); - if (response.isSuccessful() && response.body() != null) { String responseBody = response.body().string(); resumableUploads = gson.fromJson(responseBody, ResumableUploads.class); } + resumableUploads.setStatusCode(response.code()); + resumableUploads.setStatusText(response.message()); } catch (JsonSyntaxException e) { log.error(e.getMessage(), e); } @@ -233,12 +231,12 @@ public Chunk initializeResumableUpload( Chunk chunkResponse = new Chunk(); try (Response response = client.newCall(request).execute()) { - chunkResponse.setStatusCode(response.code()); - chunkResponse.setStatusText(response.message()); String _body = Objects.requireNonNull(response.body()).string(); if (response.isSuccessful() && _body != null) { chunkResponse = gson.fromJson(_body, Chunk.class); } + chunkResponse.setStatusCode(response.code()); + chunkResponse.setStatusText(response.message()); } catch (JsonSyntaxException e) { log.error(e.getMessage(), e); } @@ -285,13 +283,12 @@ public Chunk uploadChunk( Chunk chunkResponse = new Chunk(); try (Response response = client.newCall(request).execute()) { - chunkResponse.setStatusCode(response.code()); - chunkResponse.setStatusText(response.message()); - if (response.isSuccessful() && response.body() != null) { String responseBody = response.body().string(); chunkResponse = gson.fromJson(responseBody, Chunk.class); } + chunkResponse.setStatusCode(response.code()); + chunkResponse.setStatusText(response.message()); } catch (JsonSyntaxException e) { log.error(e.getMessage(), e); } @@ -364,13 +361,12 @@ public Message deleteResumableUpload(String token, String appId, String uploadId Message message = new Message(); try (Response response = client.newCall(request).execute()) { - message.setStatusCode(response.code()); - message.setStatusText(response.message()); - if (response.isSuccessful() && response.body() != null) { String responseBody = response.body().string(); message = gson.fromJson(responseBody, Message.class); } + message.setStatusCode(response.code()); + message.setStatusText(response.message()); } catch (JsonSyntaxException e) { log.error(e.getMessage(), e); } @@ -442,14 +438,14 @@ public Token getToken(String tokenType, String oidcProvider, String idToken) thr try { response = client.newCall(request).execute(); - token.setStatusCode(response.code()); - token.setStatusText(response.message()); ResponseBody responseBody = response.body(); if (response.isSuccessful() && responseBody != null) { String bodyString = responseBody.string(); token.setToken( JsonParser.parseString(bodyString).getAsJsonObject().get("token").getAsString()); } + token.setStatusCode(response.code()); + token.setStatusText(response.message()); response.close(); } catch (Exception e) { log.error(e.getMessage(), e); diff --git a/lib/tsd-file-api-client/src/main/java/no/uio/ifi/tc/model/pojo/TSDFileAPIResponse.java b/lib/tsd-file-api-client/src/main/java/no/uio/ifi/tc/model/pojo/TSDFileAPIResponse.java index 3669c414..730d26e3 100644 --- a/lib/tsd-file-api-client/src/main/java/no/uio/ifi/tc/model/pojo/TSDFileAPIResponse.java +++ b/lib/tsd-file-api-client/src/main/java/no/uio/ifi/tc/model/pojo/TSDFileAPIResponse.java @@ -1,5 +1,6 @@ package no.uio.ifi.tc.model.pojo; +import com.fasterxml.jackson.annotation.JsonProperty; import com.google.gson.annotations.SerializedName; import lombok.Data; import lombok.ToString; @@ -8,9 +9,11 @@ @ToString public class TSDFileAPIResponse { + @JsonProperty("statusCode") @SerializedName("statusCode") private int statusCode; + @JsonProperty("statusText") @SerializedName("statusText") private String statusText; }