Author: midon
Date: Tue Mar 31 22:15:20 2009
New Revision: 760677

URL: http://svn.apache.org/viewvc?rev=760677&view=rev
Log:
ODE-566: allow endpoint files in subdirectories

Added:
    ode/trunk/axis2-war/src/test/resources/TestEndpointProperties/alpha_subdir/
    
ode/trunk/axis2-war/src/test/resources/TestEndpointProperties/alpha_subdir/test-endpoint-properties-deploy-unit_headerBB_2.endpoint
      - copied, changed from r759388, 
ode/trunk/axis2-war/src/test/resources/TestEndpointProperties/test-endpoint-properties-deploy-unit_headerBB_2.endpoint
    
ode/trunk/axis2-war/src/test/resources/TestEndpointProperties/alpha_subdir/test-endpoint-properties-deploy-unit_headerBB_2.endpoint.rej
Removed:
    
ode/trunk/axis2-war/src/test/resources/TestEndpointProperties/test-endpoint-properties-deploy-unit_headerBB_2.endpoint
Modified:
    
ode/trunk/axis2-war/src/test/resources/TestRampartPolicy/secured-services/process-template/config.endpoint
    
ode/trunk/axis2/src/main/java/org/apache/ode/axis2/service/DeploymentBrowser.java
    
ode/trunk/axis2/src/main/java/org/apache/ode/axis2/soapbinding/SoapExternalService.java
    
ode/trunk/bpel-store/src/main/java/org/apache/ode/store/DeploymentUnitDir.java
    
ode/trunk/utils/src/main/java/org/apache/ode/utils/HierarchicalProperties.java
    ode/trunk/utils/src/main/java/org/apache/ode/utils/Properties.java
    ode/trunk/utils/src/main/java/org/apache/ode/utils/fs/FileUtils.java
    
ode/trunk/utils/src/test/java/org/apache/ode/utils/HierarchicalPropertiesTest.java
    ode/trunk/utils/src/test/resources/hierarchical-1.properties

Copied: 
ode/trunk/axis2-war/src/test/resources/TestEndpointProperties/alpha_subdir/test-endpoint-properties-deploy-unit_headerBB_2.endpoint
 (from r759388, 
ode/trunk/axis2-war/src/test/resources/TestEndpointProperties/test-endpoint-properties-deploy-unit_headerBB_2.endpoint)
URL: 
http://svn.apache.org/viewvc/ode/trunk/axis2-war/src/test/resources/TestEndpointProperties/alpha_subdir/test-endpoint-properties-deploy-unit_headerBB_2.endpoint?p2=ode/trunk/axis2-war/src/test/resources/TestEndpointProperties/alpha_subdir/test-endpoint-properties-deploy-unit_headerBB_2.endpoint&p1=ode/trunk/axis2-war/src/test/resources/TestEndpointProperties/test-endpoint-properties-deploy-unit_headerBB_2.endpoint&r1=759388&r2=760677&rev=760677&view=diff
==============================================================================
    (empty)

Added: 
ode/trunk/axis2-war/src/test/resources/TestEndpointProperties/alpha_subdir/test-endpoint-properties-deploy-unit_headerBB_2.endpoint.rej
URL: 
http://svn.apache.org/viewvc/ode/trunk/axis2-war/src/test/resources/TestEndpointProperties/alpha_subdir/test-endpoint-properties-deploy-unit_headerBB_2.endpoint.rej?rev=760677&view=auto
==============================================================================
--- 
ode/trunk/axis2-war/src/test/resources/TestEndpointProperties/alpha_subdir/test-endpoint-properties-deploy-unit_headerBB_2.endpoint.rej
 (added)
+++ 
ode/trunk/axis2-war/src/test/resources/TestEndpointProperties/alpha_subdir/test-endpoint-properties-deploy-unit_headerBB_2.endpoint.rej
 Tue Mar 31 22:15:20 2009
@@ -0,0 +1,7 @@
+***************
+*** 0 ****
+--- 1,4 ----
++ 
++ alias.myns2=http://ode/bpel/test/properties
++ 
++ 
myns2.PropertiesService.ode.http.default-headers.header_BB=from_deployment_unit#file2
\ No newline at end of file

Modified: 
ode/trunk/axis2-war/src/test/resources/TestRampartPolicy/secured-services/process-template/config.endpoint
URL: 
http://svn.apache.org/viewvc/ode/trunk/axis2-war/src/test/resources/TestRampartPolicy/secured-services/process-template/config.endpoint?rev=760677&r1=760676&r2=760677&view=diff
==============================================================================
--- 
ode/trunk/axis2-war/src/test/resources/TestRampartPolicy/secured-services/process-template/config.endpoint
 (original)
