diff --git a/src/main/java/eu/openaire/urls_worker/UrlsWorkerApplication.java b/src/main/java/eu/openaire/urls_worker/UrlsWorkerApplication.java index e6f12c3..d282875 100644 --- a/src/main/java/eu/openaire/urls_worker/UrlsWorkerApplication.java +++ b/src/main/java/eu/openaire/urls_worker/UrlsWorkerApplication.java @@ -21,6 +21,8 @@ import org.springframework.web.cors.UrlBasedCorsConfigurationSource; import javax.annotation.PreDestroy; import java.io.File; +import java.net.MalformedURLException; +import java.net.URL; import java.util.Arrays; import java.util.Collections; import java.util.Scanner; @@ -128,6 +130,14 @@ public class UrlsWorkerApplication { maxAssignmentsLimitPerBatch = WorkerConstants.ASSIGNMENTS_LIMIT; } controllerBaseUrl = data[2].trim(); + try { + new URL(controllerBaseUrl); + } catch (MalformedURLException mue) { + String errorMsg = "The given \"controllerBaseUrl\" (\"" + controllerBaseUrl + "\") was malformed! Please restart the program and give a valid URL."; + logger.error(errorMsg); + System.err.println(errorMsg); + System.exit(62); + } if ( !controllerBaseUrl.endsWith("/") ) controllerBaseUrl += "/"; // Make sure the other urls will not break later. } @@ -136,7 +146,7 @@ public class UrlsWorkerApplication { String errorMsg = "No \"workerId\" or/and \"maxAssignmentsLimitPerBatch\" or/and \"controllerBaseUrl\" could be retrieved from the file: " + inputDataFilePath; logger.error(errorMsg); System.err.println(errorMsg); - System.exit(62); + System.exit(63); } logger.info("workerId: " + workerId + ", maxAssignmentsLimitPerBatch: " + maxAssignmentsLimitPerBatch + ", controllerBaseUrl: " + controllerBaseUrl); // It's safe and helpful to show them in the logs. @@ -145,7 +155,7 @@ public class UrlsWorkerApplication { String errorMsg = "An error prevented the retrieval of the workerId and the controllerBaseUrl from the file: " + inputDataFilePath + "\n" + e.getMessage(); logger.error(errorMsg, e); System.err.println(errorMsg); - System.exit(63); + System.exit(64); } finally { if ( myReader != null ) myReader.close(); diff --git a/src/main/java/eu/openaire/urls_worker/plugins/PublicationsRetrieverPlugin.java b/src/main/java/eu/openaire/urls_worker/plugins/PublicationsRetrieverPlugin.java index 9df3ee7..32e81c3 100644 --- a/src/main/java/eu/openaire/urls_worker/plugins/PublicationsRetrieverPlugin.java +++ b/src/main/java/eu/openaire/urls_worker/plugins/PublicationsRetrieverPlugin.java @@ -133,7 +133,7 @@ public class PublicationsRetrieverPlugin { } - private static final String DocFileNotRetrievedExceptionName = DocFileNotRetrievedException.class.getName(); // Keep it here for easily spot if the exception changes inside the PublicationsRetriever library. + private static final String DocFileNotRetrievedExceptionName = DocFileNotRetrievedException.class.getSimpleName(); // Keep it here for easily spot if the exception changes inside the PublicationsRetriever library. public static void addUrlReportsToWorkerReport() { @@ -165,10 +165,8 @@ public class PublicationsRetrieverPlugin { } // TODO - The case where the "twin-ID" is not found, should "never" happen. But should we check? How to handle if that is the case..? } - else if ( comment.contains(DocFileNotRetrievedExceptionName) ) - fileLocation = "File not retrieved"; - else { - fileLocation = comment; + else if ( ! comment.contains(DocFileNotRetrievedExceptionName) ) { // If it was downloaded without an error. + fileLocation = comment; // This is the full-file-path. mimeType = "application/pdf"; } error = new Error(null, null); // We do not want to send a "null" object, since it just adds more complicated handling in the controller..