You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ode.apache.org by mi...@apache.org on 2009/03/31 23:29:21 UTC

svn commit: r760658 - in /ode/branches/APACHE_ODE_1.X: axis2/src/main/java/org/apache/ode/axis2/ utils/src/main/java/org/apache/ode/utils/ utils/src/test/java/org/apache/ode/utils/ utils/src/test/resources/

Author: midon
Date: Tue Mar 31 21:29:21 2009
New Revision: 760658

URL: http://svn.apache.org/viewvc?rev=760658&view=rev
Log:
ODE-566: resolve relative paths in HierarchicalProperties.java

Modified:
    ode/branches/APACHE_ODE_1.X/axis2/src/main/java/org/apache/ode/axis2/SoapExternalService.java
    ode/branches/APACHE_ODE_1.X/utils/src/main/java/org/apache/ode/utils/HierarchicalProperties.java
    ode/branches/APACHE_ODE_1.X/utils/src/test/java/org/apache/ode/utils/HierarchicalPropertiesTest.java
    ode/branches/APACHE_ODE_1.X/utils/src/test/resources/hierarchical-1.properties

Modified: ode/branches/APACHE_ODE_1.X/axis2/src/main/java/org/apache/ode/axis2/SoapExternalService.java
URL: http://svn.apache.org/viewvc/ode/branches/APACHE_ODE_1.X/axis2/src/main/java/org/apache/ode/axis2/SoapExternalService.java?rev=760658&r1=760657&r2=760658&view=diff
==============================================================================
--- ode/branches/APACHE_ODE_1.X/axis2/src/main/java/org/apache/ode/axis2/SoapExternalService.java (original)
+++ ode/branches/APACHE_ODE_1.X/axis2/src/main/java/org/apache/ode/axis2/SoapExternalService.java Tue Mar 31 21:29:21 2009
@@ -296,13 +296,7 @@
         Options options = serviceClient.getOptions();
         if (options.getProperty(Properties.PROP_SECURITY_POLICY) != null) {
             String policy = (String) options.getProperty(Properties.PROP_SECURITY_POLICY);
-            // if the policy path is relative, the full uri is resolved against the process conf directory
-            URI policyUri;
-            if (FileUtils.isRelative(policy)) {
-                policyUri = _pconf.getBaseURI().resolve(policy);
-            } else {
-                policyUri = new File(policy).toURI();
-            }
+            URI policyUri = new File(policy).toURI();
             if(__log.isDebugEnabled()) __log.debug("Applying security policy: "+policyUri);
             try {
                 InputStream policyStream = policyUri.toURL().openStream();

Modified: ode/branches/APACHE_ODE_1.X/utils/src/main/java/org/apache/ode/utils/HierarchicalProperties.java
URL: http://svn.apache.org/viewvc/ode/branches/APACHE_ODE_1.X/utils/src/main/java/org/apache/ode/utils/HierarchicalProperties.java?rev=760658&r1=760657&r2=760658&view=diff
==============================================================================
--- ode/branches/APACHE_ODE_1.X/utils/src/main/java/org/apache/ode/utils/HierarchicalProperties.java (original)
+++ ode/branches/APACHE_ODE_1.X/utils/src/main/java/org/apache/ode/utils/HierarchicalProperties.java Tue Mar 31 21:29:21 2009
@@ -23,6 +23,7 @@
 import org.apache.commons.collections.*;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.ode.utils.fs.FileUtils;
 
 import javax.xml.namespace.QName;
 import java.io.File;
@@ -74,8 +75,12 @@
  * getProperty("http://foo.com", "port-of-amsterdam", "timeout")                                     => 40000
  * </pre>
  * <p/>
+ * <p>
  * Values may contain some environment variables. For instance, message=You're using ${java.version}.
  * <p/>
+ * <p>
+ * If a property name ends with ".file" or ".path", the assumption is made that the associated value is a path and as such is resolved against the path of the file it was loaded from.
+ * </p>
  * This class is not thread-safe.
  *
  * @author <a href="mailto:midon@intalio.com">Alexis Midon</a>
@@ -226,12 +231,19 @@
                 hierarchicalMap.put(qname, port, p);
             }
 
+            if(targetedProperty.endsWith(".file") || targetedProperty.endsWith(".path")){
+                String absolutePath = file.toURI().resolve(value).getPath();
+                if(log.isDebugEnabled()) log.debug("path: "+value+" resolved into: "+absolutePath);
+                value = absolutePath;
+            }
+
             // save the key/value in its chained map
             if(log.isDebugEnabled()) log.debug("New property: "+targetedProperty+" -> "+value);
             p.put(targetedProperty, value);
         }
     }
 
