diff --git a/harvesters/src/main/java/org/fao/geonet/kernel/harvest/harvester/simpleUrl/Harvester.java b/harvesters/src/main/java/org/fao/geonet/kernel/harvest/harvester/simpleUrl/Harvester.java index 088611c999..af17dd29e3 100644 --- a/harvesters/src/main/java/org/fao/geonet/kernel/harvest/harvester/simpleUrl/Harvester.java +++ b/harvesters/src/main/java/org/fao/geonet/kernel/harvest/harvester/simpleUrl/Harvester.java @@ -52,8 +52,10 @@ import java.io.IOException; import java.io.InputStreamReader; +import java.net.MalformedURLException; import java.net.URI; import java.net.URISyntaxException; +import java.net.URL; import java.nio.file.Path; import java.util.ArrayList; import java.util.HashMap; @@ -137,8 +139,16 @@ public HarvestResult harvest(Logger log) throws Exception { nodes.forEach(record -> { String uuid = this.extractUuidFromIdentifier(record.get(params.recordIdPath).asText()); - Element xml = convertRecordToXml(record, uuid); - uuids.put(uuid, xml); + String apiUrl = params.url.split("\\?")[0]; + URL url = null; + try { + url = new URL(apiUrl); + String nodeUrl = new StringBuilder(url.getProtocol()).append("://").append(url.getAuthority()).toString(); + Element xml = convertRecordToXml(record, uuid, apiUrl, nodeUrl); + uuids.put(uuid, xml); + } catch (MalformedURLException e) { + log.warning("Failed to parse Node URL"); + } }); aligner.align(uuids, errors); allUuids.putAll(uuids); @@ -226,7 +236,7 @@ protected List buildListOfUrl(SimpleUrlParams params, int numberOfRecord return urlList; } - private Element convertRecordToXml(JsonNode record, String uuid) { + private Element convertRecordToXml(JsonNode record, String uuid, String apiUrl, String nodeUrl) { ObjectMapper objectMapper = new ObjectMapper(); try { String recordAsXml = XML.toString( @@ -235,6 +245,8 @@ private Element convertRecordToXml(JsonNode record, String uuid) { recordAsXml = Xml.stripNonValidXMLCharacters(recordAsXml).replace("<@", "<").replace("