[jboss-svn-commits] JBL Code SVN: r11208 - labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Sun Apr 22 14:35:49 EDT 2007
Author: mark.little at jboss.com
Date: 2007-04-22 14:35:48 -0400 (Sun, 22 Apr 2007)
New Revision: 11208
Modified:
labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/AbstractFileGateway.java
labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/FileGatewayListener.java
Log:
http://jira.jboss.com/jira/browse/JBESB-454
Modified: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/AbstractFileGateway.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/AbstractFileGateway.java 2007-04-22 18:02:47 UTC (rev 11207)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/AbstractFileGateway.java 2007-04-22 18:35:48 UTC (rev 11208)
@@ -331,6 +331,17 @@
{
}
+ /*
+ * Is the input suffix valid for this type of gateway?
+ */
+
+ protected void checkInputSuffix () throws ConfigurationException
+ {
+ if (_inputSuffix.length() < 1)
+ throw new ConfigurationException("Invalid "
+ + ListenerTagNames.FILE_INPUT_SFX_TAG + " attribute");
+ }
+
/**
* Check for mandatory and optional attributes in parameter tree
*
@@ -384,9 +395,8 @@
_inputSuffix = ListenerUtil.obtainAtt(_config,
ListenerTagNames.FILE_INPUT_SFX_TAG, null);
_inputSuffix = _inputSuffix.trim();
- if (_inputSuffix.length() < 1)
- throw new ConfigurationException("Invalid "
- + ListenerTagNames.FILE_INPUT_SFX_TAG + " attribute");
+
+ checkInputSuffix();
// WORK suffix (will rename in input directory)
_workingSuffix = ListenerUtil.obtainAtt(_config,
@@ -394,6 +404,7 @@
if (_workingSuffix.length() < 1)
throw new ConfigurationException("Invalid " + ListenerTagNames.FILE_WORK_SFX_TAG
+ " attribute");
+
if (_inputSuffix.equals(_workingSuffix))
throw new ConfigurationException("Work suffix must differ from input suffix <"
+ _workingSuffix + ">");
@@ -430,16 +441,17 @@
seeIfOkToWorkOnDir(_postProcessDirectory);
_postProcessSuffix = ListenerUtil.obtainAtt(_config,
ListenerTagNames.FILE_POST_SFX_TAG, ".esbDone").trim();
+
if (_postProcessDirectory.equals(_inputDirectory))
- {
- if (_postProcessSuffix.length() < 1)
- throw new ConfigurationException("Invalid "
- + ListenerTagNames.FILE_POST_SFX_TAG + " attribute");
- if (_postProcessSuffix.equals(_inputSuffix))
- throw new ConfigurationException(
- "Post process suffix must differ from input suffix <"
- + _postProcessSuffix + ">");
- }
+ {
+ if (_postProcessSuffix.length() < 1)
+ throw new ConfigurationException("Invalid "
+ + ListenerTagNames.FILE_POST_SFX_TAG + " attribute");
+ if (_postProcessSuffix.equals(_inputSuffix))
+ throw new ConfigurationException(
+ "Post process suffix must differ from input suffix <"
+ + _postProcessSuffix + ">");
+ }
}
catch (GatewayException ex)
{
@@ -456,7 +468,7 @@
try
{
String sProcessMethod = null;
- _composerName = _config.getAttribute(ListenerTagNames.GATEWAY_COMPOSER_CLASS_TAG);
+ _composerName = _config.getAttribute(ListenerTagNames.GATEWAY_COMPOSER_CLASS_TAG);
if (null != _composerName)
{ // class attribute
_composerClass = ClassUtil.forName(_composerName, getClass());
Modified: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/FileGatewayListener.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/FileGatewayListener.java 2007-04-22 18:02:47 UTC (rev 11207)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/FileGatewayListener.java 2007-04-22 18:35:48 UTC (rev 11208)
@@ -47,7 +47,33 @@
public FileGatewayListener(ConfigTree config) throws ConfigurationException, RegistryException, GatewayException
{
super(config);
- _fileFilter = new FileEndsWith(_inputSuffix);
+
+ /*
+ * 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.
+ */
+
+ _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);
}
@Override
@@ -98,7 +124,30 @@
@Override
File[] getFileList() throws GatewayException
{
- return _inputDirectory.listFiles(_fileFilter);
+ /*
+ * JBESB-454 allows no input suffix. This means that we need to
+ * ignore any worker files, which are written to the same directory,
+ * but which have a well defined suffix. All other files (errors and
+ * post processed) go into separate directories, so we don't need
+ * to be concerned about them.
+ */
+
+ if (_inputFileFilter != null)
+ {
+ /*
+ * Input suffix is not null.
+ */
+
+ return _inputDirectory.listFiles(_inputFileFilter);
+ }
+ else
+ {
+ /*
+ * Input suffix is null so ignore any worker files.
+ */
+
+ return _inputDirectory.listFiles(_ignoreFileFilter);
+ }
}
@Override
@@ -226,6 +275,19 @@
} // ____________________________________________________
/**
+ * This implementation allows no input suffix, whereas the base class
+ * requires an input suffix.
+ */
+
+ protected void checkInputSuffix () throws ConfigurationException
+ {
+ // any suffix is allowed for input; set value to "" if null.
+
+ if (_inputSuffix == null)
+ _inputSuffix = "";
+ }
+
+ /**
* Simple file filter for local filesystem Will accept only files that end
* with the String supplied at constructor time
*
@@ -244,9 +306,52 @@
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");
} // ______________________________
- } // ____________________________________________________
- private FileFilter _fileFilter;
+ 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)
+
}
More information about the jboss-svn-commits
mailing list