Hi,
Sounds like the repeat on success looping over %count-1% is not doing what you expect. I suspect that it is not evaluating the “%count-1%” expression correctly, and is therefore going beyond the number of items in your list. I would guess that the string index out of range exception is being thrown by your java service when it is asked to do something to element # 11 in a 10-element list (for example). If you need to use repeat, I would recommend putting a Map step before the repeat to decrement the loop count variable, e.g.
=> pub.math:addInts ( Add -1 to count and store result in count)
=> Repeat on success, count is %count%
However, I agree with Fred that the best solution in your case sounds like returning the list of files into a String array and then looping over that using the Loop construct.
For example - create a Java service which takes a directoryName input parameter and returns the list of files (and directories) as a String array, e.g.:
IDataCursor pipelineCursor = pipeline.getCursor();
String directoryName = IDataUtil.getString( pipelineCursor, “directoryName”);
if ((directoryName == null) || !directoryName.equals(“”)) {
directoryName = “.”; // Default to current directory
}
String files = new java.io.File(directoryName).list();
IDataUtil.put( pipelineCursor, “files”, files );
pipelineCursor.destroy();
Then, write a Flow service which calls the directoryList Java service and then loops over “files” (as the in-array parameter), e.g.
=> invoke directoryList, storing result in variable “files”
=> Loop in-array = “files”
=> pub.flow:debugLog, message is “%files%”, variable substitution is selected.
As a simple example, I set a debugLog step to output the message “File # %$iteration% is [%files%]”, which resulted in output like this:
File # 1 is [Apache_license.txt]
File # 2 is [audit]
File # 3 is [bin]
etc.
You might also filter the list (in your Java service) to remove any directories, sort it alphabetically, convert to all uppercase, etc. etc.
Hope this helps.
Cheers,
Steve Ovens
#webMethods-General#webMethods#Integration-Server-and-ESB