[jboss-svn-commits] JBL Code SVN: r24378 - in labs/jbossesb/trunk/product: rosetta/src/org/jboss/internal/soa/esb and 6 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Mon Dec 15 05:07:31 EST 2008


Author: mark.little at jboss.com
Date: 2008-12-15 05:07:31 -0500 (Mon, 15 Dec 2008)
New Revision: 24378

Added:
   labs/jbossesb/trunk/product/rosetta/src/org/jboss/internal/soa/esb/listeners/
   labs/jbossesb/trunk/product/rosetta/src/org/jboss/internal/soa/esb/listeners/gateway/
   labs/jbossesb/trunk/product/rosetta/src/org/jboss/internal/soa/esb/listeners/gateway/filefilter/
   labs/jbossesb/trunk/product/rosetta/src/org/jboss/internal/soa/esb/listeners/gateway/filefilter/FileEndsWith.java
   labs/jbossesb/trunk/product/rosetta/src/org/jboss/internal/soa/esb/listeners/gateway/filefilter/IgnoreFile.java
   labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/gateway/OverrideFileEndsWith.java
Modified:
   labs/jbossesb/trunk/product/docs/ProgrammersGuide.odt
   labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/ListenerTagNames.java
   labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/AbstractFileGateway.java
   labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/FileGatewayListener.java
   labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/gateway/FileGatewayListenerUnitTest.java
Log:
https://jira.jboss.org/jira/browse/JBESB-2178

Modified: labs/jbossesb/trunk/product/docs/ProgrammersGuide.odt
===================================================================
(Binary files differ)

Added: labs/jbossesb/trunk/product/rosetta/src/org/jboss/internal/soa/esb/listeners/gateway/filefilter/FileEndsWith.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/internal/soa/esb/listeners/gateway/filefilter/FileEndsWith.java	                        (rev 0)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/internal/soa/esb/listeners/gateway/filefilter/FileEndsWith.java	2008-12-15 10:07:31 UTC (rev 24378)
@@ -0,0 +1,51 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA  02110-1301, USA.
+ *
+ * (C) 2005-2006, JBoss Inc.
+ */
+
+package org.jboss.internal.soa.esb.listeners.gateway.filefilter;
+
+import java.io.File;
+import java.io.FileFilter;
+
+import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.soa.esb.util.Util;
+
+/**
+ * Simple file filter for local filesystem Will accept only files that end with
+ * the String supplied at constructor time
+ */
+
+// normal file filter
+public class FileEndsWith implements FileFilter
+{   
+    public FileEndsWith(String p_sEnd) throws ConfigurationException
+    {
+        m_sSuffix = p_sEnd;
+        
+        if (Util.isNullString(m_sSuffix))
+            throw new ConfigurationException("Must specify file extension");
+    }
+    
+    public boolean accept (File p_f)
+    {
+        return (p_f.isFile()) ? p_f.toString().endsWith(m_sSuffix) : false;
+    }
+    
+    private String m_sSuffix;
+}

Added: labs/jbossesb/trunk/product/rosetta/src/org/jboss/internal/soa/esb/listeners/gateway/filefilter/IgnoreFile.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/internal/soa/esb/listeners/gateway/filefilter/IgnoreFile.java	                        (rev 0)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/internal/soa/esb/listeners/gateway/filefilter/IgnoreFile.java	2008-12-15 10:07:31 UTC (rev 24378)
@@ -0,0 +1,74 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA  02110-1301, USA.
+ *
+ * (C) 2005-2006, JBoss Inc.
+ */
+
+package org.jboss.internal.soa.esb.listeners.gateway.filefilter;
+
+import java.io.File;
+import java.io.FileFilter;
+
+import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.soa.esb.util.Util;
+
+// worker file filter (used if input suffix is null)
+
+public class IgnoreFile implements FileFilter
+{
+    public IgnoreFile(String workSuffix, String errorSuffix, String postSuffix)
+            throws ConfigurationException
+    {
+        _workSuffix = workSuffix;
+        _errorSuffix = errorSuffix;
+        _postSuffix = postSuffix;
+
+        if (Util.isNullString(_workSuffix))
+            throw new ConfigurationException("Must specify workSuffix");
+        if (Util.isNullString(_errorSuffix))
+            throw new ConfigurationException("Must specify errorSuffix");
+        if (Util.isNullString(_postSuffix))
+            throw new ConfigurationException("Must specify postProcessSuffix");
+    } // ______________________________
+
+    public boolean accept (File p_f)
+    {
+        if (p_f.isFile())
+        {
+            /*
+             * If file is a work file then ignore it.
+             */
+
+            String fileName = p_f.toString();
+
+            if (fileName.endsWith(_workSuffix)
+                    || fileName.endsWith(_errorSuffix)
+                    || fileName.endsWith(_postSuffix))
+            {
+                return false;
+            }
+            else
+                return true;
+        }
+        else
+            return false;
+    }
+    
+    private String _workSuffix;
+    private String _errorSuffix;
+    private String _postSuffix;
+}

