Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor uri_parts processor so it can be exposed in Painless #73344

Merged
merged 2 commits into from
May 28, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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