forked from lsmyrnaios/UrlsController
- Optimize the json-conversion of the "BulkImportReport".
- Code polishing.
This commit is contained in:
parent
f7f919cee1
commit
0ab6bae93a
|
@ -82,7 +82,7 @@ public class UrlsController {
|
||||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
|
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
|
||||||
}
|
}
|
||||||
String remoteAddr = request.getHeader("X-FORWARDED-FOR");
|
String remoteAddr = request.getHeader("X-FORWARDED-FOR");
|
||||||
if ( (remoteAddr == null) || "".equals(remoteAddr) )
|
if ( (remoteAddr == null) || remoteAddr.isEmpty() )
|
||||||
remoteAddr = request.getRemoteAddr();
|
remoteAddr = request.getRemoteAddr();
|
||||||
|
|
||||||
WorkerInfo workerInfo = workersInfoMap.get(workerId);
|
WorkerInfo workerInfo = workersInfoMap.get(workerId);
|
||||||
|
|
|
@ -15,6 +15,8 @@ import java.util.Map;
|
||||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||||
public class BulkImportReport {
|
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
|
@JsonProperty
|
||||||
private String provenance;
|
private String provenance;
|
||||||
|
|
||||||
|
@ -48,7 +50,7 @@ public class BulkImportReport {
|
||||||
{
|
{
|
||||||
//Convert the LinkedHashMultiMap<String, String> to Map<String, Collection<String>>, since Gson cannot serialize Multimaps.
|
//Convert the LinkedHashMultiMap<String, String> to Map<String, Collection<String>>, since Gson cannot serialize Multimaps.
|
||||||
eventsMap = eventsMultimap.asMap();
|
eventsMap = eventsMultimap.asMap();
|
||||||
return new Gson().toJson(this);
|
return gson.toJson(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getProvenance() {
|
public String getProvenance() {
|
||||||
|
|
|
@ -331,9 +331,8 @@ public class FileUtils {
|
||||||
baseUrl += batchNum + "/";
|
baseUrl += batchNum + "/";
|
||||||
String requestUrl = getRequestUrlForBatch(baseUrl, fileNamesForCurBatch);
|
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]");
|
//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 {
|
try {
|
||||||
conn = (HttpURLConnection) new URL(requestUrl).openConnection();
|
HttpURLConnection conn = (HttpURLConnection) new URL(requestUrl).openConnection();
|
||||||
conn.setRequestMethod("GET");
|
conn.setRequestMethod("GET");
|
||||||
conn.setRequestProperty("User-Agent", "UrlsController");
|
conn.setRequestProperty("User-Agent", "UrlsController");
|
||||||
conn.connect();
|
conn.connect();
|
||||||
|
@ -346,7 +345,8 @@ public class FileUtils {
|
||||||
if ( (statusCode >= 500) && (statusCode <= 599) )
|
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.
|
throw new RuntimeException(); // Throw an exception to indicate that the Worker has problems and all remaining batches will fail as well.
|
||||||
return null;
|
return null;
|
||||||
}
|
} else
|
||||||
|
return conn;
|
||||||
} catch (RuntimeException re) {
|
} catch (RuntimeException re) {
|
||||||
throw re;
|
throw re;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -358,7 +358,6 @@ public class FileUtils {
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return conn;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue