Use URI vs URL accessing File from classpath.
URL escapes special characters such as spaces which causes the resource to not be found when used to create a File object. Use URI. Closes #5915
This commit is contained in:
parent
51ba3ca220
commit
4df4506875
|
@ -55,7 +55,7 @@ import java.io.IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test parsing and executing a template request.
|
* Test parsing and executing a template request.
|
||||||
* */
|
*/
|
||||||
public class TemplateQueryParserTest extends ElasticsearchTestCase {
|
public class TemplateQueryParserTest extends ElasticsearchTestCase {
|
||||||
|
|
||||||
private Injector injector;
|
private Injector injector;
|
||||||
|
@ -63,8 +63,7 @@ public class TemplateQueryParserTest extends ElasticsearchTestCase {
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setup() throws IOException {
|
public void setup() throws IOException {
|
||||||
String scriptPath = this.getClass().getResource("config").getPath();
|
Settings settings = ImmutableSettings.settingsBuilder().put("path.conf", this.getResource("config").getPath()).build();
|
||||||
Settings settings = ImmutableSettings.settingsBuilder().put("path.conf", scriptPath).build();
|
|
||||||
|
|
||||||
Index index = new Index("test");
|
Index index = new Index("test");
|
||||||
injector = new ModulesBuilder().add(
|
injector = new ModulesBuilder().add(
|
||||||
|
|
|
@ -24,8 +24,6 @@ import org.elasticsearch.action.search.SearchResponse;
|
||||||
import org.elasticsearch.common.bytes.BytesArray;
|
import org.elasticsearch.common.bytes.BytesArray;
|
||||||
import org.elasticsearch.common.bytes.BytesReference;
|
import org.elasticsearch.common.bytes.BytesReference;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
|
||||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
|
||||||
import org.elasticsearch.test.ElasticsearchIntegrationTest;
|
import org.elasticsearch.test.ElasticsearchIntegrationTest;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
@ -43,7 +41,7 @@ import static org.hamcrest.Matchers.is;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Full integration test of the template query plugin.
|
* Full integration test of the template query plugin.
|
||||||
* */
|
*/
|
||||||
@ElasticsearchIntegrationTest.ClusterScope(scope = ElasticsearchIntegrationTest.Scope.SUITE)
|
@ElasticsearchIntegrationTest.ClusterScope(scope = ElasticsearchIntegrationTest.Scope.SUITE)
|
||||||
public class TemplateQueryTest extends ElasticsearchIntegrationTest {
|
public class TemplateQueryTest extends ElasticsearchIntegrationTest {
|
||||||
|
|
||||||
|
@ -59,8 +57,7 @@ public class TemplateQueryTest extends ElasticsearchIntegrationTest {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Settings nodeSettings(int nodeOrdinal) {
|
public Settings nodeSettings(int nodeOrdinal) {
|
||||||
String scriptPath = this.getClass().getResource("config").getPath();
|
return settingsBuilder().put("path.conf", this.getResource("config").getPath()).build();
|
||||||
return settingsBuilder().put("path.conf", scriptPath).build();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -25,6 +25,7 @@ import org.elasticsearch.common.Strings;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileFilter;
|
import java.io.FileFilter;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
|
import java.net.URI;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
@ -92,7 +93,8 @@ public final class FileUtils {
|
||||||
return file;
|
return file;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new File(resource.getFile());
|
|
||||||
|
return new File(URI.create(resource.toString()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static URL findResource(String path, String optionalFileSuffix) {
|
private static URL findResource(String path, String optionalFileSuffix) {
|
||||||
|
|
Loading…
Reference in New Issue