Modified: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/ListenerTagNames.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/ListenerTagNames.java	2008-12-15 05:10:01 UTC (rev 24377)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/ListenerTagNames.java	2008-12-15 10:07:31 UTC (rev 24378)
@@ -100,7 +100,9 @@
     public static final String GATEWAY_COMPOSER_CLASS_TAG   = "composer-class";
     public static final String GATEWAY_COMPOSER_METHOD_TAG  = "composer-process";
     public static final String GATEWAY_RESPONDER_METHOD_TAG = "responder-process";
-    public static final String GATEWAY_WAIT_MILLIS_TAG 		= "max-millis-for-response";
+    public static final String GATEWAY_WAIT_MILLIS_TAG 	    = "max-millis-for-response";
+    public static final String GATEWAY_FILE_FILTER_TAG      = "file-filter-class";
+    
     /** Routing */
     public static final String DESTINATION_NAME_TAG         = "destination-name";
     public static final String DESTINATION_TYPE_TAG 		= "destination-type";

Modified: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/AbstractFileGateway.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/AbstractFileGateway.java	2008-12-15 05:10:01 UTC (rev 24377)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/AbstractFileGateway.java	2008-12-15 10:07:31 UTC (rev 24378)
@@ -80,8 +80,6 @@
     protected String _inputSuffix, _postProcessSuffix, _workingSuffix,
             _errorSuffix;
 
