- Fix a bug, causing the "fileLocation" to be set to the value of the "errorCause", when the docFile was not retrieved.

- Leave the "fileLocation" to be NULL, when the DocFile was not retrieved. Previously, the value "File not retrieved" was assigned (only in theory, because the bug above caused the related check to always fail).
- Verify that the "ControllerBaseUrl" given by the user is not malformed.
This commit is contained in:
Lampros Smyrnaios 2021-12-07 19:33:10 +02:00
parent fd5b56e3c6
commit ab5e04698c
2 changed files with 15 additions and 7 deletions

View File

@ -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();

View File

@ -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..