diff --git a/rest-api/src/main/java/lcsb/mapviewer/api/minervanet/MinervaNetController.java b/rest-api/src/main/java/lcsb/mapviewer/api/minervanet/MinervaNetController.java index 345b90e7a9295a478ffe96e5a56364acea066095..ed0b054a9da14866e0f2d5adb08efe8a65baef25 100644 --- a/rest-api/src/main/java/lcsb/mapviewer/api/minervanet/MinervaNetController.java +++ b/rest-api/src/main/java/lcsb/mapviewer/api/minervanet/MinervaNetController.java @@ -1,5 +1,6 @@ package lcsb.mapviewer.api.minervanet; +import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; import lcsb.mapviewer.model.user.ConfigurationElementType; import lcsb.mapviewer.services.interfaces.IConfigurationService; @@ -50,11 +51,24 @@ public class MinervaNetController { try (CloseableHttpResponse response = client.execute(post)) { HttpEntity responseEntity = response.getEntity(); String responseBody = EntityUtils.toString(responseEntity, "UTF-8"); - if (response.getStatusLine().getStatusCode() != 200) { - logger.error("Could not submit report to MinervaNet. Reason: " + responseBody); + if (response.getStatusLine().getStatusCode() != 200 || !responseBodyValid(responseBody)) { + String error = "Could not submit report to MinervaNet. Reason: " + responseBody; + logger.error(error); + throw new ReportSubmissionException(error); } } } } + private boolean responseBodyValid(String body) { + ObjectMapper mapper = new ObjectMapper(); + mapper.enable(DeserializationFeature.FAIL_ON_READING_DUP_TREE_KEY); + try { + mapper.readTree(body); + } catch (IOException e) { + return false; + } + return true; + } + } diff --git a/rest-api/src/main/java/lcsb/mapviewer/api/minervanet/ReportSubmissionException.java b/rest-api/src/main/java/lcsb/mapviewer/api/minervanet/ReportSubmissionException.java new file mode 100644 index 0000000000000000000000000000000000000000..38f567524a172cc88d903d09373b063d79ea388e --- /dev/null +++ b/rest-api/src/main/java/lcsb/mapviewer/api/minervanet/ReportSubmissionException.java @@ -0,0 +1,23 @@ +package lcsb.mapviewer.api.minervanet; + +public class ReportSubmissionException extends RuntimeException { + public ReportSubmissionException() { + super(); + } + + public ReportSubmissionException(String message) { + super(message); + } + + public ReportSubmissionException(String message, Throwable cause) { + super(message, cause); + } + + public ReportSubmissionException(Throwable cause) { + super(cause); + } + + protected ReportSubmissionException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { + super(message, cause, enableSuppression, writableStackTrace); + } +}