:o
I can’t think of a way to do this in Flow without opening a can of worms. Doesn’t mean it can’t be done, but my two years of WM experience haven’t shown me a way. In particular without an input array, a LOOP step is no use (or have I missed something?), and REPEAT is “interesting” to say the least.
My recommendation would be to work on the algorithm outside of webMethods. Write a Java method:
private static String[] splitString(String input, int chunkLength) {
// implementation
}
Test it, and test it well - zero length inputs, null inputs, input.length == chunkLength, etc.
Then paste that code into the ‘Shared’ tab of your Java service. Let Developer convert your service inputs and outputs into IData parsing stuff. Make minor changes to the autogenerated code, to call your splitString method.
Oh, and use the Java collections framework to make your implementation of the method easier.
Aw sod it:
/**
* Splits a string into an array of Strings, each of the requested size.
* The final string in the array may of course be shorter.
* @param input A string to split
* @param chunkSize Size of the desired chunks
* @return the chunks as requested.
*/
public static String[] splitString(String input, int chunkSize) {
List strings = new ArrayList();
while(input.length() > 0) {
int thisLen = java.lang.Math.min(chunkSize, input.length());
strings.add( input.substring(0, thisLen) ); // put chunk on list
input = input.substring(thisLen); // drop chunk from input
}
return (String[]) strings.toArray(new String[0]);
}
(Hoping that I’ve understood your intention). I daresay it could be made more efficient, but this way it’s nice and easy to understand.
Of course this fails with a null input. I’ll leave fixing that as an exercise for the reader.
#Flow-and-Java-services#Integration-Server-and-ESB#webMethods