diff --git a/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/UriPartsProcessor.java b/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/UriPartsProcessor.java index 11204235822fb..ae252fbf6240e 100644 --- a/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/UriPartsProcessor.java +++ b/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/UriPartsProcessor.java @@ -58,18 +58,7 @@ public boolean getKeepOriginal() { public IngestDocument execute(IngestDocument ingestDocument) throws Exception { String value = ingestDocument.getFieldValue(field, String.class); - URI uri = null; - URL url = null; - try { - uri = new URI(value); - } catch (URISyntaxException e) { - try { - url = new URL(value); - } catch (MalformedURLException e2) { - throw new IllegalArgumentException("unable to parse URI [" + value + "]"); - } - } - var uriParts = getUriParts(uri, url); + var uriParts = apply(value); if (keepOriginal) { uriParts.put("original", value); } @@ -81,6 +70,21 @@ public IngestDocument execute(IngestDocument ingestDocument) throws Exception { return ingestDocument; } + public static Map apply(String urlString) { + URI uri = null; + URL url = null; + try { + uri = new URI(urlString); + } catch (URISyntaxException e) { + try { + url = new URL(urlString); + } catch (MalformedURLException e2) { + throw new IllegalArgumentException("unable to parse URI [" + urlString + "]"); + } + } + return getUriParts(uri, url); + } + @SuppressForbidden(reason = "URL.getPath is used only if URI.getPath is unavailable") private static Map getUriParts(URI uri, URL fallbackUrl) { var uriParts = new HashMap();