-    protected FileFilter _fileFilter;
-
     protected AbstractFileGateway(ConfigTree config) throws ConfigurationException, RegistryException, GatewayException {
         super(config);
         this.config = config;

Modified: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/FileGatewayListener.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/FileGatewayListener.java	2008-12-15 05:10:01 UTC (rev 24377)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/FileGatewayListener.java	2008-12-15 10:07:31 UTC (rev 24378)
@@ -29,13 +29,21 @@
 import java.io.FileOutputStream;
 import java.io.IOException;
 
+import org.jboss.internal.soa.esb.listeners.gateway.filefilter.FileEndsWith;
+import org.jboss.internal.soa.esb.listeners.gateway.filefilter.IgnoreFile;
 import org.jboss.soa.esb.ConfigurationException;
 import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.listeners.ListenerTagNames;
 import org.jboss.soa.esb.services.registry.RegistryException;
+import org.jboss.soa.esb.util.ClassUtil;
 import org.jboss.soa.esb.util.FileUtil;
-import org.jboss.soa.esb.util.Util;
 
 public class FileGatewayListener extends AbstractFileGateway {
+    public interface FileFilterInit
+    {
+        void init (ConfigTree config) throws ConfigurationException;
+    };
+    
     /**
      * serial version uid for this class
      */
@@ -44,30 +52,67 @@
     public FileGatewayListener(ConfigTree config) throws ConfigurationException, RegistryException, GatewayException {
         super(config);
 
+        _filterClass = config.getAttribute(ListenerTagNames.GATEWAY_FILE_FILTER_TAG);
+        
         /*
            * JBESB-454 allowed gateways to pull files with any extension. Obvious
            * security issue, but we are explicit about this in the docs and users
            * should beware.
            */
 
-        if ((_inputSuffix == null) || (_inputSuffix.equals(""))) {
-            /*
-                * If no suffix, then inputDir must be different from outputDir
-                * or we go into an infinite loop. Already checked through
-                * checkMyParams.
-                */
+        if (_filterClass == null)
+        {
+            if ((_inputSuffix == null) || (_inputSuffix.equals(""))) {
+                /*
+                    * If no suffix, then inputDir must be different from outputDir
+                    * or we go into an infinite loop. Already checked through
+                    * checkMyParams.
+                    */
+    
+                _theFilter = new IgnoreFile(_workingSuffix, _errorSuffix, _postProcessSuffix);
 
-            _inputFileFilter = null;
-
-            /*
-                * If no input suffix, then we must have a work suffix and we
-                * must ignore worker files when sourcing new input files, or
-                * we end up in an infinite loop.
-                */
-
-            _ignoreFileFilter = new IgnoreFile(_workingSuffix, _errorSuffix, _postProcessSuffix);
-        } else
-            _inputFileFilter = new FileEndsWith(_inputSuffix);
+                /*
+                    * If no input suffix, then we must have a work suffix and we
+                    * must ignore worker files when sourcing new input files, or
+                    * we end up in an infinite loop.
+                    */
+            } else
+                _theFilter = new FileEndsWith(_inputSuffix);
+        }
+        else
+        {
+            try
+            {
+                Class c = ClassUtil.forName(_filterClass, getClass());
+                
+                _theFilter = (FileFilter) c.newInstance();
+                
+                if (_theFilter instanceof FileFilterInit)
+                {
+                    ((FileFilterInit) _theFilter).init(config);
+                }
+            }
+            catch (final ClassNotFoundException ex)
+            {
+                throw new ConfigurationException(ex);
+            }
+            catch (final IllegalAccessException ex)
+            {
+                throw new ConfigurationException(ex);
+            }
+            catch (final InstantiationException ex)
+            {
+                throw new ConfigurationException(ex);
+            }
+            catch (final ConfigurationException ex)
+            {
+                throw ex;
+            }
+            catch (final Exception ex)
+            {
+                throw new GatewayException(ex);
+            }
+        }
     }
 
     @Override
@@ -116,19 +161,7 @@
            * to be concerned about them.
            */
 
-        if (_inputFileFilter != null) {
-            /*
-            * Input suffix is not null.
-            */
-
-            return filterFiles(_inputDirectory, _inputFileFilter);
-        } else {
-            /*
-            * Input suffix is null so ignore any worker files.
-            */
-
-            return filterFiles(_inputDirectory, _ignoreFileFilter);
-        }
+        return filterFiles(_inputDirectory, _theFilter);
     }
 
     private File[] filterFiles(File dir, FileFilter filter) {
@@ -177,61 +210,7 @@
             _inputSuffix = "";
     }
 
-    /**
-     * Simple file filter for local filesystem Will accept only files that end
-     * with the String supplied at constructor time
-     */
-    private class FileEndsWith implements FileFilter {
-        String m_sSuffix;
+    private FileFilter _theFilter;
 
-        FileEndsWith(String p_sEnd) throws ConfigurationException {
-            m_sSuffix = p_sEnd;
-            if (Util.isNullString(m_sSuffix))
-                throw new ConfigurationException("Must specify file extension");
-        } // ______________________________
-
-        public boolean accept(File p_f) {
-            return (p_f.isFile()) ? p_f.toString().endsWith(m_sSuffix) : false;
-        }
-    }
-
-    private class IgnoreFile implements FileFilter {
-        String _workSuffix;
-        String _errorSuffix;
-        String _postSuffix;
-
-        IgnoreFile(String workSuffix, String errorSuffix, String postSuffix) throws ConfigurationException {
-            _workSuffix = workSuffix;
-            _errorSuffix = errorSuffix;
-            _postSuffix = postSuffix;
-
-            if (Util.isNullString(_workSuffix))
-                throw new ConfigurationException("Must specify workSuffix");
-            if (Util.isNullString(_errorSuffix))
-                throw new ConfigurationException("Must specify errorSuffix");
-            if (Util.isNullString(_postSuffix))
-                throw new ConfigurationException("Must specify postProcessSuffix");
-        } // ______________________________
-
-        public boolean accept(File p_f) {
-            if (p_f.isFile()) {
-                /*
-                 * If file is a work file then ignore it.
-                 */
-
-                String fileName = p_f.toString();
-
-                if (fileName.endsWith(_workSuffix) || fileName.endsWith(_errorSuffix) || fileName.endsWith(_postSuffix)) {
-                    return false;
-                } else
-                    return true;
-            } else
-                return false;
-        }
-    }
-
-    private FileFilter _inputFileFilter;  // normal file filter
-    private FileFilter _ignoreFileFilter; // worker file filter (used if input suffix is null)
-
-
+    private String _filterClass = null;
 }

