diff --git a/elx-common/src/main/java/org/xbib/elx/common/ClientBuilder.java b/elx-common/src/main/java/org/xbib/elx/common/ClientBuilder.java index d672335..581f04f 100644 --- a/elx-common/src/main/java/org/xbib/elx/common/ClientBuilder.java +++ b/elx-common/src/main/java/org/xbib/elx/common/ClientBuilder.java @@ -39,7 +39,7 @@ public class ClientBuilder { } public ClientBuilder(ElasticsearchClient client) { - this(client, Thread.currentThread().getContextClassLoader()); + this(client, ClassLoader.getSystemClassLoader()); } public ClientBuilder(ElasticsearchClient client, ClassLoader classLoader) { diff --git a/elx-common/src/main/java/org/xbib/elx/common/DefaultIndexDefinition.java b/elx-common/src/main/java/org/xbib/elx/common/DefaultIndexDefinition.java index 8bbd250..867c1cc 100644 --- a/elx-common/src/main/java/org/xbib/elx/common/DefaultIndexDefinition.java +++ b/elx-common/src/main/java/org/xbib/elx/common/DefaultIndexDefinition.java @@ -302,8 +302,7 @@ public class DefaultIndexDefinition implements IndexDefinition { return null; } try { - URL url = new URL(string); - try (InputStream inputStream = url.openStream()) { + try (InputStream inputStream = findInputStream(string)) { Settings settings = Settings.builder().loadFromStream(string, inputStream).build(); XContentBuilder builder = JsonXContent.contentBuilder(); settings.toXContent(builder, ToXContent.EMPTY_PARAMS); @@ -311,6 +310,8 @@ public class DefaultIndexDefinition implements IndexDefinition { } } catch (MalformedURLException e) { return string; + } catch (IOException e) { + throw new IOException("unable to read JSON from " + string + ": " + e.getMessage(), e); } } @@ -319,8 +320,7 @@ public class DefaultIndexDefinition implements IndexDefinition { return null; } try { - URL url = new URL(string); - try (InputStream inputStream = url.openStream()) { + try (InputStream inputStream = findInputStream(string)) { if (string.endsWith(".json")) { Map mappings = JsonXContent.jsonXContent.createParser(inputStream).mapOrdered(); XContentBuilder builder = JsonXContent.contentBuilder(); @@ -337,6 +337,23 @@ public class DefaultIndexDefinition implements IndexDefinition { return string; } catch (MalformedInputException e) { return string; + } catch (IOException e) { + throw new IOException("unable to read JSON from " + string + ": " + e.getMessage(), e); + } + } + + private static InputStream findInputStream(String string) { + if (string == null) { + return null; + } + try { + URL url = ClassLoader.getSystemClassLoader().getResource(string); + if (url == null) { + url = new URL(string); + } + return url.openStream(); + } catch (IOException e) { + return null; } } } diff --git a/gradle.properties b/gradle.properties index 7d9b204..bc7f5ac 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,6 +1,6 @@ group = org.xbib name = elx -version = 2.2.1.32 +version = 2.2.1.33 gradle.wrapper.version = 6.6.1 xbib-metrics.version = 2.1.0