diff --git a/src/main/java/eu/openaire/urls_controller/controllers/UrlsController.java b/src/main/java/eu/openaire/urls_controller/controllers/UrlsController.java index b003d72..109dc2a 100644 --- a/src/main/java/eu/openaire/urls_controller/controllers/UrlsController.java +++ b/src/main/java/eu/openaire/urls_controller/controllers/UrlsController.java @@ -82,7 +82,7 @@ public class UrlsController { return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build(); } String remoteAddr = request.getHeader("X-FORWARDED-FOR"); - if ( (remoteAddr == null) || "".equals(remoteAddr) ) + if ( (remoteAddr == null) || remoteAddr.isEmpty() ) remoteAddr = request.getRemoteAddr(); WorkerInfo workerInfo = workersInfoMap.get(workerId); diff --git a/src/main/java/eu/openaire/urls_controller/models/BulkImportReport.java b/src/main/java/eu/openaire/urls_controller/models/BulkImportReport.java index 57c15ff..b2b0855 100644 --- a/src/main/java/eu/openaire/urls_controller/models/BulkImportReport.java +++ b/src/main/java/eu/openaire/urls_controller/models/BulkImportReport.java @@ -15,6 +15,8 @@ import java.util.Map; @JsonInclude(JsonInclude.Include.NON_NULL) public class BulkImportReport { + private static final Gson gson = new Gson(); // This is "transient" by default. It won't be included in any json object. + @JsonProperty private String provenance; @@ -48,7 +50,7 @@ public class BulkImportReport { { //Convert the LinkedHashMultiMap to Map>, since Gson cannot serialize Multimaps. eventsMap = eventsMultimap.asMap(); - return new Gson().toJson(this); + return gson.toJson(this); } public String getProvenance() { diff --git a/src/main/java/eu/openaire/urls_controller/util/FileUtils.java b/src/main/java/eu/openaire/urls_controller/util/FileUtils.java index 009f6f1..afb5e0b 100644 --- a/src/main/java/eu/openaire/urls_controller/util/FileUtils.java +++ b/src/main/java/eu/openaire/urls_controller/util/FileUtils.java @@ -331,9 +331,8 @@ public class FileUtils { baseUrl += batchNum + "/"; String requestUrl = getRequestUrlForBatch(baseUrl, fileNamesForCurBatch); //logger.debug("Going to request the batch_" + batchNum + " (out of " + totalBatches + ") with " + fileNamesForCurBatch.size() + " fullTexts, of assignments_" + assignmentsBatchCounter + " from the Worker with ID \"" + workerId + "\" and baseRequestUrl: " + baseUrl + "[fileNames]"); - HttpURLConnection conn = null; try { - conn = (HttpURLConnection) new URL(requestUrl).openConnection(); + HttpURLConnection conn = (HttpURLConnection) new URL(requestUrl).openConnection(); conn.setRequestMethod("GET"); conn.setRequestProperty("User-Agent", "UrlsController"); conn.connect(); @@ -346,7 +345,8 @@ public class FileUtils { if ( (statusCode >= 500) && (statusCode <= 599) ) throw new RuntimeException(); // Throw an exception to indicate that the Worker has problems and all remaining batches will fail as well. return null; - } + } else + return conn; } catch (RuntimeException re) { throw re; } catch (Exception e) { @@ -358,7 +358,6 @@ public class FileUtils { } return null; } - return conn; }