+++ 
ode/trunk/axis2-war/src/test/resources/TestRampartPolicy/secured-services/process-template/config.endpoint
 Tue Mar 31 22:15:20 2009
@@ -1,7 +1,7 @@
 
 
 alias.sample-ns={sample.namespace}
-sample-ns.{sample.service.name}.ode.security.policy={sample.service.name}.xml
+sample-ns.{sample.service.name}.ode.security.policy.file={sample.service.name}.xml
 
 #sample04 tends to time out
 sample-ns.sample04-policy.ode.mex.timeout=120000

Modified: 
ode/trunk/axis2/src/main/java/org/apache/ode/axis2/service/DeploymentBrowser.java
URL: 
http://svn.apache.org/viewvc/ode/trunk/axis2/src/main/java/org/apache/ode/axis2/service/DeploymentBrowser.java?rev=760677&r1=760676&r2=760677&view=diff
==============================================================================
--- 
ode/trunk/axis2/src/main/java/org/apache/ode/axis2/service/DeploymentBrowser.java
 (original)
+++ 
ode/trunk/axis2/src/main/java/org/apache/ode/axis2/service/DeploymentBrowser.java
 Tue Mar 31 22:15:20 2009
@@ -273,7 +273,7 @@
 
     private String bundleUrlFor(String docFile) {
         if (docFile.indexOf("processes") >= 0) docFile = 
docFile.substring(docFile.indexOf("processes")+10);
-        List<File> files = 
FileUtils.listFilesRecursively(_store.getDeployDir(), null);
+        List<File> files = 
FileUtils.directoryEntriesInPath(_store.getDeployDir(), null);
         for (final File bundleFile : files) {
             if (bundleFile.getPath().replaceAll("\\\\", "/").endsWith(docFile))
                 return "/deployment/bundles/" + bundleFile.getPath()

Modified: 
ode/trunk/axis2/src/main/java/org/apache/ode/axis2/soapbinding/SoapExternalService.java
URL: 
http://svn.apache.org/viewvc/ode/trunk/axis2/src/main/java/org/apache/ode/axis2/soapbinding/SoapExternalService.java?rev=760677&r1=760676&r2=760677&view=diff
==============================================================================
--- 
ode/trunk/axis2/src/main/java/org/apache/ode/axis2/soapbinding/SoapExternalService.java
 (original)
+++ 
ode/trunk/axis2/src/main/java/org/apache/ode/axis2/soapbinding/SoapExternalService.java
 Tue Mar 31 22:15:20 2009
@@ -245,13 +245,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();
             try {
                 InputStream policyStream = policyUri.toURL().openStream();
                 try {

Modified: 
ode/trunk/bpel-store/src/main/java/org/apache/ode/store/DeploymentUnitDir.java
URL: 
http://svn.apache.org/viewvc/ode/trunk/bpel-store/src/main/java/org/apache/ode/store/DeploymentUnitDir.java?rev=760677&r1=760676&r2=760677&view=diff
==============================================================================
--- 
ode/trunk/bpel-store/src/main/java/org/apache/ode/store/DeploymentUnitDir.java 
(original)
+++ 
ode/trunk/bpel-store/src/main/java/org/apache/ode/store/DeploymentUnitDir.java 
Tue Mar 31 22:15:20 2009
@@ -32,6 +32,7 @@
 import org.apache.ode.bpel.dd.TDeployment.Process;
 import org.apache.ode.bpel.iapi.ContextException;
 import org.apache.ode.bpel.rapi.Serializer;
+import org.apache.ode.utils.fs.FileUtils;
 import org.apache.xmlbeans.XmlOptions;
 import org.w3c.dom.Node;
 
@@ -127,7 +128,7 @@
      * starts compilation.
      */
     void compile() {
-        ArrayList<File> bpels = listFilesRecursively(_duDirectory, 
DeploymentUnitDir._bpelFilter);
+        List<File> bpels = FileUtils.directoryEntriesInPath(_duDirectory, 
DeploymentUnitDir._bpelFilter);
         if (bpels.size() == 0)
             throw new IllegalArgumentException("Directory " + 
_duDirectory.getName() + " does not contain any process!");
         for (File bpel : bpels) {
@@ -137,7 +138,7 @@
 
     void scan() {
         HashMap<QName, CBPInfo> processes = new HashMap<QName, CBPInfo>();
-        ArrayList<File> cbps = listFilesRecursively(_duDirectory, 
DeploymentUnitDir._cbpFilter);
+        List<File> cbps = FileUtils.directoryEntriesInPath(_duDirectory, 
DeploymentUnitDir._cbpFilter);
         for (File file : cbps) {
             CBPInfo cbpinfo = loadCBPInfo(file);
             processes.put(cbpinfo.processName, cbpinfo);
@@ -211,16 +212,17 @@
     }
 
     /**
+     * The list of endpoint configuration files contained in the deployment 
directory and its subdirectories.
+     * Files are ordered lexicographically but for each directory, files come 
before its sudirectories.
+     * <p>The list is built on each call to handle changes.
      *
-     * @return the list of endpoint configuration files. the list is built on 
each call to handle changes. 
+     * @see 
org.apache.ode.utils.fs.FileUtils#directoryEntriesInPath(java.io.File)
      */
-    public TreeSet<File> getEndpointConfigFiles() {
-        File[] files = getDeployDir().listFiles(_endpointFilter);
-        TreeSet<File> set = new TreeSet<File>();
-        set.addAll(Arrays.asList(files));
-        return set;
+    public List<File> getEndpointConfigFiles() {
+        return FileUtils.directoryEntriesInPath(getDeployDir(), 
_endpointFilter);
     }
 
+
     public DeployDocument getDeploymentDescriptor() {
         if (_dd == null) {
             File ddLocation = new File(_duDirectory, "deploy.xml");
@@ -249,7 +251,7 @@
             WSDLReader r = wsdlFactory.newWSDLReader();
             DefaultResourceFinder rf = new DefaultResourceFinder(_duDirectory, 
_duDirectory);
             URI basedir = _duDirectory.toURI();
-            ArrayList<File> wsdls = listFilesRecursively(_duDirectory, 
DeploymentUnitDir._wsdlFilter);
+            List<File> wsdls = FileUtils.directoryEntriesInPath(_duDirectory, 
DeploymentUnitDir._wsdlFilter);
             for (File file : wsdls) {
                 URI uri = basedir.relativize(file.toURI());
                 try {
@@ -311,23 +313,6 @@
         return result;
     }
 
-    private ArrayList<File> listFilesRecursively(File root, FileFilter filter) 
{
-        ArrayList<File> result = new ArrayList<File>();
-        // Filtering the files we're interested in in the current directory
-        File[] select = root.listFiles(filter);
-        for (File file : select) {
-            result.add(file);
-        }
-        // Then we can check the directories
-        File[] all = root.listFiles();
-        for (File file : all) {
-            if (file.isDirectory())
-                result.addAll(listFilesRecursively(file, filter));
-        }
-        return result;
-    }
-
-
     public final class CBPInfo {
         final QName processName;
         final String guid;

Modified: 
ode/trunk/utils/src/main/java/org/apache/ode/utils/HierarchicalProperties.java
URL: 
http://svn.apache.org/viewvc/ode/trunk/utils/src/main/java/org/apache/ode/utils/HierarchicalProperties.java?rev=760677&r1=760676&r2=760677&view=diff
==============================================================================
--- 
ode/trunk/utils/src/main/java/org/apache/ode/utils/HierarchicalProperties.java 
(original)
+++ 
ode/trunk/utils/src/main/java/org/apache/ode/utils/HierarchicalProperties.java 
Tue Mar 31 22:15:20 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:[email protected]";>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/trunk/utils/src/main/java/org/apache/ode/utils/Properties.java
URL: 
http://svn.apache.org/viewvc/ode/trunk/utils/src/main/java/org/apache/ode/utils/Properties.java?rev=760677&r1=760676&r2=760677&view=diff
==============================================================================
--- ode/trunk/utils/src/main/java/org/apache/ode/utils/Properties.java 
(original)
+++ ode/trunk/utils/src/main/java/org/apache/ode/utils/Properties.java Tue Mar 
31 22:15:20 2009
@@ -81,7 +81,7 @@
     public static final String PROP_HTTP_REQUEST_CHUNK = "http.request.chunk";
     public static final String PROP_HTTP_REQUEST_GZIP = "http.request.gzip";
     public static final String PROP_HTTP_ACCEPT_GZIP = "http.accept.gzip";
-    public static final String PROP_SECURITY_POLICY = "security.policy";
+    public static final String PROP_SECURITY_POLICY = "security.policy.file";
     public static final String PROP_JMS_REPLY_DESTINATION = 
"jms.reply.destination";
     public static final String PROP_JMS_REPLY_TIMEOUT = "jms.reply.timeout";
 

Modified: ode/trunk/utils/src/main/java/org/apache/ode/utils/fs/FileUtils.java
URL: 
http://svn.apache.org/viewvc/ode/trunk/utils/src/main/java/org/apache/ode/utils/fs/FileUtils.java?rev=760677&r1=760676&r2=760677&view=diff
==============================================================================
--- ode/trunk/utils/src/main/java/org/apache/ode/utils/fs/FileUtils.java 
(original)
+++ ode/trunk/utils/src/main/java/org/apache/ode/utils/fs/FileUtils.java Tue 
Mar 31 22:15:20 2009
@@ -23,6 +23,7 @@
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
+import java.util.TreeSet;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -105,7 +106,27 @@
 
     /**
      * Recursively collect all Files in the given directory and all its
-     * subdirectories, applying the given FileFilter.
+     * subdirectories, applying the given FileFilter. The FileFilter is also 
applied to the given rootDirectory.
+     * As a result the rootDirectory might be in the returned list.
+     * <p>
+     * Returned files are ordered lexicographically but for each directory, 
files come before its sudirectories.
+     * For instance:<br/>
+     * test<br/>
+     * test/alpha.txt<br/>
+     * test/zulu.txt<br/>
+     * test/a<br/>
+     * test/a/alpha.txt<br/>
+     * test/z<br/>
+     * test/z/zulu.txt<br/>
+     * <p>
+     * instead of:<br/>
+     * test<br/>
+     * test/a<br/>
+     * test/a/alpha.txt<br/>
+     * test/alpha.txt<br/>
+     * test/z<br/>
+     * test/z/zulu.txt<br/>
+     * test/zulu.txt<br/>
      *
      * @param rootDirectory
      *          the top level directory used for the search
@@ -140,19 +161,23 @@
             collectedFiles.add(parentDir);
         }
 
-        File[] files = parentDir.listFiles();
-        if (files != null) {
-            for (int numFiles = files.length, i = 0; i < numFiles; i++) {
-                File currentFile = files[i];
-
-                if ((filter == null) || ((filter != null) && 
(filter.accept(currentFile)))) {
-                    collectedFiles.add(currentFile);
-                }
-
-                if (currentFile.isDirectory()) {
-                    FileUtils.directoryEntriesInPath(collectedFiles, 
currentFile, filter);
+        File[] allFiles = parentDir.listFiles();
+        if (allFiles != null) {
+            TreeSet<File> dirs = new TreeSet<File>();
+                TreeSet<File> acceptedFiles = new TreeSet<File>();
+            for (File f : allFiles) {
+                if (f.isDirectory()) {
+                    dirs.add(f);
+                } else {
+                    if ((filter == null) || ((filter != null) && 
(filter.accept(f)))) {
+                        acceptedFiles.add(f);
+                    }
                 }
             }
+            collectedFiles.addAll(acceptedFiles);
+            for (File currentFile : dirs) {
+                FileUtils.directoryEntriesInPath(collectedFiles, currentFile, 
filter);
+            }
         }
     }
 
@@ -160,17 +185,11 @@
         return path.replaceAll(" ", "%20");
     }
 
-    public static ArrayList<File> listFilesRecursively(File root, FileFilter 
filter) {
-        ArrayList<File> result = new ArrayList<File>();
-        // Filtering the files we're interested in in the current directory
-        File[] select = root.listFiles(filter);
-        result.addAll(Arrays.asList(select));
-        // Then we can check the directories
-        File[] all = root.listFiles();
-        for (File file : all)
-            if (file.isDirectory())
-                result.addAll(listFilesRecursively(file, filter));
-        return result;
+    public static void main(String[] args) {
+        List<File> l = directoryEntriesInPath(new File("/tmp/test"));
+        for(File f : l) System.out.println(f);
+        System.out.println("########");
+     TreeSet<File> s= new TreeSet(l);
+        for(File f : s) System.out.println(f);
     }
-
 }

Modified: 
ode/trunk/utils/src/test/java/org/apache/ode/utils/HierarchicalPropertiesTest.java
URL: 
http://svn.apache.org/viewvc/ode/trunk/utils/src/test/java/org/apache/ode/utils/HierarchicalPropertiesTest.java?rev=760677&r1=760676&r2=760677&view=diff
==============================================================================
--- 
ode/trunk/utils/src/test/java/org/apache/ode/utils/HierarchicalPropertiesTest.java
 (original)
+++ 
ode/trunk/utils/src/test/java/org/apache/ode/utils/HierarchicalPropertiesTest.java
 Tue Mar 31 22:15:20 2009
@@ -27,6 +27,8 @@
 import java.util.List;
 import java.util.Map;
 
+import org.apache.ode.utils.fs.FileUtils;
+
 /**
  * @author <a href="mailto:[email protected]";>Alexis Midon</a>
  */
@@ -69,6 +71,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/trunk/utils/src/test/resources/hierarchical-1.properties
URL: 
http://svn.apache.org/viewvc/ode/trunk/utils/src/test/resources/hierarchical-1.properties?rev=760677&r1=760676&r2=760677&view=diff
==============================================================================
--- ode/trunk/utils/src/test/resources/hierarchical-1.properties (original)
+++ ode/trunk/utils/src/test/resources/hierarchical-1.properties Tue Mar 31 
22:15:20 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


Reply via email to