Modified: labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/gateway/FileGatewayListenerUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/gateway/FileGatewayListenerUnitTest.java	2008-12-15 05:10:01 UTC (rev 24377)
+++ labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/gateway/FileGatewayListenerUnitTest.java	2008-12-15 10:07:31 UTC (rev 24378)
@@ -23,17 +23,21 @@
 package org.jboss.soa.esb.listeners.gateway;
 
 import java.io.File;
+import java.io.FileFilter;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.net.MalformedURLException;
 
 import org.apache.log4j.Logger;
+import org.jboss.internal.soa.esb.listeners.gateway.filefilter.FileEndsWith;
 import org.jboss.internal.soa.esb.services.registry.MockRegistry;
 import org.jboss.soa.esb.ConfigurationException;
 import org.jboss.soa.esb.services.registry.RegistryException;
+import org.jboss.soa.esb.util.Util;
 import org.jboss.soa.esb.common.tests.BaseTest;
 import org.jboss.soa.esb.helpers.ConfigTree;
 import org.jboss.soa.esb.listeners.ListenerTagNames;
+import org.jboss.soa.esb.listeners.gateway.FileGatewayListener.FileFilterInit;
 import org.jboss.soa.esb.listeners.lifecycle.ManagedLifecycleException;
 import org.jboss.soa.esb.listeners.message.MessageDeliverException;
 import org.jboss.soa.esb.message.Message;
@@ -269,6 +273,7 @@
         tree.setAttribute("target-service-category", "Example");
         tree.setAttribute("target-service-name", "Test");
         tree.setAttribute("gatewayClass", "org.jboss.soa.esb.listeners.gateway.FileGatewayListener");
+        tree.setAttribute("file-filter-class", OverrideFileEndsWith.class.getName());
         tree.setAttribute("inputSuffix", "dummy");
         tree.setAttribute("workSuffix", "work");
         tree.setAttribute("postDelete", "true");
@@ -276,4 +281,4 @@
 
         return tree;
     }
-}
+}
\ No newline at end of file

Added: labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/gateway/OverrideFileEndsWith.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/gateway/OverrideFileEndsWith.java	                        (rev 0)
+++ labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/gateway/OverrideFileEndsWith.java	2008-12-15 10:07:31 UTC (rev 24378)
@@ -0,0 +1,54 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.soa.esb.listeners.gateway;
+
+import java.io.File;
+import java.io.FileFilter;
+
+import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.soa.esb.util.Util;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.listeners.ListenerTagNames;
+import org.jboss.soa.esb.listeners.gateway.FileGatewayListener.FileFilterInit;
+
+public class OverrideFileEndsWith implements FileFilter, FileFilterInit
+{
+    public OverrideFileEndsWith ()
+    {
+    }
+    
+    public void init (ConfigTree config) throws ConfigurationException
+    {
+        m_sSuffix = config.getRequiredAttribute(ListenerTagNames.FILE_INPUT_SFX_TAG).trim();;
+        
+        if (Util.isNullString(m_sSuffix))
+            throw new ConfigurationException("Must specify file extension");
+    }
+    
+    public boolean accept (File p_f)
+    {
+        return (p_f.isFile()) ? p_f.toString().endsWith(m_sSuffix) : false;
+    }
+    
+    private String m_sSuffix;
+}




More information about the jboss-svn-commits mailing list