- Improve the stability of "UriBuilder.getPublicIP()", by using a "HttpURLConnection" to increase the connection and read timeouts and avoid timeout-exceptions.

- Show the number of assignments which are requested from the Controller, in the log-message.
- Update Spring.
This commit is contained in:
Lampros Smyrnaios 2023-01-03 18:43:26 +02:00
parent 378db2ff2f
commit 778dc6e25c
4 changed files with 17 additions and 12 deletions

View File

@ -1,5 +1,5 @@
plugins { plugins {
id 'org.springframework.boot' version '2.7.6' id 'org.springframework.boot' version '2.7.7'
id 'io.spring.dependency-management' version '1.1.0' id 'io.spring.dependency-management' version '1.1.0'
id 'java' id 'java'
} }

View File

@ -39,7 +39,7 @@ public class FullTextsController {
public Object getMultipleFullTexts(@PathVariable long assignmentsCounter, @PathVariable int totalZipBatches, @PathVariable int zipBatchCounter, @PathVariable List<String> fileNamesWithExtensions) { public Object getMultipleFullTexts(@PathVariable long assignmentsCounter, @PathVariable int totalZipBatches, @PathVariable int zipBatchCounter, @PathVariable List<String> fileNamesWithExtensions) {
int fileNamesListNum = fileNamesWithExtensions.size(); int fileNamesListNum = fileNamesWithExtensions.size();
if ( (fileNamesListNum == 1) && (fileNamesWithExtensions.get(0).length() == 0) ) { // In case the last "/" in the url was given, then this list will not be empty, but have one empty item instead. if ( (fileNamesListNum == 1) && (fileNamesWithExtensions.get(0).length() == 0) ) { // In case the last "/" in the url was given (without any files following), then this list will not be empty, but have one empty item instead.
// In case the url does not end in "/", then Spring will automatically return an "HTTP-BadRequest". // In case the url does not end in "/", then Spring will automatically return an "HTTP-BadRequest".
String errorMsg = "An empty \"fileNamesWithExtensions\" list was given from assignments_" + assignmentsCounter + ", for batch_" + zipBatchCounter; String errorMsg = "An empty \"fileNamesWithExtensions\" list was given from assignments_" + assignmentsCounter + ", for batch_" + zipBatchCounter;
logger.error(errorMsg); logger.error(errorMsg);

View File

@ -67,7 +67,7 @@ public class AssignmentsHandler {
public static AssignmentsRequest requestAssignments() public static AssignmentsRequest requestAssignments()
{ {
logger.info("Going to request assignments from the controller-server: " + requestUrl); logger.info("Going to request " + UrlsWorkerApplication.maxAssignmentsLimitPerBatch + " assignments from the controller-server: " + requestUrl);
AssignmentsRequest assignmentRequest = null; AssignmentsRequest assignmentRequest = null;
try { // Here, the HTTP-request is executed. try { // Here, the HTTP-request is executed.

View File

@ -8,8 +8,8 @@ import org.springframework.core.env.Environment;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
public class UriBuilder { public class UriBuilder {
@ -55,19 +55,24 @@ public class UriBuilder {
private static String getPublicIP() private static String getPublicIP()
{ {
String publicIpAddress = ""; String publicIpAddress = "";
URL url_name; HttpURLConnection conn = null;
try { try {
url_name = new URL("https://api.ipify.org/"); conn = (HttpURLConnection) new URL("https://api.ipify.org/").openConnection();
} catch (MalformedURLException mue) { conn.setConnectTimeout(60_000);
logger.warn(mue.getMessage()); conn.setReadTimeout(60_000);
return null; conn.setRequestMethod("GET");
} conn.connect();
try ( BufferedReader bf = new BufferedReader(new InputStreamReader(url_name.openStream()))) { try ( BufferedReader bf = new BufferedReader(new InputStreamReader(conn.getInputStream()))) {
publicIpAddress = bf.readLine().trim(); publicIpAddress = bf.readLine().trim();
}
} catch (Exception e) { } catch (Exception e) {
logger.warn("Cannot get the publicIP address for this machine!", e); logger.warn("Cannot get the publicIP address for this machine!", e);
return null; return null;
} finally {
if ( conn != null )
conn.disconnect();
} }
return publicIpAddress; return publicIpAddress;
} }