Skip to content

Commit

Permalink
Refactor uri_parts processor so it can be exposed in Painless (#73344)
Browse files Browse the repository at this point in the history
  • Loading branch information
danhermann authored May 28, 2021
1 parent 2b521e3 commit bb5fea1
Showing 1 changed file with 16 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -81,6 +70,21 @@ public IngestDocument execute(IngestDocument ingestDocument) throws Exception {
return ingestDocument;
}

public static Map<String, Object> 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<String, Object> getUriParts(URI uri, URL fallbackUrl) {
var uriParts = new HashMap<String, Object>();
Expand Down

0 comments on commit bb5fea1

Please sign in to comment.