- 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:
parent
378db2ff2f
commit
778dc6e25c
|
@ -1,5 +1,5 @@
|
|||
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 'java'
|
||||
}
|
||||
|
|
|
@ -39,7 +39,7 @@ public class FullTextsController {
|
|||
public Object getMultipleFullTexts(@PathVariable long assignmentsCounter, @PathVariable int totalZipBatches, @PathVariable int zipBatchCounter, @PathVariable List<String> fileNamesWithExtensions) {
|
||||
|
||||
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".
|
||||
String errorMsg = "An empty \"fileNamesWithExtensions\" list was given from assignments_" + assignmentsCounter + ", for batch_" + zipBatchCounter;
|
||||
logger.error(errorMsg);
|
||||
|
|
|
@ -67,7 +67,7 @@ public class AssignmentsHandler {
|
|||
|
||||
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;
|
||||
try { // Here, the HTTP-request is executed.
|
||||
|
|
|
@ -8,8 +8,8 @@ import org.springframework.core.env.Environment;
|
|||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.InetAddress;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
|
||||
public class UriBuilder {
|
||||
|
@ -55,19 +55,24 @@ public class UriBuilder {
|
|||
private static String getPublicIP()
|
||||
{
|
||||
String publicIpAddress = "";
|
||||
URL url_name;
|
||||
HttpURLConnection conn = null;
|
||||
try {
|
||||
url_name = new URL("https://api.ipify.org/");
|
||||
} catch (MalformedURLException mue) {
|
||||
logger.warn(mue.getMessage());
|
||||
return null;
|
||||
}
|
||||
try ( BufferedReader bf = new BufferedReader(new InputStreamReader(url_name.openStream()))) {
|
||||
publicIpAddress = bf.readLine().trim();
|
||||
conn = (HttpURLConnection) new URL("https://api.ipify.org/").openConnection();
|
||||
conn.setConnectTimeout(60_000);
|
||||
conn.setReadTimeout(60_000);
|
||||
conn.setRequestMethod("GET");
|
||||
conn.connect();
|
||||
try ( BufferedReader bf = new BufferedReader(new InputStreamReader(conn.getInputStream()))) {
|
||||
publicIpAddress = bf.readLine().trim();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.warn("Cannot get the publicIP address for this machine!", e);
|
||||
return null;
|
||||
} finally {
|
||||
if ( conn != null )
|
||||
conn.disconnect();
|
||||
}
|
||||
|
||||
return publicIpAddress;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue