Merge pull request #75 from madhawav/fix-tourl
[OODT-999] Fix for "File.toURL fails when their are spaces in project/repository paths"
diff --git a/commons/src/main/java/org/apache/oodt/commons/Configuration.java b/commons/src/main/java/org/apache/oodt/commons/Configuration.java
index a6e2fd3..a04c956 100644
--- a/commons/src/main/java/org/apache/oodt/commons/Configuration.java
+++ b/commons/src/main/java/org/apache/oodt/commons/Configuration.java
@@ -158,7 +158,7 @@
return getEmptyConfiguration();
}
}
- url = file.toURL();
+ url = file.toURI().toURL();
}
return getConfiguration(url);
diff --git a/commons/src/test/java/org/apache/oodt/commons/ConfigurationTest.java b/commons/src/test/java/org/apache/oodt/commons/ConfigurationTest.java
index 35ba9e2..f292faf 100644
--- a/commons/src/test/java/org/apache/oodt/commons/ConfigurationTest.java
+++ b/commons/src/test/java/org/apache/oodt/commons/ConfigurationTest.java
@@ -53,7 +53,7 @@
/** Test the various property methods. */
public void testConfiguration() throws IOException, SAXException {
- Configuration c = new Configuration(tmpFile.toURL());
+ Configuration c = new Configuration(tmpFile.toURI().toURL());
Properties props = new Properties();
props.setProperty("globalKey1", "preset-value");
c.mergeProperties(props);
diff --git a/curator/services/src/main/java/org/apache/oodt/cas/curation/service/MetadataResource.java b/curator/services/src/main/java/org/apache/oodt/cas/curation/service/MetadataResource.java
index 92901c2..bfc280e 100644
--- a/curator/services/src/main/java/org/apache/oodt/cas/curation/service/MetadataResource.java
+++ b/curator/services/src/main/java/org/apache/oodt/cas/curation/service/MetadataResource.java
@@ -662,7 +662,7 @@
InstantiationException, RepositoryManagerException {
String rootPolicyPath = this.cleanse(CurationService.config
.getPolicyUploadPath());
- String policyPath = new File(rootPolicyPath + policy).toURL()
+ String policyPath = new File(rootPolicyPath + policy).toURI().toURL()
.toExternalForm();
String[] policies = { policyPath };
XMLRepositoryManager repMgr = new XMLRepositoryManager(Arrays
@@ -678,7 +678,7 @@
CurationException {
String rootPolicyPath = this.cleanse(CurationService.config
.getPolicyUploadPath());
- String policyPath = new File(rootPolicyPath + policy).toURL()
+ String policyPath = new File(rootPolicyPath + policy).toURI().toURL()
.toExternalForm();
String[] policies = {policyPath};
XMLRepositoryManager repMgr = new XMLRepositoryManager(Arrays
diff --git a/curator/services/src/main/java/org/apache/oodt/cas/curation/service/PolicyResource.java b/curator/services/src/main/java/org/apache/oodt/cas/curation/service/PolicyResource.java
index c3bd174..6002078 100644
--- a/curator/services/src/main/java/org/apache/oodt/cas/curation/service/PolicyResource.java
+++ b/curator/services/src/main/java/org/apache/oodt/cas/curation/service/PolicyResource.java
@@ -264,7 +264,7 @@
RepositoryManagerException {
String rootPolicyPath = this.cleanse(CurationService.config
.getPolicyUploadPath());
- String policyPath = new File(rootPolicyPath + policy).toURL()
+ String policyPath = new File(rootPolicyPath + policy).toURI().toURL()
.toExternalForm();
String[] policies = { policyPath };
XMLRepositoryManager repMgr = new XMLRepositoryManager(Arrays
diff --git a/filemgr/src/main/java/org/apache/oodt/cas/filemgr/tools/ExpImpCatalog.java b/filemgr/src/main/java/org/apache/oodt/cas/filemgr/tools/ExpImpCatalog.java
index c2db95f..ba53d32 100644
--- a/filemgr/src/main/java/org/apache/oodt/cas/filemgr/tools/ExpImpCatalog.java
+++ b/filemgr/src/main/java/org/apache/oodt/cas/filemgr/tools/ExpImpCatalog.java
@@ -110,7 +110,7 @@
// first load the source prop file
try {
System.getProperties().load(
- new File(sPropFilePath).toURL().openStream());
+ new File(sPropFilePath).toURI().toURL().openStream());
} catch (Exception e) {
throw new InstantiationException(e.getMessage());
}
@@ -125,7 +125,7 @@
// first load the dest prop file
try {
System.getProperties().load(
- new File(dPropFilePath).toURL().openStream());
+ new File(dPropFilePath).toURI().toURL().openStream());
} catch (Exception e) {
throw new InstantiationException(e.getMessage());
}
diff --git a/filemgr/src/main/java/org/apache/oodt/cas/filemgr/validation/XMLValidationLayer.java b/filemgr/src/main/java/org/apache/oodt/cas/filemgr/validation/XMLValidationLayer.java
index 1c90e49..fe00437 100644
--- a/filemgr/src/main/java/org/apache/oodt/cas/filemgr/validation/XMLValidationLayer.java
+++ b/filemgr/src/main/java/org/apache/oodt/cas/filemgr/validation/XMLValidationLayer.java
@@ -469,7 +469,7 @@
InputStream xmlInputStream;
try {
- xmlInputStream = new File(xmlFile).toURL().openStream();
+ xmlInputStream = new File(xmlFile).toURI().toURL().openStream();
} catch (IOException e) {
LOG.log(Level.WARNING,
"IOException when getting input stream from [" + xmlFile
diff --git a/filemgr/src/main/java/org/apache/oodt/cas/filemgr/versioning/BasicVersioner.java b/filemgr/src/main/java/org/apache/oodt/cas/filemgr/versioning/BasicVersioner.java
index 437c4d2..8795ce6 100644
--- a/filemgr/src/main/java/org/apache/oodt/cas/filemgr/versioning/BasicVersioner.java
+++ b/filemgr/src/main/java/org/apache/oodt/cas/filemgr/versioning/BasicVersioner.java
@@ -84,7 +84,7 @@
String dataStoreRef;
try {
- dataStoreRef = new File(new URI(productRepoPath)).toURL()
+ dataStoreRef = new File(new URI(productRepoPath)).toURI().toURL()
.toExternalForm();
if(!dataStoreRef.endsWith("/")){
dataStoreRef+="/";
diff --git a/filemgr/src/main/java/org/apache/oodt/cas/filemgr/versioning/DateTimeVersioner.java b/filemgr/src/main/java/org/apache/oodt/cas/filemgr/versioning/DateTimeVersioner.java
index e72ab97..48e48aa 100644
--- a/filemgr/src/main/java/org/apache/oodt/cas/filemgr/versioning/DateTimeVersioner.java
+++ b/filemgr/src/main/java/org/apache/oodt/cas/filemgr/versioning/DateTimeVersioner.java
@@ -109,7 +109,7 @@
try {
dataStoreRef = new File(new URI(product.getProductType()
- .getProductRepositoryPath())).toURL()
+ .getProductRepositoryPath())).toURI().toURL()
.toExternalForm()
+ "/"
+ product.getProductName()
@@ -154,7 +154,7 @@
try {
String dataStoreRef = new File(new URI(product.getProductType()
- .getProductRepositoryPath())).toURL().toExternalForm()
+ .getProductRepositoryPath())).toURI().toURL().toExternalForm()
+ URLEncoder.encode(product.getProductName(), "UTF-8")
+ "/";
LOG.log(Level.INFO,
diff --git a/filemgr/src/main/java/org/apache/oodt/cas/filemgr/versioning/VersioningUtils.java b/filemgr/src/main/java/org/apache/oodt/cas/filemgr/versioning/VersioningUtils.java
index 8028bec..72ddeb6 100644
--- a/filemgr/src/main/java/org/apache/oodt/cas/filemgr/versioning/VersioningUtils.java
+++ b/filemgr/src/main/java/org/apache/oodt/cas/filemgr/versioning/VersioningUtils.java
@@ -88,7 +88,7 @@
if (!dir.equals(dirRoot)) {
try {
Reference r = new Reference();
- r.setOrigReference(dir.toURL().toExternalForm());
+ r.setOrigReference(dir.toURI().toURL().toExternalForm());
r.setFileSize(dir.length());
references.add(r);
} catch (MalformedURLException e) {
@@ -106,7 +106,7 @@
// add the file references
try {
Reference r = new Reference();
- r.setOrigReference(file.toURL().toExternalForm());
+ r.setOrigReference(file.toURI().toURL().toExternalForm());
r.setFileSize(file.length());
references.add(r);
} catch (MalformedURLException e) {
@@ -221,7 +221,7 @@
String productRepoPathRef;
try {
- productRepoPathRef = new File(new URI(productRepoPath)).toURL()
+ productRepoPathRef = new File(new URI(productRepoPath)).toURI().toURL()
.toExternalForm();
if (!productRepoPathRef.endsWith("/")) {
diff --git a/filemgr/src/test/java/org/apache/oodt/cas/filemgr/metadata/extractors/TestAbstractFilemgrMetExtractor.java b/filemgr/src/test/java/org/apache/oodt/cas/filemgr/metadata/extractors/TestAbstractFilemgrMetExtractor.java
index 4b1e1d8..013605d 100644
--- a/filemgr/src/test/java/org/apache/oodt/cas/filemgr/metadata/extractors/TestAbstractFilemgrMetExtractor.java
+++ b/filemgr/src/test/java/org/apache/oodt/cas/filemgr/metadata/extractors/TestAbstractFilemgrMetExtractor.java
@@ -92,11 +92,11 @@
"urn:oodt:GenericFile");
String refUri = null;
try {
- refUri = new File(tmpDirFullPath).toURL().toExternalForm();
+ refUri = new File(tmpDirFullPath).toURI().toURL().toExternalForm();
prod.setProductStructure(Product.STRUCTURE_HIERARCHICAL);
prod.getProductType()
.setProductRepositoryPath(
- new File(tmpDirFullPath).getParentFile().toURL()
+ new File(tmpDirFullPath).getParentFile().toURI().toURL()
.toString());
} catch (Exception e) {
fail(e.getMessage());
diff --git a/filemgr/src/test/java/org/apache/oodt/cas/filemgr/structs/type/TestTypeHandler.java b/filemgr/src/test/java/org/apache/oodt/cas/filemgr/structs/type/TestTypeHandler.java
index fd7668d..d3d12bc 100644
--- a/filemgr/src/test/java/org/apache/oodt/cas/filemgr/structs/type/TestTypeHandler.java
+++ b/filemgr/src/test/java/org/apache/oodt/cas/filemgr/structs/type/TestTypeHandler.java
@@ -234,7 +234,7 @@
List<Reference> refs = new LinkedList<Reference>();
URL refUrl = this.getClass().getResource("/ingest/test.txt");
Reference ref = new Reference();
- ref.setOrigReference(new File(refUrl.getFile()).toURL().toExternalForm());
+ ref.setOrigReference(new File(refUrl.getFile()).toURI().toURL().toExternalForm());
ref.setFileSize(123);
refs.add(ref);
testProduct.setProductReferences(refs);
diff --git a/filemgr/src/test/java/org/apache/oodt/cas/filemgr/versioning/TestBasicVersioner.java b/filemgr/src/test/java/org/apache/oodt/cas/filemgr/versioning/TestBasicVersioner.java
index b480c75..3f97872 100644
--- a/filemgr/src/test/java/org/apache/oodt/cas/filemgr/versioning/TestBasicVersioner.java
+++ b/filemgr/src/test/java/org/apache/oodt/cas/filemgr/versioning/TestBasicVersioner.java
@@ -69,13 +69,13 @@
p.setProductName("test_product");
p.setProductStructure(Product.STRUCTURE_FLAT);
ProductType type = new ProductType();
- type.setProductRepositoryPath("file:///foo/bar");
+ type.setProductRepositoryPath("file:///foo/space%20bar");
p.setProductType(type);
List refs = new Vector();
try {
URL url = this.getClass().getResource("/test.txt");
- String refname = new File(url.getFile()).toURL().toExternalForm();
+ String refname = new File(url.getFile()).toURI().toURL().toExternalForm();
refs.add(refname);
} catch (MalformedURLException e) {
fail(e.getMessage());
@@ -94,16 +94,16 @@
assertNotNull(generatedRef);
assertEquals("Versioned refs not equal: ref=[" + generatedRef + "]",
- "file:/foo/bar/test_product/test.txt", generatedRef);
+ "file:/foo/space%20bar/test_product/test.txt", generatedRef);
}
public void testVersionHierarchical() {
- String expected = "file:/archive/testdir/";
+ String expected = "file:/space%20archive/testdir/";
Product p = Product
.getDefaultFlatProduct("testdir", "urn:oodt:GenericFile");
p.setProductStructure(Product.STRUCTURE_HIERARCHICAL);
- p.getProductType().setProductRepositoryPath("file:///archive");
+ p.getProductType().setProductRepositoryPath("file:///space%20archive");
p.getProductReferences().add(
new Reference("file:///tmp/somedir/", null, 4L));
diff --git a/filemgr/src/test/java/org/apache/oodt/cas/filemgr/versioning/TestDateTimeVersioner.java b/filemgr/src/test/java/org/apache/oodt/cas/filemgr/versioning/TestDateTimeVersioner.java
index e4c4661..00b49b4 100644
--- a/filemgr/src/test/java/org/apache/oodt/cas/filemgr/versioning/TestDateTimeVersioner.java
+++ b/filemgr/src/test/java/org/apache/oodt/cas/filemgr/versioning/TestDateTimeVersioner.java
@@ -72,7 +72,7 @@
Product product = new Product();
ProductType type = new ProductType();
- type.setProductRepositoryPath("file:///foo/bar");
+ type.setProductRepositoryPath("file:///foo/space%20bar");
product.setProductName("test_product");
product.setProductStructure(Product.STRUCTURE_FLAT);
product.setProductType(type);
@@ -88,7 +88,7 @@
List refs = new Vector();
try {
URL url = this.getClass().getResource("/test.txt");
- String refname = new File(url.getFile()).toURL().toExternalForm();
+ String refname = new File(url.getFile()).toURI().toURL().toExternalForm();
refs.add(refname);
} catch (MalformedURLException e) {
fail(e.getMessage());
@@ -107,9 +107,9 @@
assertNotNull(generatedRef);
assertEquals(
"Generated ref does not equal expected ref: generatedRef=["
- + generatedRef + "], expected=[file:/foo/bar/test_product" +
+ + generatedRef + "], expected=[file:/foo/space%20bar/test_product" +
"/test.txt."+prodDateTimeNonIso+"]",
- "file:/foo/bar/test_product/test.txt."
+ "file:/foo/space%20bar/test_product/test.txt."
+ prodDateTimeNonIso, generatedRef);
}
diff --git a/metadata/src/main/java/org/apache/oodt/cas/metadata/extractors/CopyAndRewriteConfigReader.java b/metadata/src/main/java/org/apache/oodt/cas/metadata/extractors/CopyAndRewriteConfigReader.java
index 016b59e..d7deb08 100644
--- a/metadata/src/main/java/org/apache/oodt/cas/metadata/extractors/CopyAndRewriteConfigReader.java
+++ b/metadata/src/main/java/org/apache/oodt/cas/metadata/extractors/CopyAndRewriteConfigReader.java
@@ -46,7 +46,7 @@
throws MetExtractorConfigReaderException {
try {
CopyAndRewriteConfig config = new CopyAndRewriteConfig();
- config.load(configFile.toURL().openStream());
+ config.load(configFile.toURI().toURL().openStream());
return config;
} catch (Exception e) {
throw new MetExtractorConfigReaderException("Failed to parse '"
diff --git a/metadata/src/main/java/org/apache/oodt/cas/metadata/extractors/CopyAndRewriteExtractor.java b/metadata/src/main/java/org/apache/oodt/cas/metadata/extractors/CopyAndRewriteExtractor.java
index b3ba890..3314046 100644
--- a/metadata/src/main/java/org/apache/oodt/cas/metadata/extractors/CopyAndRewriteExtractor.java
+++ b/metadata/src/main/java/org/apache/oodt/cas/metadata/extractors/CopyAndRewriteExtractor.java
@@ -84,7 +84,7 @@
try {
met = new SerializableMetadata(new File(PathUtils
.replaceEnvVariables(((CopyAndRewriteConfig) this.config)
- .getProperty("orig.met.file.path"))).toURL()
+ .getProperty("orig.met.file.path"))).toURI().toURL()
.openStream());
} catch (Exception e) {
LOG.log(Level.SEVERE, e.getMessage());
diff --git a/pcs/input/src/main/java/org/apache/oodt/pcs/input/PGEXMLFileUtils.java b/pcs/input/src/main/java/org/apache/oodt/pcs/input/PGEXMLFileUtils.java
index 1fb8677..8f3795d 100644
--- a/pcs/input/src/main/java/org/apache/oodt/pcs/input/PGEXMLFileUtils.java
+++ b/pcs/input/src/main/java/org/apache/oodt/pcs/input/PGEXMLFileUtils.java
@@ -338,7 +338,7 @@
InputStream xmlInputStream;
try {
- xmlInputStream = new File(xmlFile).toURL().openStream();
+ xmlInputStream = new File(xmlFile).toURI().toURL().openStream();
} catch (IOException e) {
LOG.log(Level.WARNING, "IOException when getting input stream from ["
+ xmlFile + "]: returning null document root");
diff --git a/pge/src/main/java/org/apache/oodt/cas/pge/PGETask.java b/pge/src/main/java/org/apache/oodt/cas/pge/PGETask.java
index d55c532..68a4eda 100644
--- a/pge/src/main/java/org/apache/oodt/cas/pge/PGETask.java
+++ b/pge/src/main/java/org/apache/oodt/cas/pge/PGETask.java
@@ -79,11 +79,11 @@
}
SerializableMetadata sm = new SerializableMetadata("UTF-8", false);
- sm.loadMetadataFromXmlStream(new File(metadataFilePath).toURL()
+ sm.loadMetadataFromXmlStream(new File(metadataFilePath).toURI().toURL()
.openStream());
WorkflowTaskConfiguration config = new WorkflowTaskConfiguration();
config.getProperties().load(
- new File(configPropertiesPath).toURL().openStream());
+ new File(configPropertiesPath).toURI().toURL().openStream());
PGETask task = new PGETask(sm, config);
task.run(pgeTaskInstanceClasspath);
diff --git a/workflow/src/main/java/org/apache/oodt/cas/workflow/instrepo/WorkflowInstanceMetadataReader.java b/workflow/src/main/java/org/apache/oodt/cas/workflow/instrepo/WorkflowInstanceMetadataReader.java
index 406846b..4929796 100644
--- a/workflow/src/main/java/org/apache/oodt/cas/workflow/instrepo/WorkflowInstanceMetadataReader.java
+++ b/workflow/src/main/java/org/apache/oodt/cas/workflow/instrepo/WorkflowInstanceMetadataReader.java
@@ -119,7 +119,7 @@
InputStream xmlInputStream;
try {
- xmlInputStream = new File(xmlFile).toURL().openStream();
+ xmlInputStream = new File(xmlFile).toURI().toURL().openStream();
} catch (IOException e) {
LOG.log(Level.WARNING,
"IOException when getting input stream from [" + xmlFile
diff --git a/workflow/src/main/java/org/apache/oodt/cas/workflow/lifecycle/WorkflowLifecyclesReader.java b/workflow/src/main/java/org/apache/oodt/cas/workflow/lifecycle/WorkflowLifecyclesReader.java
index b42b8d8..9748c29 100644
--- a/workflow/src/main/java/org/apache/oodt/cas/workflow/lifecycle/WorkflowLifecyclesReader.java
+++ b/workflow/src/main/java/org/apache/oodt/cas/workflow/lifecycle/WorkflowLifecyclesReader.java
@@ -168,7 +168,7 @@
InputStream xmlInputStream;
try {
- xmlInputStream = new File(xmlFile).toURL().openStream();
+ xmlInputStream = new File(xmlFile).toURI().toURL().openStream();
} catch (IOException e) {
LOG.log(Level.WARNING,
"IOException when getting input stream from [" + xmlFile
diff --git a/workflow/src/main/java/org/apache/oodt/cas/workflow/policy/TaskPolicyReader.java b/workflow/src/main/java/org/apache/oodt/cas/workflow/policy/TaskPolicyReader.java
index 3a0dc41..95b1400 100644
--- a/workflow/src/main/java/org/apache/oodt/cas/workflow/policy/TaskPolicyReader.java
+++ b/workflow/src/main/java/org/apache/oodt/cas/workflow/policy/TaskPolicyReader.java
@@ -186,7 +186,7 @@
InputStream xmlInputStream = null;
try {
- xmlInputStream = new File(xmlFile).toURL().openStream();
+ xmlInputStream = new File(xmlFile).toURI().toURL().openStream();
} catch (IOException e) {
LOG.log(Level.WARNING,
"IOException when getting input stream from [" + xmlFile
diff --git a/workflow/src/main/java/org/apache/oodt/cas/workflow/repository/XMLWorkflowRepository.java b/workflow/src/main/java/org/apache/oodt/cas/workflow/repository/XMLWorkflowRepository.java
index 0b67db2..c946bbe 100644
--- a/workflow/src/main/java/org/apache/oodt/cas/workflow/repository/XMLWorkflowRepository.java
+++ b/workflow/src/main/java/org/apache/oodt/cas/workflow/repository/XMLWorkflowRepository.java
@@ -670,7 +670,7 @@
InputStream xmlInputStream;
try {
- xmlInputStream = new File(xmlFile).toURL().openStream();
+ xmlInputStream = new File(xmlFile).toURI().toURL().openStream();
} catch (IOException e) {
LOG.log(Level.WARNING,
"IOException when getting input stream from [" + xmlFile