+
     /**
      * Clear all content. If {@link #loadFiles()} is not invoked later, all returned values will be null.
      */
@@ -362,7 +374,7 @@
      * That's the main reason to not used the {@link java.util.Properties} class (which offers access to child keys only).
      * <p/>The child has an immutable view of the parent map. Methods {@link #clear()} and {@link #remove(Object)}
      * throw {@link UnsupportedOperationException}. Methods {@link #put(Object, Object)} and  {@link #putAll(java.util.Map)} impacts only the child map.
-     * <br/>Methods  {@link #clearLocally(Object)}
+     * <br/>Methods  {@link #clearLocally()}
      * <p/>
      * This class does NOT implement the {@link java.util.Map} interface because methods {@link java.util.Map#entrySet()} },
      * {@link java.util.Map#values()} and {@link java.util.Map#keySet()} would NOT be backed by the Map itself.

Modified: ode/branches/APACHE_ODE_1.X/utils/src/test/java/org/apache/ode/utils/HierarchicalPropertiesTest.java
URL: http://svn.apache.org/viewvc/ode/branches/APACHE_ODE_1.X/utils/src/test/java/org/apache/ode/utils/HierarchicalPropertiesTest.java?rev=760658&r1=760657&r2=760658&view=diff
==============================================================================
--- ode/branches/APACHE_ODE_1.X/utils/src/test/java/org/apache/ode/utils/HierarchicalPropertiesTest.java (original)
+++ ode/branches/APACHE_ODE_1.X/utils/src/test/java/org/apache/ode/utils/HierarchicalPropertiesTest.java Tue Mar 31 21:29:21 2009
@@ -27,6 +27,8 @@
 import java.util.List;
 import java.util.Map;
 
+import org.apache.ode.utils.fs.FileUtils;
+
 /**
  * @author <a href="mailto:midon@intalio.com">Alexis Midon</a>
  */
@@ -68,6 +70,13 @@
         assertSame("Snapshot maps should be cached!", hp.getProperties("bla", "unknown-service"), hp.getProperties("bla", "unknown-service"));
     }
 
+    public void testPathHandling(){
+        assertTrue("If the property name ends with '.file' or '.path' its value might be resolved against the file path", FileUtils.isAbsolute(hp.getProperty("http://foo.com", "film-service", "port-of-cannes", "p1.file")));
+        assertTrue("If the property name ends with '.file' or '.path' its value might be resolved against the file path", FileUtils.isAbsolute(hp.getProperty("http://foo.com", "film-service", "port-of-cannes", "p1.path")));
+        assertEquals("An absolute path should not be altered", "/home/ode/hello.txt", hp.getProperty("http://foo.com", "film-service", "port-of-cannes", "p2.path"));
+
+    }
+
     public void testWithNoFile() throws IOException {
         File file = new File("/a-file-that-does-not-exist");
         Map m = new HierarchicalProperties(file).getProperties("an-uri", "a-service", "a-port");

Modified: ode/branches/APACHE_ODE_1.X/utils/src/test/resources/hierarchical-1.properties
URL: http://svn.apache.org/viewvc/ode/branches/APACHE_ODE_1.X/utils/src/test/resources/hierarchical-1.properties?rev=760658&r1=760657&r2=760658&view=diff
==============================================================================
--- ode/branches/APACHE_ODE_1.X/utils/src/test/resources/hierarchical-1.properties (original)
+++ ode/branches/APACHE_ODE_1.X/utils/src/test/resources/hierarchical-1.properties Tue Mar 31 21:29:21 2009
@@ -10,5 +10,9 @@
 bar.brel-service.port-of-amsterdam.ode.max-redirects=60
 ode.a.property.beginning.with.the.prefix.but.no.service=so green or red?
 
-
 a_namespace_with_no_alias.a_service.ode.poolsize=4
+
+
+foo.film-service.port-of-cannes.ode.p1.path=hello.txt
+foo.film-service.port-of-cannes.ode.p1.file=hello.txt
+foo.film-service.port-of-cannes.ode.p2.path=/home/ode/hello.txt
\ No newline at end of file